예제 #1
0
 public function execute($_options = null)
 {
     switch ($this->getType()) {
         case 'info':
             if ($this->getConfiguration('virtualAction', 0) == '0') {
                 $calcul = cmd::cmdToValue($this->getConfiguration('calcul'));
                 $test = new evaluate();
                 $result = $test->Evaluer($calcul);
                 if ($this->getSubType() == 'binary') {
                     if ($result) {
                         return 1;
                     } else {
                         return 0;
                     }
                 }
                 if (is_numeric($result)) {
                     return number_format($result, 2);
                 } else {
                     return $result;
                 }
             } else {
                 return $this->getConfiguration('value');
             }
             break;
         case 'action':
             $virtualCmd = virtualCmd::byId($this->getConfiguration('infoId'));
             if (!is_object($virtualCmd)) {
                 throw new Exception('Virtual info commande non trouvé, verifier ID');
             }
             if ($virtualCmd->getEqLogic()->getEqType_name() != 'virtual') {
                 throw new Exception('La cible de la commande virtuel n\'est pas un équipement de type virtuel');
             }
             if ($this->getSubType() == 'slider') {
                 $value = $_options['slider'];
             } else {
                 if ($this->getSubType() == 'color') {
                     $value = $_options['color'];
                 } else {
                     $value = $this->getConfiguration('value');
                 }
             }
             $virtualCmd->setConfiguration('value', $value);
             $virtualCmd->save();
             $virtualCmd->event($value);
             break;
     }
 }
예제 #2
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;
     }
 }