public static function syncEqLogicWithOpenZwave($_serverId = 0, $_logical_id = null)
 {
     try {
         $controlerState = self::callOpenzwave('/ZWaveAPI/Run/network.GetControllerStatus()', $_serverId);
         $state = $controlerState['result']['data']['networkstate']['value'];
     } catch (Exception $e) {
         $state = 10;
     }
     if ($state < 7) {
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Le controleur est occupé veuillez réessayer plus tard', __FILE__)));
         return;
     }
     if ($_logical_id !== null) {
         $eqLogic = self::getEqLogicByLogicalIdAndServerId($_logical_id, $_serverId);
         if (is_object($eqLogic)) {
             if (config::byKey('autoRemoveExcludeDevice', 'openzwave') == 1) {
                 $eqLogic->remove();
                 nodejs::pushUpdate('zwave::includeDevice', '');
             }
             nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
             return;
         }
         $result = self::callOpenzwave('/ZWaveAPI/Run/devices[' . $_logical_id . ']', $_serverId);
         if (count($result) == 0) {
             nodejs::pushUpdate('jeedom::alert', array('level' => 'danger', 'message' => __('Aucun module trouvé correspondant à cette ID : ', __FILE__) . $_logical_id));
             return;
         }
         $eqLogic = new eqLogic();
         $eqLogic->setEqType_name('openzwave');
         $eqLogic->setIsEnable(1);
         $eqLogic->setLogicalId($_logical_id);
         if (isset($result['data']['product_name']['value']) && trim($result['data']['product_name']['value']) != '') {
             $eqLogic->setName($eqLogic->getLogicalId() . ' ' . $result['data']['product_name']['value']);
         } else {
             $eqLogic->setName('Device ' . $_logical_id);
         }
         $eqLogic->setConfiguration('product_name', $result['data']['product_name']['value']);
         $eqLogic->setConfiguration('manufacturer_id', $result['data']['manufacturerId']['value']);
         $eqLogic->setConfiguration('product_type', $result['data']['manufacturerProductType']['value']);
         $eqLogic->setConfiguration('product_id', $result['data']['manufacturerProductId']['value']);
         $eqLogic->setConfiguration('serverID', $_serverId);
         $eqLogic->setIsVisible(1);
         $eqLogic->save();
         $eqLogic = openzwave::byId($eqLogic->getId());
         $include_device = $eqLogic->getId();
         $eqLogic->createCommand(false, $result);
         nodejs::pushUpdate('zwave::includeDevice', $include_device);
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
         return;
     }
     $results = self::callOpenzwave('/ZWaveAPI/Run/network.GetNodesList()', $_serverId);
     $findDevice = array();
     $include_device = '';
     if (count($results['devices']) < 2) {
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Le nombre de module trouvé est inférieure à 2', __FILE__)));
         return;
     }
     foreach ($results['devices'] as $nodeId => $result) {
         $findDevice[$nodeId] = $nodeId;
         if (isset($result['description']['is_static_controller']) && $result['description']['is_static_controller']) {
             continue;
         }
         if (!isset($result['product']['is_valid']) || !$result['product']['is_valid']) {
             continue;
         }
         $eqLogic = self::getEqLogicByLogicalIdAndServerId($nodeId, $_serverId);
         if (!is_object($eqLogic)) {
             $eqLogic = new eqLogic();
             $eqLogic->setEqType_name('openzwave');
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId($nodeId);
             if (isset($result['description']['product_name']) && trim($result['description']['product_name']) != '') {
                 $eqLogic->setName($eqLogic->getLogicalId() . ' ' . $result['description']['product_name']);
             } else {
                 $eqLogic->setName('Device ' . $nodeId);
             }
             $eqLogic->setConfiguration('product_name', $result['description']['product_name']);
             $eqLogic->setConfiguration('manufacturer_id', $result['product']['manufacturer_id']);
             $eqLogic->setConfiguration('product_type', $result['product']['product_type']);
             $eqLogic->setConfiguration('product_id', $result['product']['product_id']);
             $eqLogic->setConfiguration('serverID', $_serverId);
             $eqLogic->setIsVisible(1);
             $eqLogic->save();
             $eqLogic = openzwave::byId($eqLogic->getId());
             $include_device = $eqLogic->getId();
             $eqLogic->createCommand(false, $result);
         } else {
             if (isset($result['description']['product_name'])) {
                 $eqLogic->setConfiguration('product_name', $result['description']['product_name']);
             }
             if (isset($result['product']['is_valid']) && $result['product']['is_valid']) {
                 $eqLogic->setConfiguration('manufacturer_id', $result['product']['manufacturer_id']);
                 $eqLogic->setConfiguration('product_type', $result['product']['product_type']);
                 $eqLogic->setConfiguration('product_id', $result['product']['product_id']);
             }
             $eqLogic->save();
         }
     }
     if (config::byKey('autoRemoveExcludeDevice', 'openzwave') == 1) {
         foreach (self::byType('openzwave') as $eqLogic) {
             if (!isset($findDevice[$eqLogic->getLogicalId()]) && $eqLogic->getConfiguration('serverID') == $_serverId) {
                 $eqLogic->remove();
             }
         }
     }
     nodejs::pushUpdate('zwave::includeDevice', $include_device);
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
 }
