1
0

récupération après crash

This commit is contained in:
2022-12-05 12:23:43 +01:00
parent 559039b5e3
commit a27db71327
22 changed files with 300 additions and 147 deletions

View File

@ -7,34 +7,31 @@ class availability extends hook
// by default all devices are listening for availability
protected $devicelist = array();
function init()
{
global $indexDevices;
$this->iterate();
}
protected function iterate()
{
global $indexDevices;
foreach ($indexDevices as $ieeeAddress => $value)
{
$deviceList[] = array( $ieeeAddress => "availability");
if (!key_exists("availability", $value->properties))
{
$value->properties["availability"] = "";
}
}
$this->installHooksFunction($indexDevices);
}
function installHooks(&$indexDevices)
{
static $indexDevicesSize;
$tmp = count($indexDevices);
if ($tmp != $indexDevicesSize)
{
$this->iterate();
$indexDevicesSize = $tmp;
}
$this->installHooksFunction($indexDevices);
return false;
}
function installHook(&$device)
{
global $indexDevices;
$this->devicelist = array($device["device"]->ieeeAddress => "availability");
$this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 3 parameters
// $device -> calling device
// $property -> parameter passed by mqtt
@ -48,7 +45,7 @@ class availability extends hook
{
//echo "==========>>>>>> Availability $value" . EOL;
//if (!empty($device->availability))
//{[ Torrent911.com]
//{
$log = ALERT;
//}else
//{

View File

@ -9,7 +9,7 @@ class etage_temperature_int_ext extends hook
protected $devicelist = array(
METEO=> "tempc",
METEO => "tempc",
);
protected $portesList = array(

View File

@ -49,11 +49,6 @@ class radiateurs extends hook
// ETAGE_CHAMBRE_RADIATEUR => 0
);
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 3 parameters
public function callBack(&$device, $property, $value)
{
@ -61,6 +56,7 @@ class radiateurs extends hook
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
if ($this->active === true)
{
// test mois entre mai et octobre
$now = date("MM");
if ($now <= 5 or $now >= 11)
{
@ -98,17 +94,22 @@ class radiateurs extends hook
}
}
// state = true when a door or window is open
function send($device, $state)
{
global $indexDevices;
$flag = false;
if ($state === false)
$setTo = 0;
if ($state === true)
{
$t = getValue($device->ieeeAddress, "current_heating_setpoint");
if ($t != $this->minTemp)
{
$this->prevTemp[$device->ieeeAddress] = getValue($device->ieeeAddress, "current_heating_setpoint");
}
$setTo = $minTemp;
}else
{
$r = array_keys($this->hvac, $device->ieeeAddress);
@ -123,13 +124,18 @@ class radiateurs extends hook
}
if ($flag === false)
{
$msg = array("current_heating_setpoint" => (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19));
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg;
$device->set("current_heating_setpoint", AUTO);
$device->properties["current_heating_setpoint"]["method"] = AUTO;
$setTo = (!empty($this->prevTemp[$device->ieeeAddress])?$this->prevTemp[$device->ieeeAddress]:19);
}
}
if ($setTo <> 0)
{
$msg = array("current_heating_setpoint" => $setTo );
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $device->friendlyName), __FILE__ . ":" . __LINE__);
$device->payload = $msg;
$device->set("current_heating_setpoint", AUTO);
//$device->properties["current_heating_setpoint"]["method"] = AUTO;
}
}
}
$hooks["radiateurs"] = new radiateurs();

View File

