availibility is now property of device object
This commit is contained in:
parent
260d220326
commit
91c3a3a5d4
@ -91,43 +91,19 @@ function searchPropertyValue($fn, &$device, $object, $listProperties)
|
||||
}
|
||||
}
|
||||
|
||||
function changeDevice($topic, $fn, &$device, $json)
|
||||
function changeDevice($topic, $fn, &$device, $payloadArray)
|
||||
{
|
||||
//print_r($device);
|
||||
/*foreach($fnTree as $fn)
|
||||
{
|
||||
//print_r($device);
|
||||
if (!isset($device[$fn]))
|
||||
{
|
||||
|
||||
}
|
||||
$device = & $device[$fn];
|
||||
}*/
|
||||
|
||||
//print_r($json);
|
||||
$fnTree = explode("/", $fn);
|
||||
//print_r($json);
|
||||
if ( ($jsonDevice = json_decode($json)) === null )
|
||||
{
|
||||
//echo "json ========>>>>>>> " . print_r($json,true) . EOL;
|
||||
if (!isset($device->value))
|
||||
{
|
||||
$device->{"value"} = $json;
|
||||
$device->type = true; //set this as parameter and not device
|
||||
}
|
||||
//print_r($device);
|
||||
}else
|
||||
{
|
||||
iterateDevice($topic, $fn, $device, $jsonDevice);
|
||||
}
|
||||
//$fnTree = explode("/", $fn);
|
||||
//print_r($payloadArray);
|
||||
iterateDevice($topic, $fn, $device, $payloadArray);
|
||||
}
|
||||
|
||||
function iterateDevice($topic, $fn, &$device, $json)
|
||||
function iterateDevice($topic, $fn, &$device, $payloadArray)
|
||||
{
|
||||
global $changed;
|
||||
|
||||
print_r($payloadArray);
|
||||
//echo "device =>";print_r($device);echo EOL;
|
||||
foreach($json as $key => $value)
|
||||
foreach($payloadArray as $key => $value)
|
||||
{
|
||||
$oldValue = 0;
|
||||
//echo "key =>"; print_r($key); echo EOL;
|
||||
|
26
events.php
26
events.php
@ -6,18 +6,14 @@
|
||||
function checkEvents()
|
||||
{
|
||||
global $events, $indexDevices, $devices;
|
||||
//echo "===========> checking events" . EOL;
|
||||
$exception = false;
|
||||
foreach ($events as $key => $event)
|
||||
{
|
||||
if (!empty($event->startDatetime))
|
||||
{
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
if($event->dateTimeEvent <= now())
|
||||
{
|
||||
logger(LOG_ERROR, "Error in event recurrence. event: " . $key);
|
||||
|
||||
}elseif($event->dateTimeEvent <= now())
|
||||
{
|
||||
if (!empty($event->exceptionInterval))
|
||||
{
|
||||
foreach($event->exceptionInterval as $key => $value)
|
||||
@ -35,13 +31,17 @@ function checkEvents()
|
||||
{
|
||||
echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
|
||||
publish($event->device, array($event->param => $event->value), "set", $key);
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(LOG_ERROR, __("Error in event recurrence. event: ") . $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now())
|
||||
{
|
||||
echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
|
||||
publish($event->device, array($event->param => $event->value), "set", $key);
|
||||
//$event->published = now();
|
||||
$mid = publish($event->device, array($event->param => $event->value), "set", $key);
|
||||
$event->published = now();
|
||||
//echo "#################################\nUnsetting event $key \n###########################" . EOL;
|
||||
unset($events[$key]);
|
||||
}
|
||||
@ -86,6 +86,11 @@ function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDateti
|
||||
$event->param = $param;
|
||||
$event->value = $value;
|
||||
$event->dateTimeEvent = $event->startDatetime;
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(LOG_ERROR, __("Error in event recurrence. event: ") . $key);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=false)
|
||||
@ -143,15 +148,10 @@ function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=fal
|
||||
echo "new event";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function searchEvent($device, $param , $value)
|
||||
{
|
||||
global $events;
|
||||
echo "searching event" . EOL;
|
||||
//$keys = array_keys($events, $device->ieeeAddress);
|
||||
//echo "ieee_address =>" . $device->ieeeAddress . EOL;
|
||||
//print_r($events);
|
||||
foreach($events as $key => $event)
|
||||
{
|
||||
//echo "Event : $event => $value" . EOL;
|
||||
@ -169,7 +169,7 @@ function deleteEvent($eventKey)
|
||||
{
|
||||
global $events;
|
||||
unset ($events[$eventKey]);
|
||||
//echo "delete event " . $eventKey . EOL;
|
||||
logger(LOG_INFO, __("delete event ") . $eventKey);
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,14 +5,18 @@ class rdc_panneau_salon
|
||||
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
public $luminance_min = 80;
|
||||
public $luminance_max = 3000;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
global $indexDevices;
|
||||
|
||||
// assigne the function to the sensors devices
|
||||
foreach ($this->devicelist as $ieeeAddress)
|
||||
{
|
||||
$indexDevices[$ieeeAddress]->functions[] = array($this,"callback");
|
||||
//print_r($indexDevices[$ieeeAddress]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +32,8 @@ class rdc_panneau_salon
|
||||
case "contact":
|
||||
if ($value == false) $this->send();
|
||||
break;
|
||||
case "illuminance_lux":
|
||||
if ($value >= $this->luminance_max) $this->send();
|
||||
}
|
||||
echo _("notification received from MQTT") . EOL;
|
||||
//echo $param . "=> " . $value . EOL;
|
||||
@ -36,10 +42,11 @@ class rdc_panneau_salon
|
||||
private function send()
|
||||
{
|
||||
global $devices, $indexDevices;
|
||||
if ($indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= 76)
|
||||
if ($indexDevices["0x04cf8cdf3c78aff0"]->illuminance_lux <= $this->luminance_min)
|
||||
{
|
||||
$msg = array("state" => "ON");
|
||||
$device = & $indexDevices["0x588e81fffe343e8f"];
|
||||
logger(LOG_INFO, __("publishing ") . $msg . __(" message: ") . $device->friendlyName);
|
||||
$device->payload = $msg;
|
||||
$device->set(null);
|
||||
setDelay($device, $this->delay, $this->timeUnit, "state", "OFF", true);
|
||||
@ -48,9 +55,4 @@ class rdc_panneau_salon
|
||||
}
|
||||
|
||||
$hooks["rdc/panneau/salon"] = new rdc_panneau_salon();
|
||||
//assignation of the function to the sensors devices
|
||||
//$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2
|
||||
//$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt
|
||||
//$indexDevices["0x00124b001f900753"]->functions[] = array($panneau_salon,"getCallback"); // rdc-porte-entree
|
||||
//$indexDevices["0x04cf8cdf3c78aff0"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-luminosite
|
||||
?>
|
||||
|
6
moha.php
6
moha.php
@ -42,11 +42,11 @@ class device
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
public $type; // if true then not a device but parameter of device(eg. topic/FRIENDLYNAME/PARAMETER
|
||||
public $powerSource;
|
||||
public $description;
|
||||
public $functions;
|
||||
public $payload;
|
||||
public $availibility;
|
||||
|
||||
public function set($event)
|
||||
{
|
||||
@ -198,10 +198,6 @@ while (true)
|
||||
}elseif($dbInit == 2 and $included)
|
||||
{
|
||||
checkEvents();
|
||||
if (empty($flag))
|
||||
{
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,20 @@ function message($message)
|
||||
};
|
||||
}elseif (($topic[array_key_last($topic)]) != "get" and ($topic[array_key_last($topic)]) != "set")
|
||||
{
|
||||
|
||||
$topic = explode ("/", $message->topic, 2); // get topic name
|
||||
$fnTree = explode ("/" , $topic[1]); // get friendlyname
|
||||
echo $topic[0] . " => " . $topic[1] . EOL;
|
||||
//$devices[$topic[0]][$fnTree[0]]->json = json_decode($message->payload);
|
||||
if ($fnTree[array_key_last($fnTree)] == "availability")
|
||||
{
|
||||
unset ($fnTree[array_key_last($fnTree)]);
|
||||
$payloadArray = array("availability" => $message->payload);
|
||||
print_r($payloadArray);
|
||||
}else
|
||||
{
|
||||
$payloadArray = json_decode($message->payload);
|
||||
}
|
||||
$device = & $devices[$topic[0]];
|
||||
foreach($fnTree as $fn)
|
||||
{
|
||||
@ -53,7 +63,7 @@ function message($message)
|
||||
}
|
||||
$device = & $device[$fn];
|
||||
}
|
||||
changeDevice($topic[0], $topic[1], $device["device"], $message->payload);
|
||||
changeDevice($topic[0], $topic[1], $device["device"], $payloadArray);
|
||||
//fwrite($logFh, print_r($msg, true));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user