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' => '')); }
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; } } } } } }