Exemple #1
0
 public function batteryStatus($_pourcent, $_datetime = '')
 {
     if ($_pourcent > 20) {
         foreach (message::byPluginLogicalId($this->getEqType_name(), 'lowBattery' . $this->getId()) as $message) {
             $message->remove();
         }
         foreach (message::byPluginLogicalId($this->getEqType_name(), 'noBattery' . $this->getId()) as $message) {
             $message->remove();
         }
     } else {
         if ($_pourcent > 0 && $_pourcent <= 20) {
             $logicalId = 'lowBattery' . $this->getId();
             $message = 'Le module ' . $this->getEqType_name() . ' ';
             $message .= $this->getHumanName() . ' a moins de ' . $_pourcent . '% de batterie';
             if ($this->getConfiguration('battery_type') != '') {
                 $message .= ' (' . $this->getConfiguration('battery_type') . ')';
             }
             message::add($this->getEqType_name(), $message, '', $logicalId);
         } else {
             $logicalId = 'noBattery' . $this->getId();
             $message = __('Le module ', __FILE__) . $this->getEqType_name() . ' ';
             $message .= $this->getHumanName() . __(' n\'a plus de batterie (', __FILE__) . $_pourcent . ' %)';
             message::add($this->getEqType_name(), $message, '', $logicalId);
         }
     }
     $this->setConfiguration('batteryStatus', $_pourcent);
     if ($_datetime != '') {
         $this->setConfiguration('batteryStatusDatetime', $_datetime);
     } else {
         $this->setConfiguration('batteryStatusDatetime', date('Y-m-d H:i:s'));
     }
     $this->emptyCacheWidget();
     $this->save();
 }