1
0

hooks are now in array

This commit is contained in:
daniel Tartavel 2022-01-01 06:26:02 +01:00
parent f2f8e27c89
commit 4e9aa8aeb5
3 changed files with 16 additions and 14 deletions

View File

@ -8,7 +8,7 @@ function checkEvents()
{ {
if (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now()) if (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now())
{ {
echo "---->sending command" . EOL; echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
publish($event->device, array($event->param => $event->value), "set", $key); publish($event->device, array($event->param => $event->value), "set", $key);
//$event->published = now(); //$event->published = now();
//echo "#################################\nUnsetting event $key \n###########################" . EOL; //echo "#################################\nUnsetting event $key \n###########################" . EOL;
@ -25,10 +25,10 @@ function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false)
//print_r($datetime); //print_r($datetime);
switch($unit) switch($unit)
{ {
case "sec": case "second":
$unit = "S"; $unit = "S";
break; break;
case "min": case "minute":
$unit = "M"; $unit = "M";
break; break;
case "hour": case "hour":
@ -68,7 +68,7 @@ function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false)
function searchEvent($device, $param , $value): int function searchEvent($device, $param , $value)
{ {
global $events; global $events;
echo "searching event" . EOL; echo "searching event" . EOL;
@ -85,6 +85,7 @@ function searchEvent($device, $param , $value): int
return $key; return $key;
} }
} }
return false;
} }
function deleteEvent($eventKey) function deleteEvent($eventKey)

View File

@ -1,9 +1,10 @@
<?php <?php
class panneau_salon class rdc_panneau_salon
{ {
// list of devices we are listening to
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0"); private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
public $delay = 3; public $delay = 3; // amount of time in $timeunit
public $timeUnit = "min"; public $timeUnit = "minutes"; // unit of time for delay, second, minute, day, week, month, year
function __construct() function __construct()
{ {
@ -13,13 +14,12 @@ class panneau_salon
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback"); $indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
//print_r($indexDevices[$ieeeAddress]); //print_r($indexDevices[$ieeeAddress]);
} }
} }
// callback fonction. Is called with these 4 parameters
public function callBack($topic, $fn, $param, $value) public function callBack($topic, $fn, $param, $value)
{ {
global $devices, $indexDevices; global $devices, $indexDevices;
switch($param) switch($param)
{ {
case "occupancy": case "occupancy":
@ -47,7 +47,7 @@ class panneau_salon
} }
} }
$panneau_salon = new panneau_salon(); $hooks["rdc/panneau/salon"] = new rdc_panneau_salon();
//assignation of the function to the sensors devices //assignation of the function to the sensors devices
//$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2 //$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2
//$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt //$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt

View File

@ -126,16 +126,17 @@ class notificationMethod
//global variables //global variables
$topics = array(); // list of topics $topics = array(); // list of topics
$mids = array(); // list of message IDs $mids = array(); // list of message IDs
$logFh = null; // filehandle of log file
$devices = array(); // array of device objetcs $devices = array(); // array of device objetcs
$changed = array(); // list of changed devices
$notificationMethods = array(); // array of notification methods objects
$indexDevices = array(); // index devices by ieee_address $indexDevices = array(); // index devices by ieee_address
$hooks = array(); // array of hooks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
$changed = array(); // list of changed devices
$dbInit = false; // flag to indicate that desvices db is initialized $dbInit = false; // flag to indicate that desvices db is initialized
$connected = false; // connected to MQTT server $connected = false; // connected to MQTT server
$nSubscribed = 0; // Number of topics subsribed $nSubscribed = 0; // Number of topics subsribed
$included = false; // flag indicate scripts are loaded $included = false; // flag indicate scripts are loaded
$events = array(); // list of event objects $logFh = null; // filehandle of log file
// topics definition // topics definition
$topics["zigbee2mqtt"] = new topic; $topics["zigbee2mqtt"] = new topic;