Exemplo n.º 1
0
 public static function syncEqLogicWithRazberry()
 {
     $http = new com_http(self::makeBaseUrl() . '/ZWaveAPI/Data/0');
     $results = json_decode(self::handleError($http->exec()), true);
     foreach ($results['devices'] as $nodeId => $result) {
         if ($nodeId != 1) {
             $data = $result['data'];
             if (count(self::byLogicalId($nodeId, 'zwave')) == 0 || $nodeId == 2) {
                 $eqLogic = new eqLogic();
                 $eqLogic->setEqType_name('zwave');
                 $eqLogic->setIsEnable(1);
                 $eqLogic->setName('Device ' . $nodeId);
                 $eqLogic->setLogicalId($nodeId);
                 $eqLogic->setIsVisible(1);
                 $eqLogic->save();
                 /* Demande du niveau de batterie */
                 try {
                     $http = new com_http(self::makeBaseUrl() . '/ZWaveAPI/Run/devices[' . $eqLogic->getLogicalId() . '].instances[0].commandClasses[0x80].Get()');
                     $http->exec();
                 } catch (Exception $exc) {
                 }
                 /* Reconnaissance du module */
                 foreach (self::devicesParameters() as $device_id => $device) {
                     if ($device['manufacturerId'] == $data['manufacturerId']['value'] && $device['manufacturerProductType'] == $data['manufacturerProductType']['value'] && $device['manufacturerProductId'] == $data['manufacturerProductId']['value']) {
                         $eqLogic->setConfiguration('device', $device_id);
                         $eqLogic->save();
                         $eqLogic->applyModuleConfiguration();
                         break;
                     }
                 }
             }
         }
     }
 }