63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
class etage_bureau_eclairage extends hook
|
|
{
|
|
public $hookName = "etage_bureau_eclairage";
|
|
public $active = true; //enable/disable hook (true => enabled)
|
|
public $delay = 1; // amount of time in $timeunit
|
|
public $timeUnit = "hour"; // unit of time for delay, second, minute, hour, day, week, month, year
|
|
protected $devicelist = array(ETAGE_BUREAU_ECLAIRAGE_INTER => "action");
|
|
|
|
// callback fonction. Is called with these 3 parameters
|
|
// $device -> calling device
|
|
// $property -> property of the device (given by mqtt)
|
|
// $value -> value of the property
|
|
public function callBack($device, $property, $value)
|
|
{
|
|
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
|
|
if($value == "on")
|
|
{
|
|
logger(DEBUG, "value: " . $value, __FILE__ . ":" . __LINE__);
|
|
//if(getValue(ETAGE_BUREAU_PANNEAU, "state") == 'OFF')
|
|
//{
|
|
logger(DEBUG, "Bureau panneau state: off", __FILE__ . ":" . __LINE__);
|
|
$this->send("ON", "OFF");
|
|
//}
|
|
}elseif ($value == "off")
|
|
{
|
|
//if(getValue(ETAGE_BUREAU_PANNEAU, "state") == 'ON')
|
|
//{
|
|
logger(DEBUG, "Bureau panneau state: on", __FILE__ . ":" . __LINE__);
|
|
$this->send("OFF", false);
|
|
//}
|
|
}
|
|
|
|
logger (INFO,sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value));
|
|
}
|
|
|
|
private function send($state, $delayState = false, $method = MANUAL)
|
|
{
|
|
global $devices, $indexDevices;
|
|
|
|
$device = & $indexDevices[ETAGE_BUREAU_PANNEAU];
|
|
$msg = array("state" => $state);
|
|
//if ($device->state_l1["value"] != $state)
|
|
//{
|
|
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName));
|
|
$device->payload = $msg;
|
|
$device->set("state", $method);
|
|
//$device->properties["state"]["method"] = $method;
|
|
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true, IDLE);
|
|
|
|
//}else
|
|
//{
|
|
// logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), //json_encode($msg), $device->friendlyName));
|
|
//}
|
|
//echo 'delaystate = ' . var_dump($delayState);
|
|
|
|
}
|
|
}
|
|
|
|
$hooks["etage_bureau_eclairage"] = new etage_bureau_eclairage();
|
|
?>
|