Example #2
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;
                     }
                 }
             }
         }
     }
 }
Example #3
0
 public static function syncEqLogicWithTeslaSite($_logical_id = null)
 {
     $message = '';
     try {
         $list = self::listAllVehicles();
         $num = $list->{'count'};
     } catch (Exception $e) {
         $num = -1;
         $message = displayExeption($e);
         log::add('tesla', 'error', $e);
     }
     if ($num <= 0) {
         if ($message == '') {
             $message = "Aucun vehicule identifie via l'API Tesla";
         }
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __($message, __FILE__)));
         return;
     }
     foreach ($list->{'response'} as $car) {
         $eqLogic = self::byLogicalId($car->{'vehicle_id'}, 'tesla');
         if (!is_object($eqLogic)) {
             $eqLogic = new eqLogic();
             $eqLogic->setEqType_name('tesla');
             $eqLogic->setIsEnable(1);
             $eqLogic->setLogicalId($car->{'vehicle_id'});
             $eqLogic->setName($car->{'display_name'});
             $eqLogic->setConfiguration('options_codes', $car->{'options_codes'});
             $eqLogic->setConfiguration('vin', $car->{'vin'});
             $eqLogic->setConfiguration('state', $car->{'state'});
             $eqLogic->setConfiguration('id', $car->{'id'});
             $eqLogic->setIsVisible(1);
             $eqLogic->save();
             //$eqLogic = tesla::byId($eqLogic->getId());
             //$include_device = $eqLogic->getId();
             //$eqLogic->createCommand(false, $result);
             log::add('tesla', 'error', ' Voiture ajoutee, VIN: ' . $car->{'vin'});
             nodejs::pushUpdate('jeedom::alert', array('level' => 'info', 'message' => 'Nouvelle voiture ajoutee'));
         } else {
             // update data here
             $eqLogic->setName($car->{'display_name'});
             $eqLogic->setConfiguration('options_codes', $car->{'options_codes'});
             $eqLogic->setConfiguration('vin', $car->{'vin'});
             $eqLogic->setConfiguration('state', $car->{'state'});
             log::add('tesla', 'error', 'Voiture mise a jour, VIN: ' . $car->{'vin'});
             $eqLogic->save();
         }
     }
     return;
 }