@ -48,20 +48,22 @@ class rdc_salon_eclairage extends hook
$method = $deviceTarget->properties["state"]["method"];
logger(INFO, sprintf (_("CASE: %s => "), $param) . bool2string($value), __FILE__ . ":" . __LINE__);
//print_r(getValue(RDC_SALON_LUMINOSITE, "illuminance_lux"));
if ($value == ON and $method == IDLE)
if ($value == ON)
{
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
if ($method == IDLE)
{
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
logger(INFO, _("illuminance value : ") . $illuminance, __FILE__ . ":" . __LINE__);
if ($illuminance <= $this->luminance_min)
{
logger(INFO, _("setting to ON"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "ON", false, AUTO);
removeEvent($deviceTarget, "state", "OFF");
}
}
}else
}elseif ($method == AUTO)
{
logger(INFO, _("Value is OFF and method is ") . $method, __FILE__ . ":" . __LINE__);
if ((testActionneurs($this->actionneurs) == false) and ($method == AUTO))
//if ((getValue(RDC_SALON_MVMT, "occupancy") == OFF) and (getValue(RDC_SALON_MVMT2, "occupancy") == OFF) and $method == AUTO)
if (testActionneurs($this->actionneurs) == 0)
{
logger(INFO, _("Setting to OFF"), __FILE__ . ":" . __LINE__);
$this->send($deviceTarget, "OFF", false, IDLE);
@ -97,10 +99,13 @@ class rdc_salon_eclairage extends hook
case "state":
logger(INFO, _("CASE : State"), __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state"]["method"];
if($value == "ON" and $method == IDLE)
if($value == "ON")
{
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
if ($method == IDLE)
{
$deviceTarget->properties["state"]["method"] = MANUAL;
removeEvent($deviceTarget, "state", "OFF");
}
}else
{
$deviceTarget->properties["state"]["method"] = IDLE;

View File

@ -9,9 +9,9 @@ class rdc_sdb_eclairage extends hook
// public $active = true;
//public $initlialized = false;
public $delay = 3; // amount of time in $timeunit
public $delayManual = 20; // amount of time in $timeunit for manual mode
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
//public $delay = 3; // amount of time in $timeunit
public $delayManual = 2; // amount of time in $timeunit for manual mode
public $timeUnit = "hour"; // unit of time for delay, second, minute, day, week, month, year
// list of devices we are listening to
// devicelist[$ieeAddress][0] => property to watch
@ -45,42 +45,42 @@ class rdc_sdb_eclairage extends hook
$deviceTarget = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
logger(DEBUG, "Callback : " . $this->hookName, __FILE__ . ":" . __LINE__);
$method = $deviceTarget->properties["state_l1"]["method"];
logger(DEBUG, "Method is " . $method, __FILE__ . ":" . __LINE__);
switch($property)
{
case "occupancy":
logger(DEBUG, _("CASE: occupancy"), __FILE__ . ":" . __LINE__);
if ($value == ON)
if ($value === ON)
{
if($method == IDLE)
if($method === IDLE)
{
logger(DEBUG, _("lighting with method auto"), __FILE__ . ":" . __LINE__);
//$deviceTarget->properties["state_l1"]["method"] = AUTO;
$this->send("ON", AUTO);
removeEvent($deviceTarget, "state", "OFF");
//removeEvent($deviceTarget, "state", "OFF");
}
}elseif (!testActionneurs($this->actionneurs))
}elseif ((testActionneurs($this->actionneurs) == 0) and ($method == AUTO))
{
logger(DEBUG, _("Actionneurs are all false"), __FILE__ . ":" . __LINE__);
$this->send("OFF", IDLE);
removeEvent($deviceTarget, "state", "OFF");
//removeEvent($deviceTarget, "state", "OFF");
}
break;
case "state_l1":
logger(DEBUG, _("CASE: state_l1"), __FILE__ . ":" . __LINE__);
if ($value == "ON")
{
if ($method == IDLE)
if ($method === IDLE)
{
logger(DEBUG, _("State_l1 is IDLE"), __FILE__ . ":" . __LINE__);
removeEvent($deviceTarget, "state_l1", "OFF");
//removeEvent($deviceTarget, "state_l1", "OFF");
$deviceTarget->properties["state_l1"]["method"] = MANUAL;
//setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
setDelay($deviceTarget, $this->delayManual, $this->timeUnit, "state_l1", "OFF", true, IDLE);
}
}elseif ($value == "OFF" and $method == MANUAL)
}elseif ($value == "OFF")
{
$deviceTarget->properties["state_l1"]["method"] = IDLE;
removeEvent($deviceTarget, "state_l1", "OFF");
//$deviceTarget->properties["state_l1"]["method"] = IDLE;
logger(DEBUG, _("State_l1 is false light is off and method is ") . $method, __FILE__ . ":" . __LINE__);
}
break;
@ -93,17 +93,17 @@ class rdc_sdb_eclairage extends hook
}
}
private function send($state, $method)
public function send($state, $method)
{
global $indexDevices;
$device = &$indexDevices[RDC_SDB_WC_ECLAIRAGE];
$device->properties["state_l1"]["method"] = $method;
//$device->properties["state_l1"]["method"] = $method;
logger(DEBUG, "method = " . $device->properties["state_l1"]["method"], __FILE__ . ":" . __LINE__);
$msg = array("state_l1" => $state);
$device->payload = $msg;
$device->set("state_l1");
$device->set("state_l1", $method);
logger(INFO, sprintf(_("publishing message: %s to %s"), $state, $device->friendlyName), __FILE__ . ":" . __LINE__);
}
}
$hooks["rdc_sdb_eclairage"] = new rdc_sdb_eclairage();

