public function stackData($params)
 {
     if (is_object($params)) {
         $paramsArray = utils::o2a($params);
     }
     nodejs::pushUpdate('influxdb::stackDataEqLogic', $paramsArray);
 }
Example #2
0
 public function execute(&$scenario = null)
 {
     if ($this->getOptions('enable', 1) == 0) {
         return;
     }
     $message = '';
     try {
         if ($this->getType() == 'element') {
             $element = scenarioElement::byId($this->getExpression());
             if (is_object($element)) {
                 $this->setLog($scenario, __('Exécution d\'un bloc élément : ', __FILE__) . $this->getExpression());
                 return $element->execute($scenario);
             }
             return;
         }
         $options = $this->getOptions();
         if (isset($options['enable'])) {
             unset($options['enable']);
         }
         if (is_array($options) && $this->getExpression() != 'wait') {
             foreach ($options as $key => $value) {
                 $options[$key] = str_replace('"', '', self::setTags($value, $scenario));
             }
         }
         if ($this->getType() == 'action') {
             if ($this->getExpression() == 'icon') {
                 if ($scenario != null) {
                     $options = $this->getOptions();
                     $this->setLog($scenario, __('Changement de l\'icone du scénario : ', __FILE__) . $options['icon']);
                     $scenario->setDisplay('icon', $options['icon']);
                     $scenario->save();
                 }
                 return;
             } else {
                 if ($this->getExpression() == 'wait') {
                     if (!isset($options['condition'])) {
                         return;
                     }
                     $result = false;
                     $occurence = 0;
                     $limit = isset($options['timeout']) && is_numeric($options['timeout']) ? $options['timeout'] : 7200;
                     while ($result !== true) {
                         $expression = self::setTags($options['condition'], $scenario);
                         $result = evaluate($expression);
                         if ($occurence > $limit) {
                             $this->setLog($scenario, __('[Wait] Condition valide par dépassement de temps', __FILE__));
                             return;
                         }
                         $occurence++;
                         sleep(1);
                     }
                     $this->setLog($scenario, __('[Wait] Condition valide : ', __FILE__) . $expression);
                     return;
                 } else {
                     if ($this->getExpression() == 'sleep') {
                         if (isset($options['duration'])) {
                             try {
                                 $options['duration'] = evaluate($options['duration']);
                             } catch (Exception $e) {
                             }
                             if (is_numeric($options['duration']) && $options['duration'] > 0) {
                                 $this->setLog($scenario, __('Pause de ', __FILE__) . $options['duration'] . __(' seconde(s)', __FILE__));
                                 if ($options['duration'] < 1) {
                                     return usleep($options['duration'] * 1000);
                                 } else {
                                     return sleep($options['duration']);
                                 }
                             }
                         }
                         $this->setLog($scenario, __('Aucune durée trouvée pour l\'action sleep ou la durée n\'est pas valide : ', __FILE__) . $options['duration']);
                         return;
                     } else {
                         if ($this->getExpression() == 'stop') {
                             if ($scenario != null) {
                                 $this->setLog($scenario, __('Arret du scénario', __FILE__));
                                 $scenario->setState('stop');
                                 $scenario->setPID('');
                                 $scenario->persistLog();
                                 $scenario->save();
                             }
                             die;
                         } else {
                             if ($this->getExpression() == 'log') {
                                 if ($scenario != null) {
                                     $scenario->setLog('Log : ' . $options['message']);
                                     if ($scenario->getConfiguration('speedPriority', 0) == 1) {
                                         $scenario->persistLog();
                                     }
                                 }
                                 return;
                             } else {
                                 if ($this->getExpression() == 'message') {
                                     message::add('scenario', $options['message']);
                                     return;
                                 } else {
                                     if ($this->getExpression() == 'equipement') {
                                         $eqLogic = eqLogic::byId(str_replace(array('#eqLogic', '#'), '', $this->getOptions('eqLogic')));
                                         if (!is_object($eqLogic)) {
                                             throw new Exception(__('Action sur l\'équipement impossible. Equipement introuvable - Vérifiez l\'id : ', __FILE__) . $this->getOptions('eqLogic'));
                                         }
                                         switch ($this->getOptions('action')) {
                                             case 'show':
                                                 $this->setLog($scenario, __('Equipement visible : ', __FILE__) . $eqLogic->getHumanName());
                                                 $eqLogic->setIsVisible(1);
                                                 $eqLogic->save();
                                                 break;
                                             case 'hide':
                                                 $this->setLog($scenario, __('Equipement masqué : ', __FILE__) . $eqLogic->getHumanName());
                                                 $eqLogic->setIsVisible(0);
                                                 $eqLogic->save();
                                                 break;
                                             case 'deactivate':
                                                 $this->setLog($scenario, __('Equipement désactivé : ', __FILE__) . $eqLogic->getHumanName());
                                                 $eqLogic->setIsEnable(0);
                                                 $eqLogic->save();
                                                 break;
                                             case 'activate':
                                                 $this->setLog($scenario, __('Equipement activé : ', __FILE__) . $eqLogic->getHumanName());
                                                 $eqLogic->setIsEnable(1);
                                                 $eqLogic->save();
                                                 break;
                                         }
                                         return;
                                     } else {
                                         if ($this->getExpression() == 'say') {
                                             $this->setLog($scenario, __('Je dis : ', __FILE__) . $options['message']);
                                             nodejs::pushUpdate('jeedom::say', $options['message']);
                                             return;
                                         } else {
                                             if ($this->getExpression() == 'gotodesign') {
                                                 $this->setLog($scenario, __('Changement design : ', __FILE__) . $options['plan_id']);
                                                 nodejs::pushUpdate('jeedom::gotoplan', $options['plan_id']);
                                                 return;
                                             } else {
                                                 if ($this->getExpression() == 'return') {
                                                     $this->setLog($scenario, __('Je vais retourner : ', __FILE__) . $options['message']);
                                                     $scenario->setReturn($scenario->getReturn() . $options['message']);
                                                     return;
                                                 } else {
                                                     if ($this->getExpression() == 'scenario') {
                                                         if ($scenario != null && $this->getOptions('scenario_id') == $scenario->getId()) {
                                                             $actionScenario =& $scenario;
                                                         } else {
                                                             $actionScenario = scenario::byId($this->getOptions('scenario_id'));
                                                         }
                                                         if (!is_object($actionScenario)) {
                                                             throw new Exception($scenario, __('Action sur scénario impossible. Scénario introuvable - Vérifiez l\'id : ', __FILE__) . $this->getOptions('scenario_id'));
                                                         }
                                                         switch ($this->getOptions('action')) {
                                                             case 'start':
                                                                 $this->setLog($scenario, __('Lancement du scénario : ', __FILE__) . $actionScenario->getName());
                                                                 if ($scenario != null) {
                                                                     $actionScenario->launch(false, __('Lancement provoqué par le scénario  : ', __FILE__) . $scenario->getHumanName());
                                                                 } else {
                                                                     $actionScenario->launch(false, __('Lancement provoqué', __FILE__));
                                                                 }
                                                                 break;
                                                             case 'stop':
                                                                 $this->setLog($scenario, __('Arrêt forcé du scénario : ', __FILE__) . $actionScenario->getName());
                                                                 $actionScenario->stop();
                                                                 break;
                                                             case 'deactivate':
                                                                 $this->setLog($scenario, __('Désactivation du scénario : ', __FILE__) . $actionScenario->getName());
                                                                 $actionScenario->setIsActive(0);
                                                                 $actionScenario->save();
                                                                 break;
                                                             case 'activate':
                                                                 $this->setLog($scenario, __('Activation du scénario : ', __FILE__) . $actionScenario->getName());
                                                                 $actionScenario->setIsActive(1);
                                                                 $actionScenario->save();
                                                                 break;
                                                         }
                                                         return;
                                                     } else {
                                                         if ($this->getExpression() == 'variable') {
                                                             $options['value'] = self::setTags($options['value']);
                                                             try {
                                                                 $result = evaluate($options['value']);
                                                                 if (!is_numeric($result)) {
                                                                     $result = $options['value'];
                                                                 }
                                                             } catch (Exception $ex) {
                                                                 $result = $options['value'];
                                                             }
                                                             $message = __('Affectation de la variable ', __FILE__) . $this->getOptions('name') . __(' => ', __FILE__) . $options['value'] . ' = ' . $result;
                                                             $this->setLog($scenario, $message);
                                                             $dataStore = new dataStore();
                                                             $dataStore->setType('scenario');
                                                             $dataStore->setKey($this->getOptions('name'));
                                                             $dataStore->setValue($result);
                                                             $dataStore->setLink_id(-1);
                                                             $dataStore->save();
                                                             return;
                                                         } else {
                                                             $cmd = cmd::byId(str_replace('#', '', $this->getExpression()));
                                                             if (is_object($cmd)) {
                                                                 if ($cmd->getSubtype() == 'slider' && isset($options['slider'])) {
                                                                     $options['slider'] = evaluate($options['slider']);
                                                                 }
                                                                 if (is_array($options) && count($options) != 0) {
                                                                     $this->setLog($scenario, __('Exécution de la commande ', __FILE__) . $cmd->getHumanName() . __(" avec comme option(s) : \n", __FILE__) . print_r($options, true));
                                                                 } else {
                                                                     $this->setLog($scenario, __('Exécution de la commande ', __FILE__) . $cmd->getHumanName());
                                                                 }
                                                                 if (is_object($scenario) && $scenario->getConfiguration('cmdNoWait', 0) == 1) {
                                                                     $options['speedAndNoErrorReport'] = true;
                                                                 }
                                                                 return $cmd->execCmd($options);
                                                             }
                                                             $this->setLog($scenario, __('[Erreur] Aucune commande trouvée pour ', __FILE__) . $this->getExpression());
                                                             return;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($this->getType() == 'condition') {
                 $expression = self::setTags($this->getExpression(), $scenario, true);
                 $message = __('Evaluation de la condition : [', __FILE__) . $expression . '] = ';
                 $result = evaluate($expression);
                 if (is_bool($result)) {
                     if ($result) {
                         $message .= __('Vrai', __FILE__);
                     } else {
                         $message .= __('Faux', __FILE__);
                     }
                 } else {
                     $message .= $result;
                 }
                 $this->setLog($scenario, $message);
                 return $result;
             } else {
                 if ($this->getType() == 'code') {
                     $this->setLog($scenario, __('Exécution d\'un bloc code', __FILE__));
                     return eval($this->getExpression());
                 }
             }
         }
     } catch (Exception $e) {
         $this->setLog($scenario, $message . $e->getMessage());
     }
 }
 public function createCommand($_update = false, $_data = null)
 {
     $return = array();
     if (!is_numeric($this->getLogicalId())) {
         return;
     }
     if (is_file(dirname(__FILE__) . '/../config/devices/' . $this->getConfFilePath())) {
         $this->loadCmdFromConf($_update);
         return;
     }
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Création des commandes en mode automatique', __FILE__)));
     if ($_data == null) {
         $results = self::callOpenzwave('/ZWaveAPI/Run/devices[' . $this->getLogicalId() . ']', $this->getConfiguration('serverID', 1));
     } else {
         $results = $_data;
     }
     if (isset($results['instances']) && is_array($results['instances'])) {
         foreach ($results['instances'] as $instanceID => $instance) {
             if (isset($instance['commandClasses']) && is_array($instance['commandClasses'])) {
                 foreach ($instance['commandClasses'] as $ccId => $commandClasses) {
                     if (isset($commandClasses['data']) && is_array($commandClasses['data'])) {
                         foreach ($commandClasses['data'] as $index => $data) {
                             if (isset($data['genre']) && $data['genre'] != 'Config' && $data['genre'] != 'System') {
                                 $cmd_info = null;
                                 $cmd = null;
                                 if (count($results['instances']) > 2) {
                                     $cmd_name_number = $instanceID + 1;
                                     $cmd_name = $data['name'] . ' ' . $index . ' ' . $cmd_name_number;
                                 } else {
                                     $cmd_name = $data['name'] . ' ' . $index;
                                 }
                                 if (strpos($cmd_name, 'Unknown') !== false || strpos($cmd_name, 'Unused') !== false) {
                                     continue;
                                 }
                                 if (!$data['write_only']) {
                                     $cmd_info = new openzwaveCmd();
                                     $cmd_info->setType('info');
                                     $cmd_info->setEqLogic_id($this->getId());
                                     $cmd_info->setUnite($data['units']);
                                     if ($data['read_only']) {
                                         $cmd_info->setName($cmd_name);
                                     } else {
                                         $cmd_info->setName('Info ' . $cmd_name);
                                     }
                                     $cmd_info->setConfiguration('instanceId', $instanceID);
                                     $cmd_info->setConfiguration('class', $ccId);
                                     $cmd_info->setConfiguration('value', 'data[' . $index . '].val');
                                     switch ($data['type']) {
                                         case 'bool':
                                             $cmd_info->setSubType('binary');
                                             break;
                                         case 'int':
                                             $cmd_info->setSubType('numeric');
                                             $cmd_info->setIsHistorized(1);
                                             break;
                                         case 'float':
                                             $cmd_info->setSubType('numeric');
                                             $cmd_info->setIsHistorized(1);
                                             break;
                                         default:
                                             $cmd_info->setSubType('string');
                                             break;
                                     }
                                     $cmd_info->save();
                                 }
                                 if (!$data['read_only']) {
                                     switch ($data['type']) {
                                         case 'bool':
                                             $cmd = new openzwaveCmd();
                                             $cmd->setSubType('other');
                                             $cmd->setType('action');
                                             $cmd->setEqLogic_id($this->getId());
                                             $cmd->setConfiguration('instanceId', $instanceID);
                                             $cmd->setConfiguration('class', $ccId);
                                             if ($data['typeZW'] == 'Button') {
                                                 $cmd->setName($cmd_name);
                                                 $cmd->setConfiguration('value', 'data[' . $index . '].PressButton()');
                                             } else {
                                                 $cmd->setName($cmd_name . ' On');
                                                 $cmd->setConfiguration('value', 'data[' . $index . '].Set(255)');
                                             }
                                             if (is_object($cmd_info)) {
                                                 $cmd->setValue($cmd_info->getId());
                                                 $cmd->setTemplate('dashboard', 'light');
                                                 $cmd->setTemplate('mobile', 'light');
                                                 $cmd_info->setIsVisible(0);
                                                 $cmd_info->save();
                                             }
                                             $cmd->save();
                                             $cmd = new openzwaveCmd();
                                             $cmd->setSubType('other');
                                             $cmd->setType('action');
                                             $cmd->setEqLogic_id($this->getId());
                                             $cmd->setConfiguration('instanceId', $instanceID);
                                             $cmd->setConfiguration('class', $ccId);
                                             if ($data['typeZW'] == 'Button') {
                                                 $cmd->setName($cmd_name . ' Stop');
                                                 $cmd->setIsVisible(0);
                                                 $cmd->setConfiguration('value', 'data[' . $index . '].ReleaseButton()');
                                             } else {
                                                 $cmd->setName($cmd_name . ' Off');
                                                 $cmd->setConfiguration('value', 'data[' . $index . '].Set(0)');
                                             }
                                             if (is_object($cmd_info)) {
                                                 $cmd->setValue($cmd_info->getId());
                                                 $cmd->setTemplate('dashboard', 'light');
                                                 $cmd->setTemplate('mobile', 'light');
                                                 $cmd_info->setIsVisible(0);
                                                 $cmd_info->save();
                                             }
                                             $cmd->save();
                                             break;
                                         case 'int':
                                             $cmd = new openzwaveCmd();
                                             $cmd->setType('action');
                                             $cmd->setEqLogic_id($this->getId());
                                             $cmd->setName($cmd_name);
                                             $cmd->setConfiguration('instanceId', $instanceID);
                                             $cmd->setConfiguration('class', $ccId);
                                             $cmd->setConfiguration('value', 'data[' . $index . '].Set(#slider#)');
                                             $cmd->setSubType('slider');
                                             if (is_object($cmd_info)) {
                                                 $cmd->setValue($cmd_info->getId());
                                                 $cmd_info->setIsVisible(0);
                                                 $cmd_info->save();
                                             }
                                             $cmd->save();
                                             break;
                                         case 'float':
                                             $cmd = new openzwaveCmd();
                                             $cmd->setType('action');
                                             $cmd->setEqLogic_id($this->getId());
                                             $cmd->setName($cmd_name);
                                             $cmd->setConfiguration('instanceId', $instanceID);
                                             $cmd->setConfiguration('class', $ccId);
                                             $cmd->setConfiguration('value', 'data[' . $index . '].Set(#slider#)');
                                             $cmd->setSubType('slider');
                                             if (is_object($cmd_info)) {
                                                 $cmd->setValue($cmd_info->getId());
                                                 $cmd_info->setIsVisible(0);
                                                 $cmd_info->save();
                                             }
                                             $cmd->save();
                                             break;
                                         case 'List':
                                             foreach (explode(';', $data['data_items']) as $value) {
                                                 if (strpos($value, 'Unknown') !== false || strpos($cmd_name, 'Unused') !== false) {
                                                     continue;
                                                 }
                                                 $cmd = new openzwaveCmd();
                                                 $cmd->setType('action');
                                                 $cmd->setEqLogic_id($this->getId());
                                                 $cmd->setName($value);
                                                 $cmd->setConfiguration('instanceId', $instanceID);
                                                 $cmd->setConfiguration('class', $ccId);
                                                 $cmd->setConfiguration('value', 'data[' . $index . '].Set(' . $value . ')');
                                                 $cmd->setSubType('other');
                                                 $cmd->save();
                                             }
                                             break;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
 }
Example #4
0
 public function event($_value, $_loop = 1)
 {
     if (trim($_value) === '' && $_value !== false || $_loop > 4 || $this->getType() != 'info') {
         return;
     }
     $value = $this->formatValue($_value);
     if ($this->getSubType() == 'numeric' && $value > $this->getConfiguration('maxValue', $value) && $value < $this->getConfiguration('minValue', $value) && strpos($value, 'error') === false) {
         return;
     }
     $eqLogic = $this->getEqLogic();
     if (!is_object($eqLogic) || $eqLogic->getIsEnable() == 0) {
         return;
     }
     $collectDate = $this->getCollectDate() != '' ? $this->getCollectDate() : date('Y-m-d H:i:s');
     $valueDate = $collectDate;
     if ($this->execCmd(null, 2) == $value) {
         if (strpos($value, 'error') === false) {
             $eqLogic->setStatus('lastCommunication', $collectDate);
         }
         if ($this->getConfiguration('doNotRepeatEvent', 0) == 1) {
             return;
         }
         $valueDate = $this->getValueDate();
     }
     $_loop++;
     $this->setCollectDate($collectDate);
     $this->setValueDate($valueDate);
     log::add('event', 'event', __('Evènement sur la commande ', __FILE__) . $this->getHumanName() . __(' valeur : ', __FILE__) . $value);
     cache::set('cmd' . $this->getId(), $value, $this->getCacheLifetime(), array('collectDate' => $this->getCollectDate(), 'valueDate' => $this->getValueDate()));
     scenario::check($this);
     $this->setCollect(0);
     $eqLogic->emptyCacheWidget();
     $nodeJs = array(array('cmd_id' => $this->getId()));
     $foundInfo = false;
     foreach (self::byValue($this->getId(), null, true) as $cmd) {
         if ($cmd->getType() == 'action') {
             $nodeJs[] = array('cmd_id' => $cmd->getId());
         } else {
             if ($_loop > 1) {
                 $cmd->event($cmd->execute(), $_loop);
             } else {
                 $foundInfo = true;
             }
         }
     }
     nodejs::pushUpdate('eventCmd', $nodeJs);
     if ($foundInfo) {
         listener::backgroundCalculDependencyCmd($this->getId());
     }
     listener::check($this->getId(), $value);
     if (strpos($value, 'error') === false) {
         $eqLogic->setStatus('lastCommunication', $collectDate);
         $this->addHistoryValue($value, $this->getCollectDate());
     } else {
         $this->addHistoryValue(null, $this->getCollectDate());
     }
     $this->checkReturnState($value);
     $this->checkCmdAlert($value);
     $this->pushUrl($value);
 }
Example #5
0
                        $cmd->handleUpdateValue($result);
                    }
                }
            }
        }
    }
}
if (isset($results['controller'])) {
    if (isset($results['controller']['state'])) {
        $jeeNetwork = jeeNetwork::byId($results['serverId']);
        if (is_object($jeeNetwork) || $results['serverId'] == 0) {
            nodejs::pushUpdate('zwave::controller.data.controllerState', array('name' => $results['serverId'] == 0 ? 'local' : $jeeNetwork->getName(), 'state' => $results['controller']['state']['value'], 'serverId' => $results['serverId']));
        }
    }
    if (isset($results['controller']['excluded'])) {
        nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Un périphérique Z-Wave est en cours d\'exclusion. Logical ID : ', __FILE__) . $results['controller']['excluded']['value']));
        sleep(2);
        openzwave::syncEqLogicWithOpenZwave($results['serverId'], $results['controller']['excluded']['value']);
    }
    if (isset($results['controller']['included'])) {
        for ($i = 0; $i < 10; $i++) {
            nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Nouveau module Z-Wave détecté. Début de l\'intégration.Pause de ', __FILE__) . (10 - $i) . __(' pour synchronisation avec le module', __FILE__)));
            sleep(1);
        }
        nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Inclusion en cours...', __FILE__)));
        openzwave::syncEqLogicWithOpenZwave($results['serverId'], $results['controller']['included']['value']);
    }
}
if (isset($results['message'])) {
    log::add('openzwave', 'error', $results['message']);
}
Example #6
0
 public static function pull()
 {
     $cache = cache::byKey('zwave::lastUpdate');
     $http = new com_http(self::makeBaseUrl() . '/ZWaveAPI/Data/' . $cache->getValue(strtotime(date('Y-m-d H:i:s')) - 86400));
     $results = json_decode(self::handleError($http->exec()), true);
     if (is_array($results)) {
         foreach ($results as $key => $result) {
             switch ($key) {
                 case 'controller.data.controllerState':
                     nodejs::pushUpdate('zwave::' . $key, $result['value']);
                     break;
                 case 'controller.data.lastExcludedDevice':
                     if ($result['value'] != null) {
                         nodejs::pushNotification('Razberry', 'Un périphérique Z-Wave vient d\'être exclu. Logical ID : ' . $result['value']);
                         self::syncEqLogicWithRazberry();
                     }
                     break;
                 case 'controller.data.lastIncludedDevice':
                     if ($result['value'] != null) {
                         nodejs::pushNotification('Razberry', 'Un périphérique Z-Wave vient d\'être inclu. Logical ID : ' . $result['value']);
                         self::syncEqLogicWithRazberry();
                     }
                     break;
                 default:
                     $explodeKey = explode('.', $key);
                     if (count($explodeKey) > 5) {
                         $nodeId = intval($explodeKey[1]);
                         $instanceId = intval($explodeKey[3]);
                         $class = intval($explodeKey[5]);
                         for ($i = 0; $i < 6; $i++) {
                             array_shift($explodeKey);
                         }
                         $attribut = implode('.', $explodeKey);
                         foreach (self::byLogicalId($nodeId, 'zwave') as $eqLogic) {
                             foreach ($eqLogic->getCmd() as $cmd) {
                                 if ($cmd->getConfiguration('instanceId') == $instanceId && $cmd->getConfiguration('class') == '0x' . dechex($class)) {
                                     $configurationValue = $cmd->getConfiguration('value');
                                     if (strpos($configurationValue, '[') !== false && strpos($configurationValue, ']') !== false) {
                                         $configurationValue = str_replace(']', '', str_replace('[', '.', $configurationValue));
                                     }
                                     if (strpos($configurationValue, $attribut) !== false) {
                                         if (isset($result['val'])) {
                                             $value = zwaveCmd::handleResult($result['val']);
                                         } else {
                                             if (isset($result['level'])) {
                                                 $value = zwaveCmd::handleResult($result['level']);
                                             } else {
                                                 $value = zwaveCmd::handleResult($result);
                                             }
                                         }
                                         if ($value === '') {
                                             log::add('zwave', 'info', 'Event sur ' . $cmd->getId() . ' / ' . $cmd->getName() . ' mais aucun valeur trouvée. Event result :' . print_r($result, true));
                                             $value = $cmd->execute();
                                         }
                                         $cmd->event($value);
                                     }
                                 }
                             }
                         }
                     }
                     break;
             }
         }
     }
     if (isset($results['updateTime']) && is_numeric($results['updateTime']) && $results['updateTime'] > $cache->getValue(0)) {
         cache::set('zwave::lastUpdate', $results['updateTime'], 0);
     }
 }
Example #7
0
 public function save()
 {
     if ($this->getLastLaunch() == '' && ($this->getMode() == 'schedule' || $this->getMode() == 'all')) {
         $calculateScheduleDate = $this->calculateScheduleDate();
         $this->setLastLaunch($calculateScheduleDate['prevDate']);
     }
     if ($this->getId() != '') {
         $this->emptyCacheWidget();
     }
     DB::save($this);
     if ($this->_changeState) {
         @nodejs::pushUpdate('eventScenario', $this->getId());
     }
 }
Example #8
0
             $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__)));
             $eqLogic->forceUpdate();
             break;
         }
     }
     if (!$deviceFound) {
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => __('Configuration du module non trouvé, faites une recherche sur le market, installez la et relancez la détection automatique', __FILE__)));
     } else {
         sleep(1);
         nodejs::pushUpdate('jeedom::alert', array('level' => 'warning', 'message' => ''));
     }
     ajax::success();
 }
 if (init('action') == 'getModuleInfo') {
     $eqLogic = zwave::byId(init('id'));
     if (!is_object($eqLogic)) {
         throw new Exception(__('Zwave eqLogic non trouvé : ', __FILE__) . init('id'));
     }
     ajax::success($eqLogic->getInfo());
 }
 if (init('action') == 'getDeviceConfiguration') {
     $eqLogic = zwave::byId(init('id'));
     if (!is_object($eqLogic)) {
         throw new Exception(__('Zwave eqLogic non trouvé : ', __FILE__) . init('id'));
     }
Example #9
0
 public function refreshWidget()
 {
     nodejs::pushUpdate('eventEqLogic', $this->getId());
 }
Example #10
0
 public function remove()
 {
     DB::remove($this);
     @nodejs::pushUpdate('message::refreshMessageNumber');
 }
Example #11
0
 /*         * ***************************INSTALLATION************************** */
 if (init('mode') != 'force') {
     echo "Jeedom va être installé. Voulez-vous continuer ? [o/N] ";
     if (trim(fgets(STDIN)) !== 'o') {
         echo "L'installation de Jeedom est annulée\n";
         echo "[END UPDATE SUCCESS]\n";
         exit(0);
     }
 }
 echo "\nInstallation de Jeedom " . jeedom::version() . "\n";
 $sql = file_get_contents(dirname(__FILE__) . '/install.sql');
 echo "Installation de la base de données...";
 DB::Prepare($sql, array(), DB::FETCH_TYPE_ROW);
 echo "OK\n";
 echo "Post installe...\n";
 nodejs::updateKey();
 config::save('api', config::genKey());
 require_once dirname(__FILE__) . '/consistency.php';
 echo "Ajout de l\\'utilisateur (admin,admin)\n";
 $user = new user();
 $user->setLogin('admin');
 $user->setPassword(sha1('admin'));
 $user->setRights('admin', 1);
 $user->save();
 $logLevel = array('info' => 0, 'debug' => 0, 'event' => 0, 'error' => 1);
 if (init('mode') != 'force') {
     echo "Jeedom est-il installé sur un Rasberry PI ? [o/N] ";
     if (trim(fgets(STDIN)) === 'o') {
         config::save('cronSleepTime', 60);
     }
 } else {
Example #12
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' => ''));
 }