コード例 #1
0
ファイル: ifttt.class.php プロジェクト: jeedom/plugin-ifttt
 public function execute($_options = array())
 {
     $replace = array();
     switch ($this->getSubType()) {
         case 'slider':
             $replace['#slider#'] = $_options['slider'];
             break;
         case 'color':
             $replace['#color#'] = $_options['color'];
             break;
         case 'message':
             $replace['#title#'] = $_options['title'];
             $replace['#message#'] = $_options['message'];
             break;
     }
     $eqLogic = $this->getEqLogic();
     $url = 'https://maker.ifttt.com/trigger/' . $this->getConfiguration('event', 'jeedom') . '/with/key/' . $eqLogic->getConfiguration('key') . '?';
     if ($this->getConfiguration('value1') != '') {
         $url .= 'value1=' . urlencode(jeedom::evaluateExpression(str_replace(array_keys($replace), $replace, $this->getConfiguration('value1')))) . '&';
     }
     if ($this->getConfiguration('value2') != '') {
         $url .= 'value2=' . urlencode(jeedom::evaluateExpression(str_replace(array_keys($replace), $replace, $this->getConfiguration('value2')))) . '&';
     }
     if ($this->getConfiguration('value3') != '') {
         $url .= 'value3=' . urlencode(jeedom::evaluateExpression(str_replace(array_keys($replace), $replace, $this->getConfiguration('value3')))) . '&';
     }
     $url = trim($url, '&');
     $request_http = new com_http($url);
     $request_http->exec(5, 3);
 }
コード例 #2
0
ファイル: cmd.class.php プロジェクト: jimibi/core
 public function checkCmdAlert($_value)
 {
     if ($this->getConfiguration('jeedomCheckCmdOperator') == '' || $this->getConfiguration('jeedomCheckCmdTest') == '' || $this->getConfiguration('jeedomCheckCmdTime') == '' || is_nan($this->getConfiguration('jeedomCheckCmdTime'))) {
         return;
     }
     $check = jeedom::evaluateExpression($_value . $this->getConfiguration('jeedomCheckCmdOperator') . $this->getConfiguration('jeedomCheckCmdTest'));
     if ($check == 1 || $check || $check == '1') {
         if ($this->getConfiguration('jeedomCheckCmdTime') == 0) {
             $this->executeAlertCmdAction();
             return;
         }
         $cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
         if (!is_object($cron)) {
             $cron = new cron();
         }
         $cron->setClass('cmd');
         $cron->setFunction('cmdAlert');
         $cron->setOnce(1);
         $cron->setOption(array('cmd_id' => intval($this->getId())));
         $next = strtotime('+ ' . ($this->getConfiguration('jeedomCheckCmdTime') + 1) . ' minutes ' . date('Y-m-d H:i:s'));
         $schedule = date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next);
         $cron->setSchedule($schedule);
         $cron->setLastRun(date('Y-m-d H:i:s'));
         $cron->save();
     } else {
         $cron = cron::byClassAndFunction('cmd', 'cmdAlert', array('cmd_id' => intval($this->getId())));
         if (is_object($cron)) {
             $cron->remove();
         }
     }
 }
コード例 #3
0
ファイル: vmc.class.php プロジェクト: GaelGRIFFON/Plugin-VMC
 public function toHtml($_version = 'dashboard')
 {
     if ($this->getIsEnable() != 1) {
         return '';
     }
     if (!$this->hasRight('r')) {
         return '';
     }
     $_version = jeedom::versionAlias($_version);
     $background = $this->getBackgroundColor($_version);
     $replace = array('#name#' => $this->getName(), '#id#' => $this->getId(), '#background_color#' => $background, '#eqLink#' => $this->getLinkToConfiguration(), '#height#' => $this->getDisplay('height', 'auto'), '#width#' => $this->getDisplay('width', '200px'), '#temperature_airneufexterieur#' => jeedom::evaluateExpression($this->getConfiguration('temperature_airneufexterieur')), '#temperature_airneufinsuflé#' => jeedom::evaluateExpression($this->getConfiguration('temperature_airneufinsuflé')), '#temperature_airvicie#' => jeedom::evaluateExpression($this->getConfiguration('temperature_airvicie')), '#temperature_airvicierejete#' => jeedom::evaluateExpression($this->getConfiguration('temperature_airvicierejete')));
     $parameters = $this->getDisplay('parameters');
     if (is_array($parameters)) {
         foreach ($parameters as $key => $value) {
             $replace['#' . $key . '#'] = $value;
         }
     }
     $html = template_replace($replace, getTemplate('core', $_version, 'eqLogic', 'vmc'));
     return $html;
 }
