66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
|
|
class etage_plan_travail_eclairage extends hook
|
|
{
|
|
public $hookName = "etage_plan_travail_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_CUISINE_PLAN_TRAVAIL_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 == "single")
|
|
{
|
|
if(getValue(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE, "state") == 'OFF')
|
|
{
|
|
$this->send("ON", "OFF");
|
|
}else
|
|
{
|
|
$this->send("OFF", false, null);
|
|
}
|
|
}
|
|
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_CUISINE_PLAN_TRAVAIL_SPOT];
|
|
$msg = array("state_l1" => $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_l1", $method);
|
|
//$device->properties["state_l1"]["method"] = $method;
|
|
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state_l1", $delayState, true, IDLE);
|
|
|
|
$device = & $indexDevices[ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE];
|
|
$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_plan_travail_eclairage"] = new etage_plan_travail_eclairage();
|
|
?>
|