1
0
moha/hooks/scripts/rdc_wc_eclairage.php
daniel Tartavel 0d35b1ff3f - lots of debugging
- beginning to add graphical stats
- beginning to add device by type
- added a dashboard "etage"
- begining to add notification to multiple recipients in freemobile hook
2022-03-28 00:40:34 +02:00

65 lines
1.9 KiB
PHP

<?php
class rdc_wc_eclairage extends hook
{
public $hookName = "rdc_wc_eclairage";
protected $devicelist = array(
RDC_SDB_WC_ECLAIRAGE => "state_l2",
RDC_WC_MVMT => "occupancy"
);
public $delay = 3; // amount of time in $timeunit
public $delayManual = 15; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices;
//var_dump($value);
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
switch($property)
{
case "state_l2":
logger(DEBUG, "CASE: state_l2", __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($device->method == AUTO)
{
setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true);
}else
{
$device->method = MANUAL;
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
}
}elseif ($value == "OFF")
{
removeEvent($device, "state_l2", "OFF");
$device->method = null;
}
break;
case "occupancy":
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
if ($value == true)
{
$device->method = AUTO;
$this->send("ON");
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
private function send($state)
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_SDB_WC_ECLAIRAGE];
$msg = array("state_l2" => $state);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set(null);
}
}
$hooks["rdc_wc_eclairage"] = new rdc_wc_eclairage();
?>