var panelApp = angular.module('panelApp', ['ngConstellation'])

	.controller('PanelController', ['$scope', 'constellation', function ($scope, constellation) { 	
        
        // Initialisation
	    constellation.intializeClient("http://skynet-server.ajsinfo.lan:8888/constellation/", "monAccesKey", "SPanel");

        // A la reception d'un StateObject, ajouter le SO au scope courant
	    constellation.onUpdateStateObject(function (message) {
	        $scope.$apply(function () {
	            if (typeof $scope[message.PackageName] === 'undefined' || $scope[message.PackageName] === null) {
	                $scope[message.PackageName] = {};
	            }
	            $scope[message.PackageName][message.Name] = message;		
	        });
	    }); 

        // Connexion à la Constellation
	    constellation.connect();	
	}]);

constellation.onConnectionStateChanged(function (change) {
	if (change.newState === $.signalR.connectionState.connected) {
		constellation.requestSubscribeStateObjects("*", "SEnergy", "*", "*");
		constellation.requestSubscribeStateObjects("*", "NetAtmo", "*", "*");
		constellation.requestSubscribeStateObjects("*", "Vera", "*", "*");
		constellation.requestSubscribeStateObjects("*", "Nest", "*", "*");
		constellation.requestSubscribeStateObjects("*", "Xbmc", "*", "*");
		constellation.requestSubscribeStateObjects("*", "Pioneer", "*", "*");
		constellation.requestSubscribeStateObjects("*", "BatteryChecker", "*", "*");
		constellation.requestSubscribeStateObjects("*", "Paradox", "*", "*");										
		constellation.requestSubscribeStateObjects("Powershell", "Internet", "*", "*");			
		constellation.requestSubscribeStateObjects("*", "DayInfo", "*", "*");
		constellation.requestSubscribeStateObjects("*", "LightSensor", "*", "*");	
		constellation.requestSubscribeStateObjects("*", "MeteoFrance", "*", "*");	
		constellation.requestSubscribeStateObjects("*", "Exchange", "*", "*");		
		constellation.requestSubscribeStateObjects("*", "SSound-Cuisine", "*", "*");		
		constellation.requestSubscribeStateObjects("*", "SSound-SalleDeBain", "*", "*");										
		constellation.requestSubscribeStateObjects("CEREBRUM", "HWMonitor", "*", "*");
	}
});	 

<li aria-hidden="true" class="fa fa-{{ (Paradox.AreaInfo1.Value.IsFullArmed || Paradox.AreaInfo1.Value.IsStayArmed) ? 'bell' : 'bell-slash' }}"></li>
<bold ng-if="Paradox.AreaInfo1.Value.IsFullArmed || Paradox.AreaInfo1.Value.IsStayArmed"><bad>ARMÉE</bad></bold>
<bold ng-if="!Paradox.AreaInfo1.Value.IsFullArmed && !Paradox.AreaInfo1.Value.IsStayArmed">OFF</bold>

<table>
	<tr ng-repeat="appointement in Exchange.Appointments4sebastien.Value | limitTo: 5">
		<td>{{appointement.Start.toLocaleDateString ("fr-fr", { weekday: "long", month: "short", day: "numeric" })}} à {{appointement.Start.toLocaleTimeString ("fr-fr", { minute: "numeric", hour: "numeric" })}} : {{appointement.Subject}} {{appointement.Location}}</td>
	</tr>	
</table>

<percent-display percent="HWMonitor['/intelcpu/0/load/0'].Value.Value" side="80" colors="#383737 #b2c831"></percent-display>

<progressbar value="HWMonitor['/hdd/1/load/0'].Value.Value" ><b>{{HWMonitor['/hdd/1/load/0'].Value.Value}}%</b></progressbar>

<a href="" ng-click="constellation.sendMessage({ Scope: 'Package', Args: [ 'Nest' ] }, 'SetTargetTemperature', Nest['Living Room'].Value.target_temperature_c ) + 0.5)"><img src="imgs/up-small.png" alt=""> UP</a> | 
<a href="" ng-click="constellation.sendMessage({ Scope: 'Package', Args: [ 'Nest' ] }, 'SetTargetTemperature', Nest['Living Room'].Value.target_temperature_c ) - 0.5)"><img src="imgs/down-small.png" alt=""> DN</a></p>

<table>
	<tr ng-repeat="switch in Vera" ng-if="(switch.Type == 'VeraNet.WindowCovering')">
		<td>{{switch.Name}}</td>
		<td>
			<slider onstopslide="SetWindowCovering" data-coverId="{{switch.Value.Id}}" ng-model="switch.Value.Level" min="0" step="1" max="100" value="" class="mySlider" id="windowCover{{switch.Value.Id}}" selection="after"></slider>
		</td>
	</tr>
</table>

$scope.SetWindowCovering = function (event) {
	constellation.sendMessage({ Scope: 'Package', Args: [ 'Vera' ] }, 'SetDimmableLevel', { DeviceID: $('#' + event.target.parentElement.id).data('coverid'), Level: event.value });
};