コード例 #4
0
 public function execute(&$_scenario)
 {
     if ($this->getType() == 'if') {
         if ($this->getSubElement('if')->execute($_scenario)) {
             if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
                 if ($this->getSubElement('if')->getOptions('previousState', -1) != 1) {
                     $this->getSubElement('if')->setOptions('previousState', 1);
                     $this->getSubElement('if')->save();
                 } else {
                     $_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
                     return;
                 }
             }
             return $this->getSubElement('then')->execute($_scenario);
         }
         if (!is_object($this->getSubElement('else'))) {
             return;
         }
         if ($this->getSubElement('if')->getOptions('allowRepeatCondition', 0) == 1) {
             if ($this->getSubElement('if')->getOptions('previousState', -1) != 0) {
                 $this->getSubElement('if')->setOptions('previousState', 0);
                 $this->getSubElement('if')->save();
             } else {
                 $_scenario->setLog(__('Non exécution des actions pour cause de répétition', __FILE__));
                 return;
             }
         }
         return $this->getSubElement('else')->execute($_scenario);
     } else {
         if ($this->getType() == 'action') {
             return $this->getSubElement('action')->execute($_scenario);
         } else {
             if ($this->getType() == 'code') {
                 return $this->getSubElement('code')->execute($_scenario);
             } else {
                 if ($this->getType() == 'for') {
                     $for = $this->getSubElement('for');
                     $limits = $for->getExpression();
                     $limits = intval(jeedom::evaluateExpression($limits[0]->getExpression()));
                     if (!is_numeric($limits)) {
                         $_scenario->setLog(__('[ERREUR] La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
                         throw new Exception(__('La condition pour une boucle doit être numérique : ', __FILE__) . $limits);
                     }
                     $return = false;
                     for ($i = 1; $i <= $limits; $i++) {
                         $return = $this->getSubElement('do')->execute($_scenario);
                     }
                     return $return;
                 } else {
                     if ($this->getType() == 'in') {
                         $in = $this->getSubElement('in');
                         $in = $in->getExpression();
                         $time = ceil(str_replace('.', ',', jeedom::evaluateExpression($in[0]->getExpression())));
                         if (!is_numeric($time) || $time < 0) {
                             $time = 0;
                         }
                         if ($time == 0) {
                             $cmd = '/usr/bin/php ' . dirname(__FILE__) . '/../../core/php/jeeScenario.php ';
                             $cmd .= ' scenario_id=' . $_scenario->getId();
                             $cmd .= ' scenarioElement_id=' . $this->getId();
                             $cmd .= ' >> ' . log::getPathToLog('scenario_element_execution') . ' 2>&1 &';
                             exec($cmd);
                         } else {
                             $crons = cron::searchClassAndFunction('scenario', 'doIn', '"scenarioElement_id":' . $this->getId());
                             if (is_array($crons)) {
                                 foreach ($crons as $cron) {
                                     if ($cron->getState() != 'run') {
                                         $cron->remove();
                                     }
                                 }
                             }
                             $cron = new cron();
                             $cron->setClass('scenario');
                             $cron->setFunction('doIn');
                             $cron->setOption(array('scenario_id' => intval($_scenario->getId()), 'scenarioElement_id' => intval($this->getId()), 'second' => date('s')));
                             $cron->setLastRun(date('Y-m-d H:i:s'));
                             $cron->setOnce(1);
                             $next = strtotime('+ ' . $time . ' min');
                             $cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
                             $cron->save();
                             $_scenario->setLog(__('Tâche : ', __FILE__) . $this->getId() . __(' programmé à : ', __FILE__) . date('Y-m-d H:i:00', $next) . ' (+ ' . $time . ' min)');
                         }
                         return true;
                     } else {
                         if ($this->getType() == 'at') {
                             $at = $this->getSubElement('at');
                             $at = $at->getExpression();
                             $next = jeedom::evaluateExpression($at[0]->getExpression());
                             if ($next % 100 > 59) {
                                 if (strpos($at[0]->getExpression(), '-') !== false) {
                                     $next -= 40;
                                 } else {
                                     $next += 40;
                                 }
                             }
                             if (!is_numeric($next) || $next < 0) {
                                 $_scenario->setLog(__('Erreur dans bloc (type A) : ', __FILE__) . $this->getId() . __(', heure programmée invalide : ', __FILE__) . $next);
                             }
                             if ($next < date('Gi') + 1) {
                                 if (strlen($next) == 3) {
                                     $next = date('Y-m-d', strtotime('+1 day' . date('Y-m-d'))) . ' 0' . substr($next, 0, 1) . ':' . substr($next, 1, 3);
                                 } else {
                                     $next = date('Y-m-d', strtotime('+1 day' . date('Y-m-d'))) . ' ' . substr($next, 0, 2) . ':' . substr($next, 2, 4);
                                 }
                             } else {
                                 if (strlen($next) == 3) {
                                     $next = date('Y-m-d') . ' 0' . substr($next, 0, 1) . ':' . substr($next, 1, 3);
                                 } else {
                                     $next = date('Y-m-d') . ' ' . substr($next, 0, 2) . ':' . substr($next, 2, 4);
                                 }
                             }
                             $next = strtotime($next);
                             $crons = cron::searchClassAndFunction('scenario', 'doIn', '"scenarioElement_id":' . $this->getId());
                             if (is_array($crons)) {
                                 foreach ($crons as $cron) {
                                     if ($cron->getState() != 'run') {
                                         $cron->remove();
                                     }
                                 }
                             }
                             $cron = new cron();
                             $cron->setClass('scenario');
                             $cron->setFunction('doIn');
                             $cron->setOption(array('scenario_id' => intval($_scenario->getId()), 'scenarioElement_id' => intval($this->getId()), 'second' => 0));
                             $cron->setLastRun(date('Y-m-d H:i:s'));
                             $cron->setOnce(1);
                             $cron->setSchedule(date('i', $next) . ' ' . date('H', $next) . ' ' . date('d', $next) . ' ' . date('m', $next) . ' * ' . date('Y', $next));
                             $cron->save();
                             $_scenario->setLog(__('Tâche : ', __FILE__) . $this->getId() . __(' programmée à : ', __FILE__) . date('Y-m-d H:i:00', $next));
                             return true;
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
 public function execute($_options = null)
 {
     switch ($this->getType()) {
         case 'info':
             if ($this->getConfiguration('virtualAction', 0) == '0') {
                 try {
                     $result = jeedom::evaluateExpression($this->getConfiguration('calcul'));
                     if ($this->getSubType() == 'numeric') {
                         if (is_numeric($result)) {
                             $result = number_format($result, 2);
                         } else {
                             $result = str_replace('"', '', $result);
                         }
                         if (strpos($result, '.') !== false) {
                             $result = str_replace(',', '', $result);
                         } else {
                             $result = str_replace(',', '.', $result);
                         }
                     }
                     return $result;
                 } catch (Exception $e) {
                     log::add('virtual', 'info', $e->getMessage());
                     return jeedom::evaluateExpression(str_replace('"', '', cmd::cmdToValue($this->getConfiguration('calcul'))));
                 }
             }
             break;
         case 'action':
             $virtualCmd = virtualCmd::byId($this->getConfiguration('infoId'));
             if (!is_object($virtualCmd)) {
                 $cmds = explode('&&', $this->getConfiguration('infoName'));
                 if (is_array($cmds)) {
                     foreach ($cmds as $cmd_id) {
                         $cmd = cmd::byId(str_replace('#', '', $cmd_id));
                         $cmd->execCmd($_options);
                     }
                     return;
                 } else {
                     $cmd = cmd::byId(str_replace('#', '', $this->getConfiguration('infoName')));
                     return $cmd->execCmd($_options);
                 }
             } else {
                 if ($virtualCmd->getEqType() != 'virtual') {
                     throw new Exception(__('La cible de la commande virtuel n\'est pas un équipement de type virtuel', __FILE__));
                 }
                 if ($this->getSubType() == 'slider') {
                     $value = $_options['slider'];
                 } else {
                     if ($this->getSubType() == 'color') {
                         $value = $_options['color'];
                     } else {
                         $value = $this->getConfiguration('value');
                     }
                 }
                 $result = jeedom::evaluateExpression($value);
                 if ($this->getSubtype() == 'message') {
                     $result = $_options['title'] . ' ' . $_options['message'];
                 }
                 $virtualCmd->event($result);
             }
             break;
     }
 }
コード例 #6
0
ファイル: arduidom.class.php プロジェクト: bobox59/arduidom
 public function execute($_options = null)
 {
     //file_put_contents("/tmp/arduidom2", time() . " :  arduidom_execute" . "\n", FILE_APPEND);
     //$results = print_r($_options, true);
     //log::add('arduidom', 'debug', 'execute(' . $results . ') called');
     //exec('echo "execute 2" >> /tmp/arduidom');
     if ($this->getType() == 'action') {
         try {
             //exec('echo "execute 3" >> /tmp/arduidom');
             //log::add('arduidom', 'debug', 'execute() called on type action');
             //exec('echo "execute 4" >> /tmp/arduidom');
             //log::add('arduidom','info','subTYPE=' . $this->getSubType());
             $subType = $this->getSubType();
             if ($subType == 'slider') {
                 $value = str_replace('#slider#', $_options['slider'], $this->getConfiguration('value'));
                 return arduidom::setPinValue($this->getLogicalId(), $value);
             }
             if ($subType == 'color') {
                 $value = str_replace('#color#', $_options['color'], $this->getConfiguration('value'));
                 return arduidom::setPinValue($this->getLogicalId(), $value);
             }
             if ($subType == 'other') {
                 //GROS LAG RETIRE ICI - VERIFIER QUE CA N'A PAS D'INCIDENCE SUR LES FORMULES EN VALEURS//
                 $value = $this->getConfiguration('value');
                 if ($value != 0 || $value != 1 || $value != "0" || $value != "1") {
                     $value = jeedom::evaluateExpression($value);
                 }
                 return arduidom::setPinValue($this->getLogicalId(), $value);
             }
         } catch (Exception $e) {
             //exec('echo "execute 5" >> /tmp/arduidom');
             //log::add('arduidom', 'debug', 'execute() ' . $e);
             return "bad";
         }
     }
     /*if ($this->getType() == 'info') {
           try{
               //exec('echo "execute 6" >> /tmp/arduidom');
               //log::add('arduidom', 'debug', 'execute() called on type info');
               return arduidom::getPinValue($this->getLogicalId());
           } catch (Exception $e) {
               //exec('echo "execute 7" >> /tmp/arduidom');
               //log::add('arduidom', 'debug', 'execute() ' . $e);
               return "bad";
           }
       }*/
     /*
     
     throw new Exception(__("Erreur: XXXXXXXXXXXXXXXXX", __FILE__));
     log::add('arduidom', 'debug', 'foreach.....................');
     foreach (eqLogic::byType('arduidom') as $eqLogic){
         log::add('arduidom', 'debug', 'by type arduidom');
         foreach ($eqLogic->getCmd('info') as $cmd) {
             log::add('arduidom', 'debug', 'getCmd info');
             if (array_key_exists($cmd->getConfiguration('value'), $_GET)) {
                 log::add('arduidom', 'debug', 'with value');
                 log::add('arduidom', 'debug', 'Mise à jour de : ' . $cmd->getConfiguration('value') . ':'. $_GET[$cmd->getConfiguration('value')]);
                 $cmd->setValue($_GET[$cmd->getConfiguration('value')]);
                 $cmd->event($_GET[$cmd->getConfiguration('value')]);
                 $cmd->save();
             }
         }
         log::add('arduidom', 'event', 'Mise à jour de ' . $eqLogic->getHumanName() . ' terminée');
     }
     */
     return "BAD";
 }