Skip to content

Commit 7c11054

Browse files
committed
Simple devices updates
* Motion sensor mini-template fix * Linked actions: ability to use min/max/average for period to control devices by sensors * Remove of new year decoration :)
1 parent 527b938 commit 7c11054

11 files changed

Lines changed: 277 additions & 179 deletions

File tree

3rdparty/duration-picker/html-duration-picker.min.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/devices.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
width:75px;
4545
}
4646

47+
.device-widget.mini.motion {
48+
min-width:75px;
49+
max-width:75px;
50+
width:75px;
51+
}
52+
4753
.device-widget.offline {
4854
background-color:#aaaaaa;
4955
}

languages/default.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,12 @@
12631263
'DEVICES_LINK_SET_COLOR_DESCRIPTION' => 'Change color when action triggered',
12641264
'DEVICES_LINK_SET_COLOR_PARAM_ACTION_COLOR' => 'Color',
12651265

1266+
'DEVICES_LINK_SENSOR_VALUE_TYPE' => 'Source value',
1267+
'DEVICES_LINK_SENSOR_VALUE_TYPE_CURRENT' => 'Current sensor value',
1268+
'DEVICES_LINK_SENSOR_VALUE_TYPE_MIN' => 'Minimum sensor value for period',
1269+
'DEVICES_LINK_SENSOR_VALUE_TYPE_AVG' => 'Average sensor value for period',
1270+
'DEVICES_LINK_SENSOR_VALUE_TYPE_MAX' => 'Maximum sensor value for period',
1271+
'DEVICES_LINK_SENSOR_VALUE_FOR_PERIOD' => 'For period',
12661272

12671273
'DEVICES_LINK_SENSOR_SWITCH' => 'Sensor control',
12681274
'DEVICES_LINK_SENSOR_SWITCH_DESCRIPTION' => 'Control another devices based on sensor\'s value',

languages/ru.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,13 @@
12591259
'DEVICES_LINK_SET_COLOR_DESCRIPTION' => 'Установить цвет по событию',
12601260
'DEVICES_LINK_SET_COLOR_PARAM_ACTION_COLOR' => 'Цвет',
12611261

1262+
'DEVICES_LINK_SENSOR_VALUE_TYPE' => 'Исходное значение',
1263+
'DEVICES_LINK_SENSOR_VALUE_TYPE_CURRENT' => 'Текущее значение сенсора',
1264+
'DEVICES_LINK_SENSOR_VALUE_TYPE_MIN' => 'Минимальное значение за период',
1265+
'DEVICES_LINK_SENSOR_VALUE_TYPE_AVG' => 'Среднее значение за период',
1266+
'DEVICES_LINK_SENSOR_VALUE_TYPE_MAX' => 'Максимальное значение за период',
1267+
'DEVICES_LINK_SENSOR_VALUE_FOR_PERIOD' => 'Использовать период',
1268+
12621269
'DEVICES_LINK_SENSOR_SWITCH' => 'Условное управление',
12631270
'DEVICES_LINK_SENSOR_SWITCH_DESCRIPTION' => 'Управление другим устройством по показаниям датчика',
12641271
'DEVICES_LINK_SENSOR_SWITCH_PARAM_CONDITION' => 'Тип условия',

modules/devices/devices_links.inc.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
foreach($link_details['PARAMS'] as &$p) {
2424
if (isset($settings[$p['PARAM_NAME']])) {
2525
$p['VALUE']=$settings[$p['PARAM_NAME']];
26+
if ($p['PARAM_TYPE']=='duration') {
27+
$p['VALUE'] = gmdate("H:i:s", $p['VALUE']);
28+
}
2629
}
2730
}
2831
}
@@ -46,8 +49,12 @@
4649
$config=array();
4750
$total = count($params);
4851
for ($i = 0; $i < $total; $i++) {
49-
global ${$params[$i]['PARAM_NAME'].'_value'};
50-
$config[$params[$i]['PARAM_NAME']]=${$params[$i]['PARAM_NAME'].'_value'};
52+
//global ${$params[$i]['PARAM_NAME'].'_value'};
53+
//$config[$params[$i]['PARAM_NAME']]=${$params[$i]['PARAM_NAME'].'_value'};
54+
$config[$params[$i]['PARAM_NAME']] = gr($params[$i]['PARAM_NAME'].'_value');
55+
if ($params[$i]['PARAM_TYPE']=='duration' && preg_match('/(\d+):(\d+):(\d+)/',$config[$params[$i]['PARAM_NAME']],$m)) {
56+
$config[$params[$i]['PARAM_NAME']] = $m[1]*60*60+$m[2]*60+$m[3];
57+
}
5158
}
5259
$link_rec['LINK_SETTINGS']=serialize($config);
5360
if ($ok) {

modules/devices/devices_links_actions.inc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,19 @@
318318
} elseif ($settings['action_type'] == 'close' && !gg($object . '.status')) {
319319
$action_string = 'callMethodSafe("' . $object . '.close' . '",array("link_source"=>"' . $device1['LINKED_OBJECT'] . '"));';
320320
}
321+
322+
if ($settings['source_value_type']!='') {
323+
$period = (int)$settings['source_value_time'];
324+
if ($period<1) $period=1;
325+
if ($settings['source_value_type'] == 'avg') {
326+
$value = getHistoryAvg($device1['LINKED_OBJECT'] . '.value',(-1)*$period);
327+
} elseif ($settings['source_value_type'] == 'min') {
328+
$value = getHistoryMin($device1['LINKED_OBJECT'] . '.value',(-1)*$period);
329+
} elseif ($settings['source_value_type'] == 'max') {
330+
$value = getHistoryMax($device1['LINKED_OBJECT'] . '.value',(-1)*$period);
331+
}
332+
}
333+
321334
if ($settings['condition_type'] == 'above' && $value >= (float)$settings['condition_value']) {
322335
//do the action
323336
} elseif ($settings['condition_type'] == 'below' && $value < (float)$settings['condition_value']) {

0 commit comments

Comments
 (0)