1
0

modified device database and the code for managing it

This commit is contained in:
2022-02-12 15:23:58 +01:00
parent 314305bcb1
commit 7d1dd25f2a
13 changed files with 156 additions and 113 deletions

View File

@ -41,7 +41,7 @@ class availability
// $log = INFO;
//}
//$device->availability = $value;
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, $value), __FILE__ . ":" . __LINE__);
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, bool2string($value)), __FILE__ . ":" . __LINE__);
}
break;
}

View File

@ -3,10 +3,10 @@
class etage_plan_travail_eclairage extends hook
{
public $hookName = "etage_plan_travail_eclairage";
public $active = true; //enable/disable hook (true => enabled)
public $active = false; //enable/disable hook (true => enabled)
public $delay = 3; // 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_ECLAIRAGE" => array("state", false));
protected $devicelist = array(ETAGE_CUISINE_PLAN_TRAVAIL_ECLAIRAGE => array("state", false));
// callback fonction. Is called with these 3 parameters
// $device -> calling device

View File

@ -30,7 +30,7 @@ class rdc_chambre_eclairage extends hook
{
$this->send(RDC_CHAMBRE_ECLAIRAGE, "ON", "OFF", AUTO);
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__);
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($device, $state, $delayState = false, $method = MANUAL)

View File

@ -1,4 +1,5 @@
<?php
class rdc_salon_eclairage extends hook
{
public $hookName = "rdc_salon_eclairage";
@ -14,14 +15,14 @@ class rdc_salon_eclairage extends hook
public $delay = 3; // amount of time in $timeunit
public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year
public $luminance_min = 60;
public $luminance_max = 3000;
public $luminance_max = 100;
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $param, $value)
{
global $devices, $indexDevices;
global $indexDevices;
logger(INFO, _("hook : rdc_salon_eclairage"), __FILE__ . ":" . __LINE__);
$device = &$indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
switch($param)
{
case "occupancy":
@ -31,14 +32,14 @@ class rdc_salon_eclairage extends hook
{
logger(DEBUG, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send("ON", null, AUTO);
removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
removeEvent($device, "state", "OFF");
}elseif ($value == OFF)
{
logger(DEBUG, _("Value is OFF"), __FILE__ . ":" . __LINE__);
if (getValue(RDC_SALON_MVMT, "occupancy") == OFF and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF))
{
logger(DEBUG, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
//$this->send("ON", "OFF", AUTO);
}
}
@ -64,7 +65,10 @@ class rdc_salon_eclairage extends hook
logger(DEBUG, _("illuminace is > to max"), __FILE__ . ":" . __LINE__);
//$this->send("OFF", null, AUTO);
//removeEvent($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], "state", "OFF");
setDelay($indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU], $this->delay, $this->timeUnit, "state", "OFF", true);
if (searchEvent($device, "state", "OFF") === false)
{
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
}
}elseif ($value <= $this->luminance_min and (getValue(RDC_SALON_MVMT, "occupancy") == ON OR getValue(RDC_SALON_MVMT2,"occupancy") == ON))
{
logger(DEBUG, _("illuminance < min and movement detected"), __FILE__ . ":" . __LINE__);
@ -77,7 +81,7 @@ class rdc_salon_eclairage extends hook
private function send($state, $delayState = false, $method = MANUAL)
{
global $devices, $indexDevices;
global $indexDevices;
$device = & $indexDevices[RDC_SALON_ECLAIRAGE_PANNEAU];
$msg = array("state" => $state);
if ($device->state["value"] != $state)
@ -89,7 +93,6 @@ class rdc_salon_eclairage extends hook
}else
{
logger(INFO, sprintf(_("not publishing message: %s to %s, already set"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
}
//echo 'delaystate = ' . var_dump($delayState);
if ($delayState !== false) setDelay($device, $this->delay, $this->timeUnit, "state", $delayState, true);

View File

@ -28,7 +28,7 @@ class rdc_wc_eclairage extends hook
}
break;
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value), __FILE__ . ":" . __LINE__);
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);
}
}