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 setData($_key, $_value, $_private = false) { $dataStore = new dataStore(); $dataStore->setType('scenario'); $dataStore->setKey($_key); $dataStore->setValue($_value); if ($_private) { $dataStore->setLink_id($this->getId()); } else { $dataStore->setLink_id(-1); } $dataStore->save(); return true; }
throw new Exception(__('401 - Accès non autorisé', __FILE__)); } if (init('action') == 'remove') { $dataStore = dataStore::byId(init('id')); if (!is_object($dataStore)) { throw new Exception(__('Data store inconnu vérifer l\'id : ', __FILE__) . init('id')); } $dataStore->remove(); ajax::success(); } if (init('action') == 'save') { if (init('id') == '') { $dataStore = new dataStore(); $dataStore->setKey(init('key')); $dataStore->setLink_id(init('link_id')); $dataStore->setType(init('type')); } else { $dataStore = dataStore::byId(init('id')); } if (!is_object($dataStore)) { throw new Exception(__('Data store inconnu vérifer l\'id : ', __FILE__) . init('id')); } $dataStore->setValue(init('value')); $dataStore->save(); ajax::success(); } if (init('action') == 'all') { $datastores = utils::o2a(dataStore::byTypeLinkId(init('type'))); if (init('usedBy') == 1) { foreach ($datastores as &$datastore) { $datastore['usedBy'] = array('scenario' => array());
if ($cmd->getType() == 'info') { $cmd_return['state'] = $cmd->execCmd(); } $eqLogic_return['cmds'][] = $cmd_return; } $return['eqLogics'][] = $eqLogic_return; } $jsonrpc->makeSuccess($return); } /* * ************************datastore*************************** */ if ($jsonrpc->getMethod() == 'datastore::byTypeLinkIdKey') { $jsonrpc->makeSuccess(dataStore::byTypeLinkIdKey($params['type'], $params['linkId'], $params['key'])); } if ($jsonrpc->getMethod() == 'datastore::save') { $dataStore = new dataStore(); $dataStore->setType($params['type']); $dataStore->setKey($params['key']); $dataStore->setValue($params['value']); $dataStore->setLink_id($params['linkId']); $dataStore->save(); $jsonrpc->makeSuccess('ok'); } /* * ************************Equipement*************************** */ if ($jsonrpc->getMethod() == 'eqLogic::all') { $jsonrpc->makeSuccess(utils::o2a(eqLogic::all())); } if ($jsonrpc->getMethod() == 'eqLogic::byType') { $jsonrpc->makeSuccess(utils::o2a(eqLogic::byType($params['type']))); } if ($jsonrpc->getMethod() == 'eqLogic::byObjectId') { $jsonrpc->makeSuccess(utils::o2a(eqLogic::byObjectId($params['object_id'])));