예제 #1
0
 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' => ''));
 }
예제 #2
0
         throw new Exception(__('Zwave eqLogic non trouvé : ', __FILE__) . init('id'));
     }
     foreach ($eqLogic->getCmd() as $cmd) {
         $cmd->remove();
     }
     $eqLogic->createCommand(true);
     ajax::success();
 }
 if (init('action') == 'migrateZwave') {
     $cmd = 'sudo php ' . dirname(__FILE__) . '/../../script/migrate.php';
     $cmd .= ' >> ' . log::getPathToLog('openzwave_migrate') . ' 2>&1 &';
     exec($cmd);
     ajax::success();
 }
 if (init('action') == 'getAllPossibleConf') {
     $eqLogic = openzwave::byId(init('id'));
     if (!is_object($eqLogic)) {
         ajax::success();
     }
     ajax::success($eqLogic->getConfFilePath(true));
 }
 if (init('action') == 'getConfiguration') {
     if (init('translation') == 1 && config::byKey('language', 'core', 'fr_FR') != 'fr_FR') {
         ajax::success();
     }
     $id = init('manufacturer_id') . '.' . init('product_type') . '.' . init('product_id');
     $files = ls(dirname(__FILE__) . '/../config/devices', $id . '_*.json', false, array('files', 'quiet'));
     foreach (ls(dirname(__FILE__) . '/../config/devices', '*', false, array('folders', 'quiet')) as $folder) {
         foreach (ls(dirname(__FILE__) . '/../config/devices/' . $folder, $id . '_*.json', false, array('files', 'quiet')) as $file) {
             $files[] = $folder . $file;
         }