diff --git a/core/class/zwavejs.class.php b/core/class/zwavejs.class.php index 8419e95c..a943fc0c 100644 --- a/core/class/zwavejs.class.php +++ b/core/class/zwavejs.class.php @@ -21,7 +21,7 @@ class zwavejs extends eqLogic { - + public static function dependancy_end() { config::save('zwavejsVersion', config::byKey('wantedVersion', __CLASS__), __CLASS__); } @@ -136,7 +136,7 @@ public static function cron() { } } } - + public static function cronHourly() { $deamon_info = self::deamon_info(); if ($deamon_info['state'] != 'ok') { @@ -182,7 +182,7 @@ public static function configureSettings($_path) { $settings['zwave']['logEnabled'] = true; $settings['zwave']['logToFile'] = false; $settings['zwave']['serverEnabled'] = false; - if (config::byKey('softReset', __CLASS__,1) == 1){ + if (config::byKey('softReset', __CLASS__, 1) == 1) { $settings['zwave']['enableSoftReset'] = true; } else { $settings['zwave']['enableSoftReset'] = false; @@ -283,9 +283,9 @@ public static function deamon_info() { } $port = config::byKey('port', __CLASS__); if ($port == 'none') { - $return['launchable'] = 'nok'; - $return['launchable_message'] = __("Le port n'est pas configuré", __FILE__); - }else{ + $return['launchable'] = 'nok'; + $return['launchable_message'] = __("Le port n'est pas configuré", __FILE__); + } else { $port = jeedom::getUsbMapping($port); if (is_array($port) || @!file_exists($port)) { $return['launchable'] = 'nok'; @@ -355,7 +355,7 @@ public static function deamon_start($_debug = false) { $cmd .= ' KEY_S2_Authenticated=' . config::byKey('s2key_auth', __CLASS__); $cmd .= ' KEY_S2_AccessControl=' . config::byKey('s2key_access', __CLASS__); $cmd .= ' SESSION_SECRET=' . 'jeedomSession'; - $cmd .= ' yarn start'; + $cmd .= ' npm start'; log::add(__CLASS__, 'info', __('Démarrage du démon ZwaveJS', __FILE__) . ' : ' . $cmd); exec(system::getCmdSudo() . $cmd . ' >> ' . log::getPathToLog('zwavejsd') . ' 2>&1 &'); $i = 0; @@ -480,13 +480,12 @@ public static function handleClients($_clients) { // log::add(__CLASS__, 'debug', $key); if ($key == 'api') { self::handleApi($value); - } - else if ($key == 'version') { + } else if ($key == 'version') { config::save('zwavejsVersion', $value['value'], __CLASS__); event::add('zwavejs::dependancy_end', array()); - if (config::byKey('wantedVersion', __CLASS__) != config::byKey('zwavejsVersion', __CLASS__)){ + if (config::byKey('wantedVersion', __CLASS__) != config::byKey('zwavejsVersion', __CLASS__)) { sleep(2); - message::add('zwavejs',__("Votre version de ZwaveJS UI n'est pas celle recommandée par le plugin. Vous utilisez actuellement la version ", __FILE__). config::byKey('zwavejsVersion', __CLASS__) .'. '.__('Le plugin nécessite la version ', __FILE__). config::byKey('wantedVersion', __CLASS__) .'. '.__('Veuillez relancer les dépendances pour mettre à jour la librairie.', __FILE__)); + message::add('zwavejs', __("Votre version de ZwaveJS UI n'est pas celle recommandée par le plugin. Vous utilisez actuellement la version ", __FILE__) . config::byKey('zwavejsVersion', __CLASS__) . '. ' . __('Le plugin nécessite la version ', __FILE__) . config::byKey('wantedVersion', __CLASS__) . '. ' . __('Veuillez relancer les dépendances pour mettre à jour la librairie.', __FILE__)); } } } @@ -513,11 +512,11 @@ public static function handleApi($_api) { foreach ($_api as $key => $value) { if ($key == 'abortFirmwareUpdate') { if (isset($value['success']) && $value['success']) { - event::add('zwavejs::firmware_update',array('node' => $value['args'][0], 'cancel'=>true)); + event::add('zwavejs::firmware_update', array('node' => $value['args'][0], 'cancel' => true)); } } else if ($key == 'restoreNVM') { if (isset($value['success']) && !$value['success']) { - event::add('zwavejs::restoreNVM',array('message' => $value['message'])); + event::add('zwavejs::restoreNVM', array('message' => $value['message'])); } } else if ($key == 'getInfo') { self::addFileEvent('getInfo', $value['result']); @@ -718,7 +717,7 @@ public static function handleNode($_node) { } else if ($key == 'node_firmware_update_progress') { $nodeData = $value['data'][0]; $updateData = $value['data'][1]; - event::add('zwavejs::firmware_update',array('node' => $nodeData['id'], 'progress'=>$updateData['progress'],'files'=>$updateData['currentFile'].'/'.$updateData['totalFiles'])); + event::add('zwavejs::firmware_update', array('node' => $nodeData['id'], 'progress' => $updateData['progress'], 'files' => $updateData['currentFile'] . '/' . $updateData['totalFiles'])); } } } @@ -782,7 +781,7 @@ public static function handleController($_controller) { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . __('Accorder la securité', __FILE__)); $securityClasses = $value['data'][0]['securityClasses']; $clientSideAuth = $value['data'][0]['clientSideAuth']; - event::add('zwavejs::grant_security_classes', array('classes'=>$securityClasses, 'auth'=>$clientSideAuth)); + event::add('zwavejs::grant_security_classes', array('classes' => $securityClasses, 'auth' => $clientSideAuth)); } else if ($key == 'validate_dsk') { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . __('Validation DSK', __FILE__)); event::add('zwavejs::validate_dsk', $value['data'][0]); @@ -835,10 +834,10 @@ public static function handleNodeNotification($_value_update) { if ($eqLogic->getIsEnable()) { // log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . "Le nœud avec l'id : " . $node['id'] . ' existe ' . $eqLogic->getHumanName()); } - $eqLogic->handleNotificationUpdate($change,$cc); + $eqLogic->handleNotificationUpdate($change, $cc); } } - + public static function handleNodeValueUpdate($_value_update) { // log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . "Traitement d'un update de value d'un node"); // log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . json_encode($_value_update)); @@ -869,13 +868,13 @@ public static function handleNodeValueUpdateDirect($_nodeId, $_value_update) { $eqLogic->updateCmd('0-0-nodeStatus', $data['status']); if ($data['status'] == 'Awake') { $eqLogic->setConfiguration('lastWakeUp', time()); - if ($eqLogic->getConfiguration('missedWakeup', false)){ + if ($eqLogic->getConfiguration('missedWakeup', false)) { $action = '' . __('Equipement', __FILE__) . ''; - if (config::byKey('notifyMissWakeup', __CLASS__, 1)==1 && $eqLogic->getIsEnable()==1){ - if (version_compare(jeedom::version(),'4.4.0','>=')){ - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de se réveiller après avoir raté au minimum 4 réveils.', $action,'Awake-'.$eqLogic->getLogicalId(),true,'alerting'); + if (config::byKey('notifyMissWakeup', __CLASS__, 1) == 1 && $eqLogic->getIsEnable() == 1) { + if (version_compare(jeedom::version(), '4.4.0', '>=')) { + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de se réveiller après avoir raté au minimum 4 réveils.', $action, 'Awake-' . $eqLogic->getLogicalId(), true, 'alerting'); } else { - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de se réveiller après avoir raté au minimum 4 réveils.', $action,'Awake-'.$eqLogic->getLogicalId(),true); + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de se réveiller après avoir raté au minimum 4 réveils.', $action, 'Awake-' . $eqLogic->getLogicalId(), true); } } } @@ -884,21 +883,21 @@ public static function handleNodeValueUpdateDirect($_nodeId, $_value_update) { } if ($data['status'] == 'Dead' && $currentValue == 'Alive') { $action = '' . __('Equipement', __FILE__) . ''; - if (config::byKey('notifyDead', __CLASS__, 1)==1 && $eqLogic->getIsEnable()==1){ - if (version_compare(jeedom::version(),'4.4.0','>=')){ - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de passer au statut Dead.', $action,'Dead-'.$eqLogic->getLogicalId(),true,'alerting'); + if (config::byKey('notifyDead', __CLASS__, 1) == 1 && $eqLogic->getIsEnable() == 1) { + if (version_compare(jeedom::version(), '4.4.0', '>=')) { + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de passer au statut Dead.', $action, 'Dead-' . $eqLogic->getLogicalId(), true, 'alerting'); } else { - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de passer au statut Dead.', $action,'Dead-'.$eqLogic->getLogicalId(),true); + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de passer au statut Dead.', $action, 'Dead-' . $eqLogic->getLogicalId(), true); } } } if ($data['status'] == 'Alive' && $currentValue == 'Dead') { $action = '' . __('Equipement', __FILE__) . ''; - if (config::byKey('notifyDead', __CLASS__, 1)==1 && $eqLogic->getIsEnable()==1){ - if (version_compare(jeedom::version(),'4.4.0','>=')){ - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de passer au statut Alive.', $action,'Alive-'.$eqLogic->getLogicalId(),true,'alertingReturnBack'); + if (config::byKey('notifyDead', __CLASS__, 1) == 1 && $eqLogic->getIsEnable() == 1) { + if (version_compare(jeedom::version(), '4.4.0', '>=')) { + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de passer au statut Alive.', $action, 'Alive-' . $eqLogic->getLogicalId(), true, 'alertingReturnBack'); } else { - message::add('zwavejs',"L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId(). ', vient de passer au statut Alive.', $action,'Alive-'.$eqLogic->getLogicalId(),true); + message::add('zwavejs', "L'équipement : " . $eqLogic->getHumanName(true) . ' avec le nodeId : ' . $eqLogic->getLogicalId() . ', vient de passer au statut Alive.', $action, 'Alive-' . $eqLogic->getLogicalId(), true); } } } @@ -923,12 +922,12 @@ public static function publishMqttValue($_node, $_path, $_args = array()) { // log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . 'Publication Mqtt Value' . $_node . ' ' . $_path . ' ' . json_encode($_args)); mqtt2::publish(config::byKey('prefix', __CLASS__, 'zwave') . '/' . $_node . '/' . $_path . '/set', $_args); } - + public static function cleanHistory() { foreach (self::byType(__CLASS__) as $eqLogic) { - $eqLogic->setCache('waiting',array()); + $eqLogic->setCache('waiting', array()); } - return ; + return; } public static function getInfo() { @@ -1011,15 +1010,15 @@ public static function setNodeValue($_fullpath, $_value) { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . $_fullpath . ' ' . $_value); $detailsPath = explode('-', $_fullpath, 2); $value = $_value; - if (strpos($_fullpath,'userCode') !== false){ - if (strpos($_value,'0x') !== false){ - $value = array("type"=>"Buffer", "data"=>array_map('hexdec', str_split(str_replace('0x','',$_value), 2))); + if (strpos($_fullpath, 'userCode') !== false) { + if (strpos($_value, '0x') !== false) { + $value = array("type" => "Buffer", "data" => array_map('hexdec', str_split(str_replace('0x', '', $_value), 2))); } else { - $value = '"'.$_value.'"'; + $value = '"' . $_value . '"'; } } self::publishMqttValue($detailsPath[0], str_replace('-', '/', $detailsPath[1]), $value); - self::handleSetHistory($_fullpath,$_value); + self::handleSetHistory($_fullpath, $_value); } public static function setPolling($_nodeId, $_cc, $_endpoint, $_property, $_value) { @@ -1040,11 +1039,11 @@ public static function handleSetHistory($_fullpath, $_value) { $endpoint = $elements[2]; $property = $elements[3]; $logical = $class . '-' . $endpoint . '-' . $property; - if (in_array($class,array('112','132','99'))){ - $waiting = $eqLogic->getCache('waiting',array()); - $waiting[$logical] = array('value'=>$_value,'date'=>date("d/m/Y H:i:s")); + if (in_array($class, array('112', '132', '99'))) { + $waiting = $eqLogic->getCache('waiting', array()); + $waiting[$logical] = array('value' => $_value, 'date' => date("d/m/Y H:i:s")); log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . $logical . ' ' . $_value); - $eqLogic->setCache('waiting',$waiting); + $eqLogic->setCache('waiting', $waiting); } } } @@ -1110,27 +1109,27 @@ public static function inclusion($_method, $_options) { $args['type'] = 'inclusion'; self::publishMqttApi($api, $args); } - + public static function grantSecurity($_security, $_auth) { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . __('Grant Security', __FILE__) . ' ' . $_security . ' ' . $_auth); $auth = false; $security = array(); - if ($_auth != "false"){ + if ($_auth != "false") { $auth = true; } foreach ($_security as $class) { - $security[]= intval($class); + $security[] = intval($class); } $args = array('args' => array(array('securityClasses' => $security, 'clientSideAuth' => $auth))); self::publishMqttApi('grantSecurityClasses', $args); } - + public static function validateDSK($_dsk) { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . __('Validation DSK', __FILE__) . ' ' . $_dsk); $args = array('args' => array($_dsk)); self::publishMqttApi('validateDSK', $args); } - + public static function abortInclusion() { log::add(__CLASS__, 'debug', '[' . __FUNCTION__ . '] ' . __('Annulation Inclusion', __FILE__)); $args = array(); @@ -1209,7 +1208,7 @@ public static function createEqLogic($_node, $_ignoreEvent = false) { public static function constructValuePage($_nodeId, $_values, $_nodeStatus) { $nodeValuesDict = array(); $eqLogic = self::byLogicalId($_nodeId, __CLASS__); - $waiting = $eqLogic->getCache('waiting',array()); + $waiting = $eqLogic->getCache('waiting', array()); $nodeValues = '