Skip to content
Permalink
Browse files

Simple Devices update

* Simple Devices: "system device" option
  • Loading branch information...
sergejey committed May 2, 2019
1 parent e1e9ceb commit 99bd5a7f0062ff83c28f05d74f6f387898d3d0d3
@@ -1301,6 +1301,7 @@
'AUTO_LINK' => 'Execute script automatically',
'FAVORITE_DEVICE' => 'Favorite device',
'SYSTEM_DEVICE' => 'System device',
'ROOMS' => 'Rooms',
'APPEARANCE' => 'Appearance',
@@ -1295,6 +1295,7 @@
'AUTO_LINK' => 'Автоматический запуск сценария',
'FAVORITE_DEVICE' => 'В списке быстрого доступа',
'SYSTEM_DEVICE' => 'Системное устройство',
'ROOMS' => 'Комнаты',
'APPEARANCE' => 'Внешний вид',
@@ -477,7 +477,7 @@ function sendAllDevices()
// POST TO SERVER
$url = 'https://connect.smartliving.ru/sync_device_data.php';
$fields = array();
$devices = SQLSelect("SELECT ID, TITLE, ALT_TITLES, TYPE, SUBTYPE, LINKED_OBJECT FROM devices WHERE 1");
$devices = SQLSelect("SELECT devices.ID, devices.TITLE, devices.ALT_TITLES, devices.TYPE, devices.SUBTYPE, devices.LINKED_OBJECT, locations.TITLE as ROOM_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE devices.SYSTEM_DEVICE=0");
include_once(DIR_MODULES . 'classes/classes.class.php');
$cl = new classes();
@@ -496,6 +496,9 @@ function sendAllDevices()
$value = $object->getProperty($v['TITLE']);
if ($value === '') continue;
$device['properties'][$v['TITLE']] = $value;
if (strtolower($v['TITLE'])=='linkedroom') {
$device['ROOM_OBJECT']=$value;
}
}
}
}
@@ -532,7 +535,8 @@ function sendDeviceProperty($property, $value)
$url = 'https://connect.smartliving.ru/sync_device_data.php';
$fields = array();
list($object_name, $property_name) = explode('.', $property);
$device_rec = SQLSelectOne("SELECT ID, TITLE, TYPE, SUBTYPE FROM devices WHERE LINKED_OBJECT='" . DBSafe($object_name) . "'");
$device_rec = SQLSelectOne("SELECT ID, TITLE, TYPE, SUBTYPE FROM devices WHERE LINKED_OBJECT='" . DBSafe($object_name) . "' AND SYSTEM_DEVICE=0");
if (!$device_rec['ID']) return;
$fields['object'] = $object_name;
$fields['property'] = $property_name;
$fields['value'] = $value;
@@ -652,7 +652,7 @@ function usual(&$out)
$devices=SQLSelect("SELECT ID, LINKED_OBJECT FROM devices WHERE FAVORITE!=1");
}
*/
$devices = SQLSelect("SELECT ID, LINKED_OBJECT FROM devices WHERE 1");
$devices = SQLSelect("SELECT ID, LINKED_OBJECT FROM devices WHERE SYSTEM_DEVICE=0");
$total = count($devices);
for ($i = 0; $i < $total; $i++) {
if ($devices[$i]['LINKED_OBJECT']) {
@@ -674,7 +674,7 @@ function usual(&$out)
global $type;
if ($location_id || $type) {
$qry = "1";
$qry = "1 AND SYSTEM_DEVICE=0";
$orderby = 'locations.PRIORITY DESC, LOCATION_ID, TYPE, TITLE';
if (preg_match('/loc(\d+)/', $type, $m)) {
$location_id = $m[1];
@@ -728,7 +728,7 @@ function usual(&$out)
} else {
$orderby = 'locations.PRIORITY DESC, LOCATION_ID, TYPE, TITLE';
//$qry=" devices.FAVORITE=1";
$qry = "1";
$qry = "1 AND SYSTEM_DEVICE=0";
$out['ALL_DEVICES']=1;
$devices = SQLSelect("SELECT devices.*, locations.TITLE as LOCATION_TITLE FROM devices LEFT JOIN locations ON devices.LOCATION_ID=locations.ID WHERE $qry ORDER BY $orderby");
$recent_devices=SQLSelect("SELECT devices.* FROM devices WHERE !IsNull(CLICKED) ORDER BY CLICKED DESC LIMIT 10");
@@ -849,7 +849,7 @@ function usual(&$out)
foreach ($this->device_types as $k => $v) {
if ($v['TITLE']) {
$type_rec = array('NAME' => $k, 'TITLE' => $v['TITLE']);
$tmp = SQLSelectOne("SELECT COUNT(*) AS TOTAL FROM devices WHERE TYPE='" . $k . "'");
$tmp = SQLSelectOne("SELECT COUNT(*) AS TOTAL FROM devices WHERE SYSTEM_DEVICE=0 AND TYPE='" . $k . "'");
$type_rec['TOTAL'] = (int)$tmp['TOTAL'];
if ($type_rec['TOTAL'] > 0) {
$types[] = $type_rec;
@@ -1366,6 +1366,7 @@ function dbInstall($data = '')
devices: LINKED_OBJECT varchar(100) NOT NULL DEFAULT ''
devices: LOCATION_ID int(10) unsigned NOT NULL DEFAULT 0
devices: FAVORITE int(3) unsigned NOT NULL DEFAULT 0
devices: SYSTEM_DEVICE int(3) unsigned NOT NULL DEFAULT 0
devices: CLICKED datetime DEFAULT NULL
devices: SYSTEM varchar(255) NOT NULL DEFAULT ''
@@ -8,10 +8,10 @@
$table_name = 'devices';
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE ID='$id'");
if (!$id && gr('linked_object')) {
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE LINKED_OBJECT='".DBSafe(gr('linked_object'))."'");
$rec = SQLSelectOne("SELECT * FROM $table_name WHERE LINKED_OBJECT='" . DBSafe(gr('linked_object')) . "'");
}
if ($this->owner->print==1) {
$out['NO_NAV']=1;
if ($this->owner->print == 1) {
$out['NO_NAV'] = 1;
}
$show_methods = array();
@@ -229,8 +229,8 @@
if ($this->tab == '') {
for($i=1;$i<100;$i++) {
$out['PRIORITIES'][]=array('VALUE'=>$i);
for ($i = 1; $i < 100; $i++) {
$out['PRIORITIES'][] = array('VALUE' => $i);
}
global $prefix;
@@ -285,7 +285,7 @@
if ($this->mode == 'update' && $this->tab == '') {
$ok = 1;
$rec['TITLE'] = gr('title','trim');
$rec['TITLE'] = gr('title', 'trim');
if ($rec['TITLE'] == '') {
$out['ERR_TITLE'] = 1;
$ok = 0;
@@ -302,12 +302,14 @@
global $location_id;
$rec['LOCATION_ID'] = (int)$location_id;
if (gr('favorite','int')) {
$rec['FAVORITE'] = gr('favorite_priority','int');
if (gr('favorite', 'int')) {
$rec['FAVORITE'] = gr('favorite_priority', 'int');
} else {
$rec['FAVORITE'] = 0;
}
$rec['SYSTEM_DEVICE'] = gr('system_device', 'int');
$rec['LINKED_OBJECT'] = $linked_object;
if ($rec['LINKED_OBJECT'] && !$rec['ID']) {
@@ -347,7 +349,7 @@
$type_details = $this->getTypeDetails($rec['TYPE']);
if (!$rec['LINKED_OBJECT'] && $out['ADD_OBJECT']) {
$prefix = $out['PREFIX'] . ucfirst($rec['TYPE']);
$new_object_title = $prefix . $this->getNewObjectIndex($type_details['CLASS'],$prefix);
$new_object_title = $prefix . $this->getNewObjectIndex($type_details['CLASS'], $prefix);
$object_id = addClassObject($type_details['CLASS'], $new_object_title, 'sdevice' . $rec['ID']);
$rec['LINKED_OBJECT'] = $new_object_title;
SQLUpdate('devices', $rec);
@@ -20,6 +20,8 @@
$payload['name']=$devices[$i]['LINKED_OBJECT'];
sg('HomeBridge.to_remove',json_encode($payload));
if ($devices[$i]['SYSTEM_DEVICE']) continue;
$payload['service_name']=processTitle($devices[$i]['TITLE']);
switch($devices[$i]['TYPE']) {
@@ -105,6 +105,15 @@
</div>
</div>

<div class="form-group ">
<label class="col-lg-4 control-label"><#LANG_SYSTEM_DEVICE#>: <#LANG_HCB#>system_device<#LANG_HCE#></label>
<div class="col-lg-4">
<input type="radio" name="system_device" value="1"[#if SYSTEM_DEVICE!="0"#] checked[#endif#]> <#LANG_YES#>
<input type="radio" name="system_device" value="0"[#if (SYSTEM_DEVICE=="0") || (SYSTEM_DEVICE=="")#] checked[#endif#]> <#LANG_NO#>
</span>
</div>
</div>


<div class="form-group">
<label class="col-lg-4 control-label">

0 comments on commit 99bd5a7

Please sign in to comment.
You can’t perform that action at this time.