if (init('action') == 'getModuleInfo') { $eqLogic = zwave::byId(init('id')); if (!is_object($eqLogic)) { throw new Exception('Razberry plugin non trouvé : ' . init('id')); } ajax::success($eqLogic->getInfo()); } if (init('action') == 'getDeviceConfiguration') { $eqLogic = zwave::byId(init('id')); if (!is_object($eqLogic)) { throw new Exception('Razberry plugin non trouvé : ' . init('id')); } ajax::success($eqLogic->getDeviceConfiguration(init('forceRefresh', false), init('parameter_id', null))); } if (init('action') == 'setDeviceConfiguration') { $eqLogic = zwave::byId(init('id')); if (!is_object($eqLogic)) { throw new Exception('Razberry plugin non trouvé : ' . init('id')); } ajax::success($eqLogic->setDeviceConfiguration(json_decode(init('configurations'), true))); } if (init('action') == 'inspectQueue') { ajax::success(zwave::inspectQueue()); } if (init('action') == 'getRoutingTable') { ajax::success(zwave::getRoutingTable()); } if (init('action') == 'updateRoute') { ajax::success(zwave::updateRoute()); } throw new Exception('Aucune methode correspondante');
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' => '')); } }