Salut à tous, Je suis passé sur un bridge pro, du coup j'en ai profité pour testé cette api V2. De mon côté aucun problème. Simplement j'ai du mettre à jour le script du plugin afin de prendre en charge les zones et leurs scène. En fait tout était déjà géré suffisait simplement de les afficher sur la page qui liste les périphériques. Voilà le code pour ceux que ca peut intéressé.
- Code : Tout sélectionner
<?php
/** Couleurs des icones: rouge : #FF0000 orange : #FF7400 vert : #01AD1B bleu : #000FFF
Liste des actions: 1. reset : topology (hueDatas) and debug infos. 2. debug : ON/OFF debug mode 3. debugInfos : dump the traces debugInfos 4. hueDatas : dump the traces debugInfos 5. link_helper : connect to the Philips Hub 6. topology : update the var hueDatas, aka a cache with the identifiers and capacities (light, power, etc..) 7. getState : get the state for a device 8. setSate : set the state for a device 9. topology_helper : display an html page with the attached devices. **/
$html = '<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>hue and eedomus</title>
<style> html { background:#222; color: #fff; font-family: "proxima-nova","Helvetica Neue",Helvetica,Arial,sans-serif; }
header, section {width: 100%; display: block;} header img, header h1 {display: inline; margin: 25px; vertical-align: middle;} section {margin-left: 25px;} form label, form input, form button {margin: 15px 0px; display: block;} a:link, a:visited { color: #0078e7; } a:hover { color: red; }
fieldset { border: 0 none; margin: 0; padding: 0.35em 0 0.75em; }
input[type="text"] { -moz-box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; box-shadow: 0 1px 3px #ddd inset; padding: 0.5em 0.6em; }
button { font-size: 100%; padding: 0.5em 1em; text-decoration: none; -moz-user-select: none; cursor: pointer; line-height: normal; text-align: center; vertical-align: baseline; white-space: nowrap; border: 0 none rgba(0, 0, 0, 0); border-radius: 2px; background-color: #0078e7; color: #fff; } </style>
</head> <body>
<header> <img alt="Hue Personal Wireless Lighting" src="https://secure.eedomus.com/sdk/plugins/hue/hue-logo.png"> <h1>Philips hue and eedomus</h1> </header>';
$end = '</body></html>';
$hueDatas = loadVariable('hueDatas');
//API $apiv2_resource = "/clip/v2/resource";
// remplace adresse mac et cle api par *** dans les traces de debug. function sdk_parse_encrypt($var, $encrypt) { $result = null; foreach ($var as $key => $val) { $keyencrypt = $key; $temp = $keyencrypt; $count = 0; $temp = str_replace(array_keys($encrypt), $encrypt, $keyencrypt, $count); if ($count) $keyencrypt = $temp; if (is_array($val)) { $result[$keyencrypt] = sdk_parse_encrypt($val, $encrypt); } else { $count = 0; $valencrypt = $val; $temp = str_replace(array_keys($encrypt), $encrypt, $valencrypt, $count); if ($count) $valencrypt = $temp; $result[$keyencrypt] = $valencrypt; } } return $result; }
// affiche la variable $var function sdk_print_debug($var, $bencrypt) { if ($bencrypt || $bencrypt=="false") { $hueDatas = loadVariable('hueDatas'); $encrypt_keys = loadVariable('encrypt_keys'); if (empty($encrypt_keys)) { var_dump($var); } else var_dump (sdk_parse_encrypt($var, $encrypt_keys)); } else var_dump($var); }
// corrige les problemes d'encodage function sdk_htmlentities($str) { return htmlentities($str, ENT_QUOTES, "UTF-8"); //preg_replace('/\\\\u([\da-fA-F]{4})/', '&#x\1;', $str); }
// ajoute un trace de debug function sdk_append_traces($key, $value, $time=null) { $debug = loadVariable('debug'); if ($debug=='on') { $debugInfos = loadVariable('debugInfos'); if (is_null($time)) $debugInfos[date("d-m-Y H:i:s",time())][$key]=$value; else if (array_key_exists($key, $debugInfos)) { if (is_array($debugInfos[date("d-m-Y H:i:s",$time)][$key])) $debugInfos[date("d-m-Y H:i:s",$time)][$key][]=$value; else { $newvalue = array($debugInfos[date("d-m-Y H:i:s",$time)][$key], $value); $debugInfos[date("d-m-Y H:i:s",$time)][$key]=$newvalue; } } else $debugInfos[date("d-m-Y H:i:s",$time)][$key]=$value; saveVariable('debugInfos', $debugInfos); } }
// Ã revoir pour utilisaion ou suppression function sdk_check_connexion($hue_datas) { $response = httpQuery('https://'.$hue_datas['ip'].$api_hue.$api_resource, 'GET'); if (false == strpos($response, "Error")) { return true; } else { sdk_append_traces('sdk_check_connexion', $response); return false; } }
function sdk_HSVtoRGBHue($iH, $S, $V) { $H = $iH/65535*360; $s = $S/254 ; $v = $V/254; $C = $s*$v; $X = $C*(1-abs(fmod($H/60.0, 2)-1)); $m = $v-$C; $r = $g = $b = 0; if($H >= 0 && $H < 60){ $r = $C; $g = $X; $b = 0; } else if($H >= 60 && $H < 120){ $r = $X; $g = $C; $b = 0; } else if($H >= 120 && $H < 180){ $r = 0; $g = $C; $b = $X; } else if($H >= 180 && $H < 240){ $r = 0; $g = $X; $b = $C; } else if($H >= 240 && $H < 300){ $r = $X; $g = 0; $b = $C; } else{ $r = $C; $g = 0; $b = $X; } $R = $r+$m; $G = $g+$m; $B = $b+$m; return array('r'=>round(100*$R), 'g'=>round(100*$G), 'b'=>round(100*$B)); }
$action = getArg('action');
switch ($action) { case 'reset': { $mac = getArg('mac'); saveVariable('debugInfos', array()); saveVariable('hueDatas', array($mac=>array('key'=>$hueDatas[$mac]['key']))); echo "<xml><status>ok</status></xml"; break; } case 'debug': { $arg = getArg('status', false); if ($arg === "off") { saveVariable('debug', 'off'); saveVariable('debugInfos', array()); } else if ($arg === "on") saveVariable('debug', 'on');
$status = loadVariable('debug'); echo '<xml><status>'.$status.'</status></xml>'; break; } case "debugInfos": { $debugInfos = loadVariable('debugInfos'); $bencrypt = getArg('encrypt', false, true); sdk_print_debug($debugInfos, $bencrypt); break; } case 'hueDatas': { $bencrypt = getArg('encrypt', false, true); sdk_print_debug($hueDatas, $bencrypt); break; } case 'link_helper': { $mac= getArg('mac'); $hue_bridge_ip = sdk_get_ip_from_ip_or_mac($mac); $hue_controller_id = $_GET['controller_id']; $post = '{"devicetype":"eedomus#pluginhue", "generateclientkey":true}'; $response= httpQuery("https://$hue_bridge_ip/api", 'POST', $post); $json = sdk_json_decode($response); sdk_append_traces('link_helper_api_json', $json); if (array_key_exists('error', $json[0])) { if ($json[0]['error']['description']=== "link button not pressed") { // push button if ($json[0]['error']['description']=== "link button not pressed") { $exec = $_GET['exec']; $url_to_call = "http://localhost/script/?exec=$exec&action=link_helper&mac=$mac"; if($hue_controller_id !== null) $url_to_call .= "&controller_id=$hue_controller_id"; echo $html; echo '<section>'; echo "<form>"; echo "<fieldset>"; echo "<input type=\"hidden\" name=\"url\" value=\"$url_to_call\">"; if($hue_controller_id !== null) echo "<input type=\"hidden\" name=\"controller_id\" value=\"$hue_controller_id\">"; echo "<label>Please press the button on the bridge and confirm.</label>"; echo "<button type=\"submit\">Confirm</button>"; echo "</fieldset>"; echo "</form>"; echo '</section>'; echo $end; } } else { echo $html; echo '<div>'.$json[0]['error']['description'].'</div>'; echo $end; } } else { //store infos $hue_application_key = $json[0]['success']['username']; $hueDatas[$mac]['key'] = $hue_application_key; saveVariable('hueDatas', $hueDatas); $encrypt_keys = array($mac => "***", $hue_application_key => "***"); saveVariable('encrypt_keys', $encrypt_keys); echo $html; echo "<div>Application linked with the hub. Close this window</div>"; echo $end; } break; } case 'topology': { $mac = getArg('mac'); $hue_bridge_ip = sdk_get_ip_from_ip_or_mac($mac); $key = $hueDatas[$mac]['key']; // TO REMOVE $encrypt_keys = array($mac => "***", $key => "***"); saveVariable('encrypt_keys', $encrypt_keys); // if (empty($key)) { echo "<xml><status>-1</status></xml>"; die(); } $header = array("hue-application-key:".$hueDatas[$mac]['key']); $response= httpQuery('https://'.$hue_bridge_ip.$apiv2_resource, NULL, NULL, NULL,$header); $json_device = sdk_json_decode($response); if (is_null($json_device) || count($json_device['errors'])) { $time = time(); sdk_append_traces('topology_helper_devices_header', $header, $time); sdk_append_traces('topology_helper_devices_json', $json_device, $time); echo "<xml><status>0</status></xml>"; } else { $types = array('grouped_light', 'device', 'zone', 'scene'); foreach ($json_device['data'] as $device) { if (in_array($device['type'], $types)) { $hueDatas[$mac]['devices'][$device['id']]['id_v2'] = $device['id']; $hueDatas[$mac]['devices'][$device['id']]['id_v1'] = $device['id_v1']; //Zones commit if (isset($device['metadata']['name'])) { $hueDatas[$mac]['devices'][$device['id']]['name'] = $device['metadata']['name']; } if (isset($device['children'])) { $hueDatas[$mac]['devices'][$device['id']]['children'] = $device['children']; } foreach ($device['services'] as $service) { $hueDatas[$mac]['devices'][$device['id']][$service['rtype']] = $service['rid']; } } } saveVariable('hueDatas', $hueDatas); echo "<xml><status>1</status></xml>"; } break; } case 'getState': { $mac = getArg('mac'); $hue_bridge_ip = sdk_get_ip_from_ip_or_mac($mac); $id = getArg('id'); $type = getArg('type'); $time = time(); $eeDevice = getArg('eedomus_controller_module_id'); //$hueDatas = loadVariable('hueDatas'); sdk_header('text/xml');
sdk_append_traces('getState',$id,$time); sdk_append_traces('getState',$type,$time); if (array_key_exists($id,$hueDatas[$mac]['devices'])) { sdk_append_traces('getState_device',$hueDatas[$mac]['devices'][$id],$time); $battery_state = null; if (array_key_exists('device_power', $hueDatas[$mac]['devices'][$id])) { $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $url_V2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/device_power/'.$hueDatas[$mac]['devices'][$id]['device_power']; $response = httpQuery($url_V2, 'GET', NULL, NULL, $header_V2, false, false, $infos); $json = sdk_json_decode($response); $eeDevice = getArg('eedomus_controller_module_id'); setBattery($eeDevice, $json['data'][0]['power_state']['battery_level']); $battery_state = $json['data'][0]['power_state']['battery_state']; } switch ($type) { case 'light': { $url_V1 = 'https://'.$hue_bridge_ip.'/api/'.$hueDatas[$mac]['key'].$hueDatas[$mac]['devices'][$id]['id_v1']; $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $url_V2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/'.$type.'/'.$hueDatas[$mac]['devices'][$id][$type]; $json = httpQuery($url_V2, 'GET', NULL, NULL, $header_V2); $response = sdk_json_decode($json); sdk_append_traces('getState', $json, $time); // ERROR : ["responseV1"]=> string(94) "[{"error":{"type":2,"address":"/lights/14/state","description":"body contains invalid json"}}]" $status = ($response['data'][0]['on']['on'])?"on":"off"; if ($response['data'][0]['mode']!=="normal") $status = $response['data'][0]['mode']; else if($status=="on") { $url_V1 = 'https://'.$hue_bridge_ip.'/api/'.$hueDatas[$mac]['key'].$hueDatas[$mac]['devices'][$id]['id_v1']; $json = httpQuery($url_V1, 'GET'); $responseV1 = sdk_json_decode($json); $rgb = sdk_HSVtoRGBHue($responseV1['state']['hue'], $responseV1['state']['sat'], $responseV1['state']['bri']); $status_rgb=$rgb['r'].','.$rgb['g'].','.$rgb['b']; $values = getPeriphValueList($eeDevice); sdk_append_traces("status_rgb", $status_rgb, $time); sdk_append_traces("values",$values, $time); if (array_key_exists($status_rgb, $values)) $status = $status_rgb; } echo "<xml><status>$status</status></xml>"; break; } case 'button': { $status = 'disconnected'; if (isset($battery_state)) $status = $battery_state; echo "<xml><status>$status</status></xml>"; break; } case 'temperature': { $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $url_V2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/'.$type.'/'.$hueDatas[$mac]['devices'][$id][$type]; $response = httpQuery($url_V2, 'GET', NULL, NULL, $header_V2, false, false, $infos); $json = sdk_json_decode($response); $temperature = -100; if ($json['data'][0]['enabled'] && $json['data'][0]['temperature']['temperature_valid']) $temperature = $json['data'][0]['temperature']['temperature']; echo '<xml><temperature>'.$temperature.'</temperature></xml>'; break; } case 'grouped_light': { $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $url_V2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/'.$type.'/'.$hueDatas[$mac]['devices'][$id]['id_v2']; $json = httpQuery($url_V2, 'GET', NULL, NULL, $header_V2, false, false, $infos); $response = sdk_json_decode($json); sdk_append_traces('getState_url',$url_V2,$time); sdk_append_traces('getState_response',$response,$time); $status = ($response['data'][0]['on']['on'])?"on":"off"; echo "<xml><status>$status</status></xml>"; break; } case 'scene': { $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $url_V2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/'.$type.'/'.$hueDatas[$mac]['devices'][$id]['id_v2']; $json = httpQuery($url_V2, 'GET', NULL, NULL, $header_V2, false, false, $infos); $response = sdk_json_decode($json); sdk_append_traces('getState_url',$url_V2,$time); sdk_append_traces('getState_response',$response,$time); $status = ($response['data'][0]['on']['on'])?"on":"off"; echo "<xml><status>$status</status></xml>"; break; } default: { echo "<xml><status>Unknow type</status></xml>"; } } } else echo "<xml><status>Identifier not found.</status></xml>"; break; } case 'setState': { $actif = getArg('actif', false, true); if ($actif != true) { echo "unactive"; } $type = getArg('type'); $mac = getArg('mac'); $hue_bridge_ip = sdk_get_ip_from_ip_or_mac($mac); $id = getArg('id'); $time = time(); $on = getArg('on', false, 'true'); /* V1-V2 : true, false */ $bri = getArg('bri', false, null); /* V1-V2 : brightness */ $hue = getArg('hue', false, null); /* V1 : color */ $sat = getArg('sat', false, null); /* V1 : saturation */ $alert = getArg('alert', false, null); /*V1 : select, lselect */ $effect = getArg('effect', false, null); /* V1 : colorloop */ $effects = getArg('effects', false, null); /* V2 - light : candle, fire */ $scene = getArg('scene', false, null); /* V2 - group : identifier */ $isV1 = $isV2 = false; if (isset($effects) || isset($scene)) { $isV2 = true; /*$effects +($bri)* */ // V2 : values between 0 and 100. if (isset($bri)) { if ($bri<0) $bri = 0; else if ($bri>254) $bri = 254; $bri = round($bri/254*100); } } else { $isV1 = true; // V1 : values between 0 and 254. if (isset($bri)) { if ($bri<0) $bri = 0; else if ($bri>254) $bri = 254; } if (isset($sat)) { if ($sat<0) $sat = 0; else if ($sat>254) $sat = 254; } } $isV1str = ($isV1==true)?"true":"false"; $isV2str = ($isV2==true)?"true":"false"; sdk_append_traces("V1", $isV1str, $time); sdk_append_traces("V2", $isV2str, $time); //$hueDatas = loadVariable('hueDatas'); if (array_key_exists($id,$hueDatas[$mac]['devices'])) { $postDatas = NULL; switch ($type) { case 'light': { if ($isV1) { $postDatas = '{"on":'.$on; if (isset($bri)) $postDatas .= ', "bri":'.$bri; if (isset($hue)) $postDatas .= ', "hue":'.$hue; if (isset($sat)) $postDatas .= ', "sat":'.$sat; if (isset($alert)) $postDatas .= ', "alert":"'.$alert.'"'; if (isset($effect)) $postDatas .= ', "effect":"'.$effect.'"'; $postDatas .= "}"; $urlV1 = 'https://'.$hue_bridge_ip.'/api/'.$hueDatas[$mac]['key'].$hueDatas[$mac]['devices'][$id]['id_v1'].'/state'; $json = httpQuery($urlV1, "PUT", $postDatas); sdk_append_traces("datasV1", $postDatas, $time); sdk_append_traces("urlV1", $urlV1, $time); sdk_append_traces("responseV1", $json, $time); echo ($on==="true")?'on':'off'; } else if ($isV2) { $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $postDatas = '{"on":{"on":'.$on.'}}'; $urlV2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/light/'.$hueDatas[$mac]['devices'][$id]['light']; $json = httpQuery($urlV2, "PUT", $postDatas,NULL, $header_V2); sdk_append_traces("postDatas.1", $postDatas, $time); sdk_append_traces("urlV2.1", $urlV2, $time); sdk_append_traces("responseV2.1", $json, $time); $postDatas = '{"effects":{"effect":"'.$effects.'"}'; if (isset($bri)) $postDatas .= ', "dimming":{"brightness":'.$bri.'}'; $postDatas .= "}"; $json = httpQuery($urlV2, "PUT", $postDatas,NULL, $header_V2); sdk_append_traces("postDatas.2", $postDatas, $time); sdk_append_traces("urlV2.2", $urlV2, $time); sdk_append_traces("responseV2.2", $json, $time); echo ($on==="true")?'on':'off'; } break; } case 'grouped_light': { if ($isV1) { $postDatas = '{"on":'.$on; if (isset($bri)) $postDatas .= ', "bri":'.$bri; if (isset($hue)) $postDatas .= ', "hue":'.$hue; if (isset($sat)) $postDatas .= ', "sat":'.$sat; if (isset($alert)) $postDatas .= ', "alert":"'.$alert.'"'; if (isset($effect)) $postDatas .= ', "effect":"'.$effect.'"'; if (isset($scene)) $postDatas .= ', "scene":"'.$scene.'"'; $postDatas .= "}"; $urlV1 = 'https://'.$hue_bridge_ip.'/api/'.$hueDatas[$mac]['key'].$hueDatas[$mac]['devices'][$id]['id_v1'].'/action'; $json = httpQuery($urlV1, "PUT", $postDatas); sdk_append_traces("datasV1", $postDatas, $time); sdk_append_traces("urlV1", $urlV1, $time); sdk_append_traces("responseV1", $json, $time); echo ($on==="true")?'on':'off'; } else if ($isV2) { //$postDatas = '{"on":{"on":'.$on.'}'; $postDatas = '{"recall":{"action":"active"'; if (isset($bri)) $postDatas .= ', "dimming":{"brightness":'.$bri.'}'; $postDatas .= "}}"; $header_V2 = array('hue-application-key:'.$hueDatas[$mac]['key']); $urlV2 = 'https://'.$hue_bridge_ip.$apiv2_resource.'/scene/'.$scene; $json = httpQuery($urlV2, "PUT", $postDatas, NULL, $header_V2 ); sdk_append_traces("datasV2", $postDatas, $time); sdk_append_traces("urlV2", $urlV2, $time); sdk_append_traces("responseV1", $json, $time); echo ($on==="true")?'on':'off'; } break; } default: { echo "ERROR : Type not supported"; } } } else echo "ERROR : Identifier not found"; break; } case 'topology_helper': { $mac = getArg('mac'); $hue_bridge_ip = sdk_get_ip_from_ip_or_mac($mac); //$hueDatas = loadVariable('hueDatas'); $key = $hueDatas[$mac]['key']; if (empty($key)) { echo $html; echo "<div>Application is not linked to the Hub</div>"; echo $end; die(); } $header = array("hue-application-key:".$hueDatas[$mac]['key']); $response= httpQuery('https://'.$hue_bridge_ip.$apiv2_resource, NULL, NULL, NULL,$header); $json_resource = sdk_json_decode($response); $bridge_home = $rooms = $zones = $devices = $lights = $grouped_lights = $scenes = $zoneScenes = $device_powers = $motions = $temperatures = $buttons = array(); //Zones commit if (is_null($json_resource) || count($json_resource['errors'])) { $time = time(); sdk_append_traces('topology_helper_devices_header', $header, $time); sdk_append_traces('topology_helper_devices_json', $json_resource, $time); echo $html; echo "<div>ERROR : json_resource not retrieve</div>"; echo $end; } else { foreach ($json_resource['data'] as $resource) { switch ($resource['type']) { case 'bridge_home': { $keys = array('children', 'services'); foreach ($resource as $key => $values) { if (in_array($key, $keys)) { foreach ($values as $value) { $bridge_home[$resource['id']][$key][$value['rtype']][] = $value['rid']; } } } break; } case 'room': { if (array_key_exists('metadata', $resource)) $rooms[$resource['id']]['name'] = $resource['metadata']['name']; $keys = array('children', 'services'); foreach ($resource as $key => $values) { if (in_array($key, $keys)) { foreach ($values as $value) { $rooms[$resource['id']][$key][$value['rtype']][] = $value['rid']; } } } break; } //Zones commit case 'zone': { if (array_key_exists('metadata', $resource)) $zones[$resource['id']]['name'] = $resource['metadata']['name']; if (array_key_exists('product_data', $resource)) $zones[$resource['id']]['product_name'] = $resource['product_data']['product_name'];
$keys = array('children', 'services'); foreach ($resource as $key => $values) { if (in_array($key, $keys)) { foreach ($values as $value) { $zones[$resource['id']][$key][$value['rtype']][] = $value['rid']; } } } break; } case 'device': { if (array_key_exists('metadata', $resource)) $devices[$resource['id']]['name'] = $resource['metadata']['name']; if (array_key_exists('product_data', $resource)) $devices[$resource['id']]['product_name'] = $resource['product_data']['product_name']; $keys = array('children', 'services'); foreach ($resource as $key => $values) { if (in_array($key, $keys)) { foreach ($values as $value) { $devices[$resource['id']][$key][$value['rtype']][] = $value['rid']; } } } break; } case 'light': { //Zones commit if (array_key_exists('owner', $resource)) $lights[$resource['id']] = $resource['owner']['rid']; break; } case 'grouped_light': { if (array_key_exists('owner', $resource)) $grouped_lights[$resource['id']]['owner'][$resource['owner']['rtype']] = $resource['owner']['rid']; break; } case 'scene': { if (array_key_exists('metadata', $resource)) $scenes[$resource['id']]['name'] = $resource['metadata']['name']; if (array_key_exists('group', $resource)) $scenes[$resource['id']][$resource['group']['rtype']] = $resource['group']['rid']; break; } case 'device_power': { break; } case 'motion': { break; } case 'temperature': { break; } case 'button': { break; } } }
//Zones commit foreach ($scenes as $sceneId => $scene) { if (isset($scene['zone'])) { $zoneId = $scene['zone']; $zoneScenes[$zoneId][$sceneId] = $scene['name']; } } } $time = time(); sdk_append_traces('topology_helper_bridge_home', $bridge_home, $time); sdk_append_traces('topology_helper_rooms', $rooms, $time); sdk_append_traces('topology_helper_zones', $zones, $time); //Zones commit sdk_append_traces('topology_helper_devices', $devices, $time); sdk_append_traces('topology_helper_grouped_lights', $grouped_lights, $time); sdk_append_traces('topology_helper_scenes', $scenes, $time); echo $html; $tags = array('grouped_light'=>'Groupe'); foreach ($bridge_home as $bridge) { echo '<ul>'; echo '<li><h1>Bridge :</h1></li>'; echo '<ul>'; // Devices $count = sizeof($bridge['children']['device']); if ($count > 0) echo '<li><h2>Devices :</h2></li> <ul>'; foreach ($bridge['children']['device'] as $device ) { echo '<li>'.sdk_htmlentities($devices[$device]['name']).' ('.$devices[$device]['product_name'].') => <b>'.$device.'</b></li>'; } if ($count > 0) echo '</ul>'; // Services $count = sizeof($bridge['services']); if ($count > 0) echo '<li><h2>Services :</h2></li>'; foreach ($bridge['services'] as $key => $service) { $count2 = sizeof($service); if ($count2 >0) echo '<ul>'; foreach ($service as $value) { if (array_key_exists($key, $tags)) echo '<li>'.$tags[$key].' => <b>'.$value.'</b></li>'; else echo '<li>'.$key.' => <b>'.$value.'</b></li>'; } if ($count2 >0) echo '</ul>'; }
// Zones commit if (!empty($zones)) { echo '<li><h2>Zones :</h2></li><ul>';
foreach ($zones as $zoneId => $zone) { echo '<li><h3>'.sdk_htmlentities($zone['name']).'</h3>'; echo '<ul>'; if (isset($zone['children']['light'])) { foreach ($zone['children']['light'] as $lightId) { $deviceId = isset($lights[$lightId]) ? $lights[$lightId] : null; if ($deviceId && isset($devices[$deviceId])) echo '<li>'. sdk_htmlentities($devices[$deviceId]['name']). ' ('.sdk_htmlentities($devices[$deviceId]['product_name']).') => <b>'.$lightId.'</b></li>'; else echo '<li>Light => <b>'.$lightId.'</b></li>'; } } if (isset($zone['services']['grouped_light'][0])) echo '<li>Grouped light => <b>'.$zone['services']['grouped_light'][0].'</b></li>'; if (isset($zoneScenes[$zoneId])) { echo '<ul><li><h4>Scènes</h4></li><ul>'; foreach ($zoneScenes[$zoneId] as $sceneId => $sceneName) { echo '<li>'.sdk_htmlentities($sceneName).' => <b>'.$sceneId.'</b></li>'; } echo '</ul></ul>'; } echo '</ul></li>'; } echo '</ul>'; }
$count = sizeof($bridge['children']['room']); if ($count >0) echo '<li><h2>'.sdk_htmlentities('Pièces :').'</h2></li> <ul>'; foreach ($bridge['children']['room'] as $room ) { echo '<li><h3>'.sdk_htmlentities($rooms[$room]['name']).'</h3></li>'; $count2 = sizeof($rooms[$room]['children']['device']); if ($count2 >0) { echo '<ul><li><h4>Produits</h4></li>'; echo '<ul>'; } foreach ($rooms[$room]['children']['device'] as $device) { echo '<li>'.sdk_htmlentities($devices[$device]['name']).' ('.$devices[$device]['product_name'].') => <b>'.$device.'</b></li>'; } if ($count2 >0) { echo '</ul>'; echo '</ul>'; } $count2 = sizeof($rooms[$room]['services']); if ($count2 >0) { echo '<ul><li><h4>Groupes</h4></li>'; echo '<ul>'; } foreach ($rooms[$room]['services'] as $key => $service) { foreach ($service as $value) { if (array_key_exists($key, $tags)) echo '<li>'.$tags[$key].' => <b>'.$value.'</b></li>'; else echo '<li>'.$key.' => <b>'.$value.'</b></li>'; } } if ($count2 >0) { echo '</ul>'; echo '</ul>'; } /*$count2 = sizeof($scenes); if ($count2 >0) { echo '<ul><li><h4>'.sdk_htmlentities('Scènes:').'</h4></li>'; echo '<ul>'; }*/ $hasScene = false; foreach ($scenes as $key_scene => $scene) { if ($scene['room'] == $room) { if ($hasScene==false) { $hasScene = true; echo '<ul><li><h4>'.sdk_htmlentities('Scènes:').'</h4></li><ul>'; } echo '<li>'.sdk_htmlentities($scene['name']).' => <b>'.$key_scene.'</b></li>'; } } if ($hasScene) { echo '</ul></ul>'; } } if ($count > 0) echo '</ul>'; echo '</ul>'; echo '</ul>'; } echo $end; break; } default: { echo 'Action unknown'; } }
?>
|