View File

@ -251,7 +251,7 @@ class rdc_store extends hook
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];
$msg = array("position" => $level);
$msg = array("position" => 100 - $level);
logger(INFO, sprintf(_("publishing message: %s to %s"), json_encode($msg), $deviceObject->friendlyName), __FILE__ . ":" . __LINE__);
$deviceObject->payload = $msg;
$deviceObject->set("position", $method);

View File

@ -29,7 +29,7 @@ class rdc_temperature_int_ext extends hook
// callback fonction. Is called with these 4 parameters
public function callBack(&$device, $property, $value)
{
global $indexDevices, $hooks;
global $indexDevices, $scripts;
static $time;
$portes = array();
$status = -1;
@ -76,7 +76,7 @@ class rdc_temperature_int_ext extends hook
//print_r($portes);
if ($status == 1)
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, false);
$portes = $scripts["test_portes"]->testPortes($this->portesList, false, false);
if (empty($portes))
{
$time = now();
@ -88,7 +88,7 @@ class rdc_temperature_int_ext extends hook
}
}else
{
$portes = $hooks["test_portes"]->testPortes($this->portesList, false, true);
$portes = $scripts["test_portes"]->testPortes($this->portesList, false, true);
if (!empty($portes))
{
$time = now();

View File

@ -1,62 +0,0 @@
<?php
require_once "events.php";
class test_portes extends hook
{
public $hookName = "test_portes";
public $active = true;
protected $devicelist = array(
);
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
public function testPortes($deviceList=false, $send=true, $opened=true) :array
{
global $indexDevices;
$portes = array();
logger(DEBUG, _("Function testPorte"), __FILE__ . ":" . __LINE__);
if ($deviceList === false) $deviceList = $hooks["rdc_portes_ouvertes"]->devicelist;
$msg = "";
foreach ($deviceList as $device => $property)
{
//echo "device: " . $device . "\n";
//echo "opened = " . bool2string($opened);
//echo " value = " . var_dump($indexDevices[$device]->properties[$property]);
if ($opened)
{
if($indexDevices[$device]->properties[$property]["value"] === false)
{
//echo "porte opened";
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}else
{
if($indexDevices[$device]->properties[$property]["value"] === true)
{
//echo "porte closed";
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}
}
if ($send)
{
logger(ALERT, _("doors opened :") . $msg, null, $device);
}
return $portes;
}
}
$hooks["test_portes"] = new test_portes();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
$function = array($hooks["test_portes"], "testPortes");
//setRecurrentEvent("test_portes", $function, "", "", 0, -1, "", "", false, 21);
?>