Skip to content

Commit

Permalink
Simple Devices update
Browse files Browse the repository at this point in the history
* Leak sensor alert message option
* Light sensor minimum value tracking
  • Loading branch information
sergejey committed Feb 4, 2022
1 parent e4bae99 commit b21689a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
26 changes: 16 additions & 10 deletions modules/devices/SLeak_alert.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<?php

$ot = $this->object_title;
$alert_timer_title = $ot.'_alert';
$alert_timer_title = $ot . '_alert';

$description = $this->description;
if (!$description) {
$description = $ot;
}
$message = $this->getProperty('notify_msg_reminder');

if ($message) {
say($message, 100);
} else {
$description = $this->description;
if (!$description) {
$description = $ot;
}
$location_title = processTitle($this->getProperty('location_title'));
if ($location_title) {
$description .= ' ' . LANG_LOCATED_IN_ROOM . ' ' . $location_title;
}

$location_title=processTitle($this->getProperty('location_title'));
if ($location_title) {
$description.=' '.LANG_LOCATED_IN_ROOM.' '.$location_title;
say(LANG_DEVICES_SENSOR_ALERT . ': ' . $description, 100);
}

say(LANG_DEVICES_SENSOR_ALERT.': '.$description,100);
clearTimeOut($alert_timer_title);
if ($this->getProperty('notify_eliminated')) {
setTimeOut($alert_timer_title,'cm("'.$ot.'.alert");',60);
setTimeOut($alert_timer_title, 'cm("' . $ot . '.alert");', 60);
}
2 changes: 2 additions & 0 deletions modules/devices/SLightSensors_periodMinValueUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php

16 changes: 16 additions & 0 deletions modules/devices/SLightSensors_valueUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$ot = $this->object_title;

$period = $this->getProperty('periodTime');
if (!$period) $period = 60 * 60;

$min_value = getHistoryMin($ot . '.value', (-1) * $period);
$value = (float)$this->getProperty('value');
if (is_null($min_value) || $value < $min_value) {
$min_value = $value;
}

if (!is_null($min_value)) {
$this->setProperty('periodMinValue', $min_value);
}
7 changes: 7 additions & 0 deletions modules/devices/devices_structure.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
'CLASS'=>'SLeak',
'PROPERTIES'=>array(
'notify_eliminated'=>array('DESCRIPTION'=>LANG_DEVICES_NOTIFY_ELIMINATED,'_CONFIG_TYPE'=>'yesno'),
'notify_msg_reminder'=>array('DESCRIPTION'=>LANG_DEVICES_MSG_REMINDER,'_CONFIG_TYPE'=>'text'),
'blocked'=>array('DESCRIPTION'=>'Is blocked'),
),
'METHODS'=>array(
Expand Down Expand Up @@ -484,7 +485,13 @@
'CLASS'=>'SLightSensors',
'PROPERTIES'=>array(
'unit'=>array('DESCRIPTION'=>LANG_DEVICES_UNIT,'_CONFIG_TYPE'=>'text'),
'periodMinValue'=>array('DESCRIPTION'=>'Minimum value for period','ONCHANGE'=>'periodMinValueUpdated','KEEP_HISTORY'=>365),
'periodTime'=>array('DESCRIPTION'=>'Period to calculate minimum value (seconds)','_CONFIG_TYPE'=>'num','_CONFIG_HELP'=>'SdSensorPeriodTime'),
),
'METHODS'=>array(
'valueUpdated'=>array('DESCRIPTION'=>'Value Updated'),
'periodMinValueUpdated'=>array('DESCRIPTION'=>'Period Min value updated'),
),
),
);

Expand Down
4 changes: 2 additions & 2 deletions templates/classes/views/SLightSensors.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="device-widget sensor %.alive|"offline;online"%" onclick="var url=('<#ROOTHTML#>pChart/?p=%.object_title%'+'.value&op=log&subop=24h');parent.$.fancybox.open({ src: url, type: 'iframe',iframe:{preload:false} });return false;">
<div class="device-widget sensor %.alive|"offline;online"%" onclick="var url=('<#ROOTHTML#>pChart/?p[]=%.object_title%'+'.value&p[]=%.object_title%'+'.periodMinValue&op=log&subop=24h');parent.$.fancybox.open({ src: url, type: 'iframe',iframe:{preload:false} });return false;">
<div class="device-icon light-sensor"></div>
<div class="device-header">%.value% %.unit%
<div class="device-header">%.value% %.unit% <sub>(min: %.periodMinValue% )</sub>
<span>%.direction|"-1=&#9660;1=&#9650;0=&#8801"%</span>
</div>
<div class="device-details">%.object_description%</div>
Expand Down

0 comments on commit b21689a

Please sign in to comment.