public function applyModuleConfiguration()
 {
     if ($this->getConfiguration('device') == '') {
         return true;
     }
     $device = self::devicesParameters($this->getConfiguration('device'));
     if (!is_array($device) || !isset($device['commands'])) {
         return true;
     }
     if (isset($device['configuration'])) {
         foreach ($device['configuration'] as $key => $value) {
             $this->setConfiguration($key, $value);
         }
     }
     $this->setConfiguration('applyDevice', $this->getConfiguration('device'));
     $cmd_order = 0;
     $link_cmds = array();
     foreach ($device['commands'] as $command) {
         if (!isset($command['configuration']['instanceId'])) {
             $command['configuration']['instanceId'] = 0;
         }
         $cmd = null;
         foreach ($this->getCmd() as $liste_cmd) {
             if ($liste_cmd->getConfiguration('instanceId', 0) == $command['configuration']['instanceId'] && $liste_cmd->getConfiguration('class') == $command['configuration']['class'] && $liste_cmd->getConfiguration('value') == $command['configuration']['value']) {
                 $cmd = $liste_cmd;
                 break;
             }
         }
         try {
             if ($cmd == null || !is_object($cmd)) {
                 $cmd = new zwaveCmd();
                 $cmd->setOrder($cmd_order);
                 $cmd->setEqLogic_id($this->getId());
             } else {
                 $command['name'] = $cmd->getName();
             }
             utils::a2o($cmd, $command);
             if (isset($command['value'])) {
                 $cmd->setValue(null);
             }
             $cmd->save();
             if (isset($command['value'])) {
                 $link_cmds[$cmd->getId()] = $command['value'];
             }
             $cmd_order++;
         } catch (Exception $exc) {
             error_log($exc->getMessage());
         }
     }
     if (count($link_cmds) > 0) {
         foreach ($this->getCmd() as $eqLogic_cmd) {
             foreach ($link_cmds as $cmd_id => $link_cmd) {
                 if ($link_cmd == $eqLogic_cmd->getName()) {
                     $cmd = cmd::byId($cmd_id);
                     if (is_object($cmd)) {
                         $cmd->setValue($eqLogic_cmd->getId());
                         $cmd->save();
                     }
                 }
             }
         }
     }
     $this->save();
 }
Exemple #2
0
 public function applyModuleConfiguration($_light = false)
 {
     $this->setConfiguration('applyDevice', $this->getConfiguration('device'));
     if ($this->getConfiguration('device') == '') {
         $this->save();
         return true;
     }
     $device = self::devicesParameters($this->getConfiguration('device'));
     if (!is_array($device) || !isset($device['commands'])) {
         return true;
     }
     if (isset($device['configuration'])) {
         foreach ($device['configuration'] as $key => $value) {
             try {
                 $this->setConfiguration($key, $value);
             } catch (Exception $e) {
             }
         }
     }
     $cmd_order = 0;
     $link_cmds = array();
     $razberry_id = zwave::getZwaveInfo('controller::data::nodeId::value', $this->getConfiguration('serverID', 1));
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Mise en place des groupes par défaut', __FILE__)));
     if (isset($device['groups']) && isset($device['groups']['associate'])) {
         foreach ($this->getAssociation() as $group_id => $associate) {
             foreach ($associate['nodes']['value'] as $node) {
                 if ($node['id'] == $razberry_id && !isset($device['groups']['associate'][$group_id])) {
                     $this->changeAssociation('remove', $group_id, $razberry_id);
                 }
             }
         }
         foreach ($device['groups']['associate'] as $group) {
             try {
                 $this->changeAssociation('add', $group, $razberry_id);
             } catch (Exception $e) {
             }
         }
     }
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Création des commandes', __FILE__)));
     if (self::$_listZwaveServer == null) {
         self::listServerZway();
     }
     if (isset($device['commands_openzwave']) && self::$_listZwaveServer[$this->getConfiguration('serverID', 1)]['isOpenZwave'] == 1) {
         $commands = $device['commands_openzwave'];
     } else {
         $commands = $device['commands'];
     }
     foreach ($commands as &$command) {
         if (!isset($command['configuration']['instanceId'])) {
             $command['configuration']['instanceId'] = 0;
         }
         if (!isset($command['configuration']['class'])) {
             $command['configuration']['class'] = '';
         }
         $cmd = null;
         foreach ($this->getCmd() as $liste_cmd) {
             if ($liste_cmd->getConfiguration('instanceId', 0) == $command['configuration']['instanceId'] && $liste_cmd->getConfiguration('class') == $command['configuration']['class'] && $liste_cmd->getConfiguration('value') == $command['configuration']['value']) {
                 $cmd = $liste_cmd;
                 break;
             }
         }
         try {
             if ($cmd == null || !is_object($cmd)) {
                 $cmd = new zwaveCmd();
                 $cmd->setOrder($cmd_order);
                 $cmd->setEqLogic_id($this->getId());
             } else {
                 $command['name'] = $cmd->getName();
                 if (isset($command['display'])) {
                     unset($command['display']);
                 }
             }
             utils::a2o($cmd, $command);
             if (isset($command['value'])) {
                 $cmd->setValue(null);
             }
             $cmd->save();
             if (isset($command['value'])) {
                 $link_cmds[$cmd->getId()] = $command['value'];
             }
             $cmd_order++;
         } catch (Exception $exc) {
         }
     }
     if (count($link_cmds) > 0) {
         foreach ($this->getCmd() as $eqLogic_cmd) {
             foreach ($link_cmds as $cmd_id => $link_cmd) {
                 if ($link_cmd == $eqLogic_cmd->getName()) {
                     $cmd = cmd::byId($cmd_id);
                     if (is_object($cmd)) {
                         $cmd->setValue($eqLogic_cmd->getId());
                         $cmd->save();
                     }
                 }
             }
         }
     }
     if (isset($device['wakeup']) && is_numeric($device['wakeup']) && $device['wakeup'] > 1) {
         try {
             $this->setWakeUp($device['wakeup']);
         } catch (Exception $ex) {
         }
     }
     if (!$_light) {
         try {
             nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Récupération de la configuration d\'origine du module', __FILE__)));
             $configuration = $this->getDeviceConfiguration(true);
             $optimiseConfigFound = false;
             foreach ($configuration as $id => &$parameter) {
                 if (isset($device['parameters'][$id]['set'])) {
                     $optimiseConfigFound = true;
                     $configuration[$id]['value'] = $device['parameters'][$id]['set'];
                 }
             }
             if ($optimiseConfigFound) {
                 nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Envoi de la configuration optimisée Jeedom', __FILE__)));
                 $this->setDeviceConfiguration($configuration);
             }
         } catch (Exception $ex) {
         }
         if (isset($device['configure']) && is_array($device['configure'])) {
             try {
                 nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Execution des commandes post-configuration', __FILE__)));
                 $this->applyDeviceConfigurationCommand();
             } catch (Exception $ex) {
             }
         }
     }
     $this->save();
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
 }