From cb43eff76cabc2587261820e41ed4691c1bf5d03 Mon Sep 17 00:00:00 2001 From: skysilver Date: Tue, 5 Dec 2017 22:40:52 +0300 Subject: [PATCH] v.0.6-alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * В интерфейс модуля добавлена кнопка для запроса актуального состояния устройства. * В интерфейс модуля добавлена кнопка для получения сведения miIO.info. * Добавлено условие постановки команды в очередь запросов - обязательное наличие IP и токена. * Рефакторинг. --- modules/xiaomimiio/miio_devices_edit.inc.php | 104 +++---- .../xiaomimiio/miio_devices_search.inc.php | 2 +- modules/xiaomimiio/xiaomimiio.class.php | 257 +++++++++++------- scripts/cycle_xiaomimiio.php | 9 +- templates/xiaomimiio/action_admin.html | 22 +- .../xiaomimiio/miio_devices_edit_default.html | 235 ++++++++-------- .../xiaomimiio/miio_devices_search_admin.html | 101 ++++--- 7 files changed, 412 insertions(+), 318 deletions(-) diff --git a/modules/xiaomimiio/miio_devices_edit.inc.php b/modules/xiaomimiio/miio_devices_edit.inc.php index dd360b6..e4d44f1 100644 --- a/modules/xiaomimiio/miio_devices_edit.inc.php +++ b/modules/xiaomimiio/miio_devices_edit.inc.php @@ -2,7 +2,7 @@ /* * @author * @copyright 2017 Agaphonov Dmitri aka skysilver (c) -* @version 0.5 +* @version 0.6 */ if ($this->owner->name == 'panel') { @@ -18,105 +18,107 @@ $this->getConfig(); $ok = 1; - // step: default if ($this->tab == '') { - /*updating '<%LANG_TITLE%>' (varchar, required)*/ + global $title; $rec['TITLE'] = $title; if ($rec['TITLE'] == '') { $out['ERR_TITLE'] = 1; $ok = 0; } - //updating 'IP' (varchar) + global $ip; $rec['IP'] = $ip; - //updating 'TOKEN' (varchar) + if ($rec['IP'] == '') { + $out['ERR_IP'] = 1; + $ok = 0; + } + global $token; $rec['TOKEN'] = $token; - //updating 'DEVICE_TYPE' (varchar) + global $device_type; $rec['DEVICE_TYPE'] = $device_type; - //updating 'UPDATE_PERIOD' (varchar) + global $update_period; $rec['UPDATE_PERIOD'] = (int)$update_period; if ($rec['UPDATE_PERIOD'] > 0) { $rec['NEXT_UPDATE'] = date('Y-m-d H:i:s'); } - $commands=array('online','command','message'); + $commands = array('online', 'command', 'message'); } - // step: data - if ($this->tab == 'data') { - // - } - - //UPDATING RECORD if ($ok) { if ($rec['ID']) { - SQLUpdate($table_name, $rec); // update + if ($this->config['API_LOG_DEBMES']) DebMes('Save params for device with IP ' . $rec['IP'], 'xiaomimiio'); + SQLUpdate($table_name, $rec); } else { - $new_rec = 1; - $rec['ID'] = SQLInsert($table_name, $rec); // adding new record + if ($this->config['API_LOG_DEBMES']) DebMes('Manual add new device with IP ' . $rec['IP'], 'xiaomimiio'); + $rec['ID'] = SQLInsert($table_name, $rec); } + $out['OK'] = 1; if ($this->tab == '') { foreach($commands as $cmd) { - $cmd_rec=SQLSelectOne("SELECT * FROM miio_commands WHERE DEVICE_ID=".$rec['ID']." AND TITLE = '".$cmd."'"); + $cmd_rec = SQLSelectOne("SELECT * FROM miio_commands WHERE DEVICE_ID=" . $rec['ID'] . " AND TITLE = '" . $cmd . "'"); if (!$cmd_rec['ID']) { - $cmd_rec=array(); - $cmd_rec['TITLE']=$cmd; - $cmd_rec['DEVICE_ID']=$rec['ID']; - SQLInsert('miio_commands',$cmd_rec); + $cmd_rec = array(); + $cmd_rec['TITLE'] = $cmd; + $cmd_rec['DEVICE_ID'] = $rec['ID']; + SQLInsert('miio_commands', $cmd_rec); } } - $this->requestInfo($rec['ID']); + + $this->processCommand($rec['ID'], 'online', 0); + + if ($rec['TOKEN'] != '' && $rec['IP'] != '') $this->requestInfo($rec['ID']); sleep(1); - if ($this->config['API_LOG_DEBMES']) DebMes('Save device params [requestStatus] DevID='.$rec['ID'], 'xiaomimiio'); - if ((int)$update_period == 0) $this->requestStatus($rec['ID']); + if ((int)$update_period == 0 && $rec['TOKEN'] != '' && $rec['DEVICE_TYPE'] != '') $this->requestStatus($rec['ID']); } } else { $out['ERR'] = 1; } } -// step: default -if ($this->tab=='') { -} -// step: data -if ($this->tab=='data') { - //dataset2 - $new_id=0; +if ($this->tab == 'data') { + + $new_id = 0; global $delete_id; + if ($delete_id) { - SQLExec("DELETE FROM miio_commands WHERE ID='".(int)$delete_id."'"); + SQLExec("DELETE FROM miio_commands WHERE ID='" . (int)$delete_id . "'"); } - $properties=SQLSelect("SELECT * FROM miio_commands WHERE DEVICE_ID='".$rec['ID']."' ORDER BY ID"); - $total=count($properties); - for($i=0;$i<$total;$i++) { - if ($properties[$i]['ID']==$new_id) continue; - if ($this->mode=='update') { - /* - global ${'title'.$properties[$i]['ID']}; - $properties[$i]['TITLE']=trim(${'title'.$properties[$i]['ID']}); - global ${'value'.$properties[$i]['ID']}; - $properties[$i]['VALUE']=trim(${'value'.$properties[$i]['ID']}); - */ + + $properties = SQLSelect("SELECT * FROM miio_commands WHERE DEVICE_ID='" . $rec['ID'] . "' ORDER BY ID"); + $total = count($properties); + + for($i = 0; $i < $total; $i++) { + if ($properties[$i]['ID'] == $new_id) continue; + + if ($this->mode == 'update') { + global ${'linked_object'.$properties[$i]['ID']}; - $properties[$i]['LINKED_OBJECT']=trim(${'linked_object'.$properties[$i]['ID']}); + $properties[$i]['LINKED_OBJECT'] = trim(${'linked_object'.$properties[$i]['ID']}); + global ${'linked_property'.$properties[$i]['ID']}; - $properties[$i]['LINKED_PROPERTY']=trim(${'linked_property'.$properties[$i]['ID']}); + $properties[$i]['LINKED_PROPERTY'] = trim(${'linked_property'.$properties[$i]['ID']}); + global ${'linked_method'.$properties[$i]['ID']}; - $properties[$i]['LINKED_METHOD']=trim(${'linked_method'.$properties[$i]['ID']}); + $properties[$i]['LINKED_METHOD'] = trim(${'linked_method'.$properties[$i]['ID']}); + SQLUpdate('miio_commands', $properties[$i]); - $old_linked_object=$properties[$i]['LINKED_OBJECT']; - $old_linked_property=$properties[$i]['LINKED_PROPERTY']; - if ($old_linked_object && $old_linked_object!=$properties[$i]['LINKED_OBJECT'] && $old_linked_property && $old_linked_property!=$properties[$i]['LINKED_PROPERTY']) { + + $old_linked_object = $properties[$i]['LINKED_OBJECT']; + $old_linked_property = $properties[$i]['LINKED_PROPERTY']; + + if ($old_linked_object && $old_linked_object != $properties[$i]['LINKED_OBJECT'] && $old_linked_property && $old_linked_property != $properties[$i]['LINKED_PROPERTY']) { removeLinkedProperty($old_linked_object, $old_linked_property, $this->name); } } - $properties[$i]['VALUE']=str_replace('",','", ',$properties[$i]['VALUE']); + + $properties[$i]['VALUE'] = str_replace('",','", ',$properties[$i]['VALUE']); if ($properties[$i]['LINKED_OBJECT'] && $properties[$i]['LINKED_PROPERTY']) { addLinkedProperty($properties[$i]['LINKED_OBJECT'], $properties[$i]['LINKED_PROPERTY'], $this->name); diff --git a/modules/xiaomimiio/miio_devices_search.inc.php b/modules/xiaomimiio/miio_devices_search.inc.php index ef07ae4..24f6bf9 100644 --- a/modules/xiaomimiio/miio_devices_search.inc.php +++ b/modules/xiaomimiio/miio_devices_search.inc.php @@ -2,7 +2,7 @@ /* * @author * @copyright 2017 Agaphonov Dmitri aka skysilver (c) -* @version 0.5 +* @version 0.6 */ global $session; diff --git a/modules/xiaomimiio/xiaomimiio.class.php b/modules/xiaomimiio/xiaomimiio.class.php index 9e729df..b570eee 100644 --- a/modules/xiaomimiio/xiaomimiio.class.php +++ b/modules/xiaomimiio/xiaomimiio.class.php @@ -4,7 +4,7 @@ * @package project * @author * @copyright 2017 Agaphonov Dmitri aka skysilver (c) -* @version 0.5 +* @version 0.6 */ define ('MIIO_YEELIGHT_WHITE_BULB_PROPS', 'power,bright'); @@ -150,30 +150,34 @@ function getParams() { function run() { global $session; - $out=array(); - if ($this->action=='admin') { + + $out = array(); + + if ($this->action == 'admin') { $this->admin($out); } else { $this->usual($out); } if (IsSet($this->owner->action)) { - $out['PARENT_ACTION']=$this->owner->action; + $out['PARENT_ACTION'] = $this->owner->action; } if (IsSet($this->owner->name)) { - $out['PARENT_NAME']=$this->owner->name; + $out['PARENT_NAME'] = $this->owner->name; } - $out['VIEW_MODE']=$this->view_mode; - $out['EDIT_MODE']=$this->edit_mode; - $out['MODE']=$this->mode; - $out['ACTION']=$this->action; - $out['DATA_SOURCE']=$this->data_source; - $out['TAB']=$this->tab; - $this->data=$out; - $p=new parser(DIR_TEMPLATES.$this->name."/".$this->name.".html", $this->data, $this); - $this->result=$p->result; + $out['VIEW_MODE'] = $this->view_mode; + $out['EDIT_MODE'] = $this->edit_mode; + $out['MODE'] = $this->mode; + $out['ACTION'] = $this->action; + $out['DATA_SOURCE'] = $this->data_source; + $out['TAB'] = $this->tab; + + $this->data = $out; + + $p = new parser(DIR_TEMPLATES . $this->name . '/' . $this->name . '.html', $this->data, $this); + $this->result = $p->result; } /** @@ -194,8 +198,11 @@ function admin(&$out) { $out['API_LOG_CYCLE'] = $this->config['API_LOG_CYCLE']; $out['API_LOG_MIIO'] = $this->config['API_LOG_MIIO']; - if ((time() - gg('cycle_xiaomimiioRun')) < 15 ) $out['CYCLERUN'] = 1; - else $out['CYCLERUN'] = 0; + if ((time() - gg('cycle_xiaomimiioRun')) < 15 ) { + $out['CYCLERUN'] = 1; + } else { + $out['CYCLERUN'] = 0; + } if ($this->view_mode == 'update_settings') { @@ -239,6 +246,13 @@ function admin(&$out) { $this->redirect('?'); } + if ($this->view_mode == 'propupd_miio_devices') { + if ($this->config['API_LOG_DEBMES']) DebMes('Starting manual update the properties of the device', 'xiaomimiio'); + $this->requestStatus($this->id); + if ($this->config['API_LOG_DEBMES']) DebMes('Manual update the properties of the device is finished', 'xiaomimiio'); + $this->redirect('?'); + } + if ($this->view_mode == 'edit_miio_devices') { $this->edit_miio_devices($out, $this->id); } @@ -253,7 +267,7 @@ function admin(&$out) { /** * addToQueue * - * ... + * Добавление команды в очередь * * @access private */ @@ -266,7 +280,6 @@ function addToQueue($device_id, $method, $data = '[]') { $rec['DATA'] = $data; $rec['ADDED'] = date('Y-m-d H:i:s'); - //TO-DO: добавить проверку на наличие токена, иначе не ставить команду в очередь. SQLInsert('miio_queue', $rec); } @@ -380,7 +393,7 @@ function discover($ip = '') { /** * requestInfo * - * ... + * Запрос сведений miIO.info * * @access public */ @@ -403,12 +416,9 @@ function requestStatus($device_id) { $device_rec = SQLSelectOne("SELECT * FROM miio_devices WHERE ID=" . (int)$device_id); - //DebMes($device_rec['DEVICE_TYPE'], 'xiaomimiio'); - //DebMes('[requestStatus] DEVICE_TYPE='.$device_rec['DEVICE_TYPE'], 'xiaomimiio'); - if ($device_rec['DEVICE_TYPE'] == 'philips.light.bulb') { // - $props=explode(',', MIIO_PHILIPS_LIGHT_BULB_PROPS); + $props = explode(',', MIIO_PHILIPS_LIGHT_BULB_PROPS); $total = count($props); for ($i = 0; $i < $total; $i++) { $props[$i] = '"' . $props[$i] . '"'; @@ -476,44 +486,82 @@ function usual(&$out) { if ($this->config['API_LOG_DEBMES']) DebMes('Starting periodic search for devices in the network', 'xiaomimiio'); $this->discover(); if ($this->config['API_LOG_DEBMES']) DebMes('Periodic search for devices in the network is finished', 'xiaomimiio'); + } else if ($op == 'get_miio_info') { + + $dip = $_GET['dip']; + $dtoken = $_GET['dtoken']; + + header("HTTP/1.0: 200 OK\n"); + header('Content-Type: text/html; charset=utf-8'); + + if (!class_exists('miIO', false)) { + include_once(DIR_MODULES . 'xiaomimiio/lib/miio.class.php'); + } + $this->getConfig(); + + if ($miio_module->config['API_IP']) $bind_ip = $miio_module->config['API_IP']; + else $bind_ip = '0.0.0.0'; + if ($miio_module->config['API_LOG_MIIO']) $miio_debug = true; + else $miio_debug = false; + + $dev = new miIO($dip, $bind_ip, $dtoken, $miio_debug); + + if ($dev->getInfo(time())) { + if ($dev->data == '') $info = 'Сведения miIO.info не получены. Вероятно, указан неверный токен.'; + else $info = $dev->data; + } else $info = 'Что-то пошло не так...'; + + echo $info; + exit; } echo 'OK'; exit; } } + + /** + * miio_devices search + * + * @access public + */ -/** -* miio_devices search -* -* @access public -*/ - function search_miio_devices(&$out) { - require(DIR_MODULES.$this->name.'/miio_devices_search.inc.php'); - } -/** -* miio_devices edit/add -* -* @access public -*/ - function edit_miio_devices(&$out, $id) { - require(DIR_MODULES.$this->name.'/miio_devices_edit.inc.php'); - } -/** -* miio_devices delete record -* -* @access public -*/ - function delete_miio_devices($id) { - $rec=SQLSelectOne("SELECT * FROM miio_devices WHERE ID='$id'"); - // some action for related tables - SQLExec("DELETE FROM miio_commands WHERE DEVICE_ID='".$rec['ID']."'"); - SQLExec("DELETE FROM miio_devices WHERE ID='".$rec['ID']."'"); - } + function search_miio_devices(&$out) { + + require(DIR_MODULES.$this->name . '/miio_devices_search.inc.php'); + + } + + /** + * miio_devices edit/add + * + * @access public + */ + + function edit_miio_devices(&$out, $id) { + + require(DIR_MODULES.$this->name . '/miio_devices_edit.inc.php'); + + } + + /** + * miio_devices delete record + * + * @access public + */ + + function delete_miio_devices($id) { + + $rec = SQLSelectOne("SELECT * FROM miio_devices WHERE ID='$id'"); + + SQLExec("DELETE FROM miio_commands WHERE DEVICE_ID='" . $rec['ID'] . "'"); + SQLExec("DELETE FROM miio_devices WHERE ID='" . $rec['ID'] . "'"); + + } /** * propertySetHandle * - * ... + * Обработчик привязанных свойств и методов * * @access private */ @@ -524,64 +572,81 @@ function propertySetHandle($object, $property, $value) { $table = 'miio_commands'; - $properties = SQLSelect("SELECT miio_commands.*, miio_devices.DEVICE_TYPE FROM miio_commands LEFT JOIN miio_devices ON miio_devices.ID=miio_commands.DEVICE_ID WHERE miio_commands.LINKED_OBJECT LIKE '".DBSafe($object)."' AND miio_commands.LINKED_PROPERTY LIKE '".DBSafe($property)."'"); - + $properties = SQLSelect("SELECT miio_commands.*, miio_devices.TOKEN, miio_devices.DEVICE_TYPE FROM miio_commands LEFT JOIN miio_devices ON miio_devices.ID=miio_commands.DEVICE_ID WHERE miio_commands.LINKED_OBJECT LIKE '".DBSafe($object)."' AND miio_commands.LINKED_PROPERTY LIKE '".DBSafe($property)."'"); + /* + ID TITLE VALUE DEVICE_ID LINKED_OBJECT LINKED_PROPERTY LINKED_METHOD UPDATED TOKEN DEVICE_TYPE + 3 command NULL 2 ThisComputer GwCmd NULL xxxxx lumi.gateway.v3 + 10 command NULL 3 ThisComputer GwCmd NULL isa.camera.isc5 + */ $total = count($properties); if ($total) { for($i = 0; $i < $total; $i++) { - if ($properties[$i]['TITLE'] == 'command') { - // Отправка любой команды (метода) без параметров. - // Например, miIO.info, toggle, app_start и др. - $this->addToQueue($properties[$i]['DEVICE_ID'], $value, '[]'); - } elseif ($properties[$i]['TITLE'] == 'power') { - // Команда на включение и выключени - if ($value) { - $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["on"]'); - } else { - $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["off"]'); + // Если есть токен, то обрабатываем команду и ставим ее в очередь. Без токена ничего не делаем. + if ($properties[$i]['TOKEN'] != '') { + if ($properties[$i]['TITLE'] == 'command') { + // Отправка любой команды (метода) без параметров. + // Например, miIO.info, toggle, app_start и др. + $this->addToQueue($properties[$i]['DEVICE_ID'], $value, '[]'); + //TO-DO: после отправки команды желательно обновить сведения об устройстве, + //но при этом перезапишется поле message (удалится результат выполнения команды), + //что может быть неприемлемо. + //$this->requestStatus($properties[$i]['DEVICE_ID']); + } elseif ($properties[$i]['TITLE'] == 'power') { + // Команда на включение и выключени + if ($value) { + $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["on"]'); + } else { + $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["off"]'); + } + } elseif ($properties[$i]['TITLE'] == 'bright') { + // Команда на изменение яркости (в % от 1 до 100) + $value = (int)$value; + if ($value < 1) $value = 1; + if ($value > 100) $value = 100; + $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_bright', "[$value]"); + } elseif ($properties[$i]['TITLE'] == 'cct') { + // Команда на изменение цветовой температуры (в % от 1 до 100) + $value = (int)$value; + if ($value < 1) $value = 1; + if ($value > 100) $value = 100; + $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_cct', "[$value]"); } - } elseif ($properties[$i]['TITLE'] == 'bright') { - // Команда на изменение яркости (в % от 1 до 100) - $value = (int)$value; - if ($value < 1) $value = 1; - if ($value > 100) $value = 100; - $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_bright', "[$value]"); - } elseif ($properties[$i]['TITLE'] == 'cct') { - // Команда на изменение цветовой температуры (в % от 1 до 100) - $value = (int)$value; - if ($value < 1) $value = 1; - if ($value > 100) $value = 100; - $this->addToQueue($properties[$i]['DEVICE_ID'], 'set_cct', "[$value]"); + SQLExec("UPDATE miio_commands SET VALUE='".DBSafe($value)."' WHERE ID=".$properties[$i]['ID']); } - SQLExec("UPDATE miio_commands SET VALUE='".DBSafe($value)."' WHERE ID=".$properties[$i]['ID']); } } } - + /** + * processCommand + * + * ... + * + * @access private + */ function processCommand($device_id, $command, $value, $params = 0) { - //DebMes("processCommand($device_id, $command, $value, $params)", 'xiaomimiio'); + $cmd_rec = SQLSelectOne("SELECT * FROM miio_commands WHERE DEVICE_ID=".(int)$device_id." AND TITLE LIKE '".DBSafe($command)."'"); - $cmd_rec=SQLSelectOne("SELECT * FROM miio_commands WHERE DEVICE_ID=".(int)$device_id." AND TITLE LIKE '".DBSafe($command)."'"); - if (!$cmd_rec['ID']) { - $cmd_rec=array(); - $cmd_rec['TITLE']=$command; - $cmd_rec['DEVICE_ID']=$device_id; - $cmd_rec['ID']=SQLInsert('miio_commands',$cmd_rec); - } + if (!$cmd_rec['ID']) { + $cmd_rec = array(); + $cmd_rec['TITLE'] = $command; + $cmd_rec['DEVICE_ID'] = $device_id; + $cmd_rec['ID'] = SQLInsert('miio_commands', $cmd_rec); + } - $old_value=$cmd_rec['VALUE']; + $old_value = $cmd_rec['VALUE']; - $cmd_rec['VALUE']=$value; - $cmd_rec['UPDATED']=date('Y-m-d H:i:s'); - SQLUpdate('miio_commands',$cmd_rec); + $cmd_rec['VALUE'] = $value; + $cmd_rec['UPDATED'] = date('Y-m-d H:i:s'); + SQLUpdate('miio_commands', $cmd_rec); - if ($cmd_rec['LINKED_OBJECT'] && $cmd_rec['LINKED_PROPERTY']) { - setGlobal($cmd_rec['LINKED_OBJECT'] . '.' . $cmd_rec['LINKED_PROPERTY'], $value, array($this->name => '0')); - } + if ($cmd_rec['LINKED_OBJECT'] && $cmd_rec['LINKED_PROPERTY']) { + setGlobal($cmd_rec['LINKED_OBJECT'] . '.' . $cmd_rec['LINKED_PROPERTY'], $value, array($this->name => '0')); + } + if ($cmd_rec['LINKED_OBJECT'] && $cmd_rec['LINKED_METHOD']) { if (!is_array($params)) { $params = array(); @@ -720,7 +785,6 @@ function processMessage($message, $command, $device_id) { if ($val == 'on') $val = 1; else if ($val == 'off') $val = 0; } - //DebMes("cmd=$cmd value=$val", 'xiaomimiio'); $this->processCommand($device['ID'], $cmd, $val); } @@ -736,9 +800,8 @@ function processMessage($message, $command, $device_id) { function install($data = '') { - //setGlobal('cycle_schedappControl', 'restart'); - //setGlobal('cycle_schedappAutoRestart', '1'); - //$this->name + //setGlobal('cycle_xiaomimiioControl', 'start'); + //setGlobal('cycle_xiaomimiioAutoRestart', '1'); parent::install(); @@ -759,7 +822,7 @@ function uninstall() { - перед удалением таблиц нужно остановить цикл, если он запущен, чтобы не было ошибок SQL - также нужно удалить сведения о цикле из Xray и свойства из объекта ThisComputer (ThisComputer.cycle_xiaomimiioRun, ThisComputer.cycle_xiaomimiioControl, - ThisComputer.cycle_xiaomihomeDisabled, ThisComputer.cycle_xiaomimiioAutoRestart) + ThisComputer.cycle_xiaomimiioDisabled, ThisComputer.cycle_xiaomimiioAutoRestart) */ SQLExec('DROP TABLE IF EXISTS miio_devices'); diff --git a/scripts/cycle_xiaomimiio.php b/scripts/cycle_xiaomimiio.php index 8c535c5..9f9553b 100644 --- a/scripts/cycle_xiaomimiio.php +++ b/scripts/cycle_xiaomimiio.php @@ -3,7 +3,7 @@ * Xiaomi miIO Cycle * @author * @copyright 2017 Agaphonov Dmitri aka skysilver (c) -* @version 0.5 +* @version 0.6 */ chdir(dirname(__FILE__) . '/../'); @@ -72,7 +72,6 @@ $reply = ''; $dev->data = ''; if ($queue[$i]['DEVICE_ID']) { - // get status command if ($queue[$i]['IP']) { $dev->ip = $queue[$i]['IP']; } else { @@ -96,13 +95,13 @@ if ($reply != '') { if ($cycle_debug) echo date('H:i:s') . " Reply: $reply \n"; $url = BASE_URL.'/ajax/xiaomimiio.html?op=process&command='.urlencode($queue[$i]['METHOD']).'&device_id='.$queue[$i]['DEVICE_ID'].'&message='.urlencode($reply); - $res = get_headers($url); + getURLBackground($url, 0); if ($cycle_debug) echo date('H:i:s') . ' Background processing of the response is started' . PHP_EOL; } } } - // TO-DO: проверить на наличие типа устройства (DEVICE_TYPE не пустой) - $devices = SQLSelect('SELECT * FROM miio_devices WHERE UPDATE_PERIOD>0 AND NEXT_UPDATE<=NOW()'); + + $devices = SQLSelect("SELECT * FROM miio_devices WHERE UPDATE_PERIOD>0 AND NEXT_UPDATE<=NOW() AND DEVICE_TYPE!='' AND TOKEN!=''"); if ($devices[0]['ID']) { $total = count($devices); diff --git a/templates/xiaomimiio/action_admin.html b/templates/xiaomimiio/action_admin.html index 1f3cfe4..e802857 100644 --- a/templates/xiaomimiio/action_admin.html +++ b/templates/xiaomimiio/action_admin.html @@ -20,14 +20,24 @@ - - +
    diff --git a/templates/xiaomimiio/miio_devices_edit_default.html b/templates/xiaomimiio/miio_devices_edit_default.html index 815da88..e43ffdf 100644 --- a/templates/xiaomimiio/miio_devices_edit_default.html +++ b/templates/xiaomimiio/miio_devices_edit_default.html @@ -1,128 +1,125 @@
-[#if OK#] -
<#LANG_DATA_SAVED#>
-[#endif OK#] -[#if ERR#] -
<#LANG_FILLOUT_REQURED#>
-[#endif ERR#] -
-[#if ID=""#] -<#LANG_NEW_RECORD#> -[#endif ID#] - -
- -
-
- -
- -
-
- -
- -
-
+ [#if OK#] +
<#LANG_DATA_SAVED#>
+ [#endif OK#] + + [#if ERR#] +
<#LANG_FILLOUT_REQURED#>
+ [#endif ERR#] + +
+ [#if ID=""#] + <#LANG_NEW_RECORD#> + [#endif ID#] - -
- -
- -
-
+
+ +
+
- -
- -
-
+
+ +
+
- [#if SERIAL!=""#] -
- -
[#SERIAL#]
-
- [#endif#] +
+ +
+
- [#if DEVICE_TYPE_CODE!=""#] -
- -
[#DEVICE_TYPE_CODE#]
-
- [#endif#] +
+ +
+ +
+
- [#if MAC!=""#] -
- -
[#MAC#]
-
- [#endif#] +
+ +
+
- - [#if MODEL!=""#] -
- -
[#MODEL#]
-
- [#endif#] - - - [#if HW_VER!=""#] -
- -
[#HW_VER#]
-
- [#endif#] - - -
-
- [#if ID!=""#] - - [#else ID#] - - [#endif ID#] - <#LANG_STRING_BACK#> - - - - - - -
-
-
+ [#if SERIAL!=""#] +
+ +
[#SERIAL#]
+
+ [#endif#] + + [#if DEVICE_TYPE_CODE!=""#] +
+ +
[#DEVICE_TYPE_CODE#]
+
+ [#endif#] + + [#if MAC!=""#] +
+ +
[#MAC#]
+
+ [#endif#] + + [#if MODEL!=""#] +
+ +
[#MODEL#]
+
+ [#endif#] + + [#if HW_VER!=""#] +
+ +
[#HW_VER#]
+
+ [#endif#] + +
+
+ [#if ID!=""#] + + [#else ID#] + + [#endif ID#] + <#LANG_STRING_BACK#> + + + + + + +
+
+
diff --git a/templates/xiaomimiio/miio_devices_search_admin.html b/templates/xiaomimiio/miio_devices_search_admin.html index 54fed58..0dddce4 100644 --- a/templates/xiaomimiio/miio_devices_search_admin.html +++ b/templates/xiaomimiio/miio_devices_search_admin.html @@ -3,7 +3,7 @@

<#LANG_ADD#> - <#LANG_RESCAN_DEVICES#> + <#LANG_RESCAN_DEVICES#>

@@ -24,10 +24,42 @@ [#endif PAGES#] + + + +
[#begin RESULT#] + + + - - - [#end RESULT#]
@@ -42,25 +74,24 @@ [#endif#] - [#if IP!=""#] - [#IP#] - [#else#] -   - [#endif#] - - [#if TOKEN!=""#] - [#TOKEN#] - [#else#] -   - [#endif#] + [#if IP!=""#] + [#IP#] +   + [#if TOKEN!="" && ONLINE==1#] + + + + [#endif#] + [#else#] +   + [#endif#] - [#if MAC!=""#] - [#MAC#] - [#else#] -   - [#endif#] + [#if TOKEN!=""#] + [#TOKEN#] + [#else#] +   + [#endif#] [#if DEVICE_TYPE!=""#] @@ -80,29 +111,21 @@   [#endif#] - [#if HW_VER!=""#] - [#HW_VER#] - [#else#] -   - [#endif#] - - [#if UPDATE_PERIOD!=""#] - [#UPDATE_PERIOD#] - [#else#] -   - [#endif#] + + [#if UPDATE_PERIOD!=""#] + [#UPDATE_PERIOD#] + [#else#] +   + [#endif#] -
- [#if "<#ACTION#>"=="admin"#] - - - [#endif ACTION#] -
+
+ [#if "<#ACTION#>"=="admin"#] + + + + [#endif ACTION#] +