Example #4
0
 public static function syncEqLogicWithRazberry($_serverId = 1)
 {
     $results = self::callRazberry('/ZWaveAPI/Data/0', $_serverId);
     $findDevice = array();
     $include_device = '';
     $razberry_id = zwave::getZwaveInfo('controller::data::nodeId::value', $_serverId);
     $findConfiguration = true;
     foreach ($results['devices'] as $nodeId => $result) {
         $findDevice[$nodeId] = $nodeId;
         if ($nodeId != $razberry_id) {
             if (!is_object(self::getEqLogicByLogicalIdAndServerId($nodeId, $_serverId))) {
                 $eqLogic = new eqLogic();
                 $eqLogic->setEqType_name('zwave');
                 $eqLogic->setIsEnable(1);
                 $eqLogic->setName('Device ' . $nodeId);
                 $eqLogic->setLogicalId($nodeId);
                 $eqLogic->setConfiguration('serverID', $_serverId);
                 $eqLogic->setIsVisible(1);
                 $eqLogic->save();
                 $eqLogic = zwave::byId($eqLogic->getId());
                 $eqLogic->InterviewForce();
                 for ($i = 0; $i < 30; $i++) {
                     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Pause de ', __FILE__) . (30 - $i) . __(' pour interview forcé du module', __FILE__)));
                     sleep(1);
                 }
                 $include_device = $eqLogic->getId();
                 $findConfiguration = false;
                 $result = self::callRazberry('/ZWaveAPI/Run/devices[' . $eqLogic->getLogicalId() . ']', $_serverId);
                 $data = $result['data'];
                 if (isset($data['manufacturerId']['value']) && isset($data['manufacturerProductType']['value']) && isset($data['manufacturerProductId']['value'])) {
                     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Recherche, si nécessaire, de la configuration sur le market', __FILE__)));
                     sleep(1);
                     try {
                         $market_rpc = market::getJsonRpc();
                         if ($market_rpc->sendRequest('market::searchZwaveModuleConf', array('manufacturerId' => $data['manufacturerId']['value'], 'manufacturerProductType' => $data['manufacturerProductType']['value'], 'manufacturerProductId' => $data['manufacturerProductId']['value']))) {
                             foreach ($market_rpc->getResult() as $logicalId => $result) {
                                 if (isset($result['id'])) {
                                     $markets[$logicalId] = market::construct($result);
                                 }
                             }
                             if (count($markets) == 1) {
                                 $market = $markets[0];
                                 $update = update::byLogicalId($market->getLogicalId());
                                 if (!is_object($update)) {
                                     if ($market->getStatus('stable') == 1) {
                                         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Configuration trouvée en stable : ', __FILE__) . $market->getName() . __(' installation en cours', __FILE__)));
                                         sleep(1);
                                         $market->install();
                                     } else {
                                         if ($market->getStatus('beta') == 1) {
                                             nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Configuration trouvée en beta : ', __FILE__) . $market->getName() . __(' installation en cours', __FILE__)));
                                             sleep(1);
                                             $market->install('beta');
                                         }
                                     }
                                 }
                             }
                         }
                     } catch (Exception $e) {
                     }
                 }
                 /* 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']) {
                         $findConfiguration = true;
                         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Périphérique reconnu : ', __FILE__) . $device['name'] . '!! (Manufacturer ID : ' . $data['manufacturerId']['value'] . ', Product type : ' . $data['manufacturerProductType']['value'] . ', Product ID : ' . $data['manufacturerProductId']['value'] . __('). Configuration en cours veuillez patienter...', __FILE__)));
                         sleep(1);
                         $eqLogic->setConfiguration('device', $device_id);
                         $eqLogic->save();
                         for ($i = 0; $i < 5; $i++) {
                             nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Pause de ', __FILE__) . (5 - $i) . __(' secondes pour synchronisation avec le module', __FILE__)));
                             sleep(1);
                         }
                         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Mise à jour forcée des valeurs des commandes', __FILE__)));
                         $listServerZway = self::listServerZway();
                         if ($listServerZway[$_serverId]['isOpenZwave'] != 1) {
                             $eqLogic->forceUpdate();
                         }
                         break;
                     }
                 }
             }
         }
     }
     if (config::byKey('autoRemoveExcludeDevice', 'zwave') == 1 && count($findDevice) > 1) {
         foreach (self::byType('zwave') as $eqLogic) {
             if (!isset($findDevice[$eqLogic->getLogicalId()]) && $eqLogic->getConfiguration('serverID') == $_serverId) {
                 $eqLogic->remove();
             }
         }
     }
     nodejs::pushUpdate('zwave::includeDevice', $include_device);
     if (!$findConfiguration) {
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Votre module n\'est pas reconnu, veuillez récupérer sa configuration sur le market si celle ci est disponible', __FILE__)));
     } else {
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
     }
 }