Skip to content

Commit

Permalink
v.1.4-beta
Browse files Browse the repository at this point in the history
* Добавлена поддержка розетки Mi Smart Socket Plug with USB:
  * получение текущего статуса и параметров (power, temperature, usb_on, wifi_led);
  * включение/выключение (power);
  * управление usb-портом (usb_on);
  * управление индикатором wifi (wifi_led).
* Для светильника Yeelight Ceiling Light добавлен режим ночника (nl_br).
* Добавлено лого для новой панели управления.
  • Loading branch information
skysilver-lab committed Mar 22, 2018
1 parent bf2e50e commit 0ea629e
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 13 deletions.
Binary file added img/modules/xiaomimiio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion modules/xiaomimiio/miio_devices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @author <[email protected]>
* @copyright 2017-2018 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 1.2b
* @version 1.4b
*/

if ($this->owner->name == 'panel') {
Expand Down Expand Up @@ -189,6 +189,9 @@
if ($properties[$i]['TITLE'] == 'wifi_led') {
$properties[$i]['SDEVICE_TYPE'] = 'relay';
}
if ($properties[$i]['TITLE'] == 'usb_on') {
$properties[$i]['SDEVICE_TYPE'] = 'relay';
}
if ($properties[$i]['TITLE'] == 'bright') {
$properties[$i]['SDEVICE_TYPE'] = 'dimmer';
}
Expand All @@ -198,6 +201,9 @@
if ($properties[$i]['TITLE'] == 'ct') {
$properties[$i]['SDEVICE_TYPE'] = 'dimmer';
}
if ($properties[$i]['TITLE'] == 'nl_br') {
$properties[$i]['SDEVICE_TYPE'] = 'dimmer';
}
if ($properties[$i]['TITLE'] == 'rgb') {
$properties[$i]['SDEVICE_TYPE'] = 'rgb';
}
Expand Down
2 changes: 1 addition & 1 deletion modules/xiaomimiio/miio_devices_search.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* @author <[email protected]>
* @copyright 2017-2018 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 1.2b
* @version 1.4b
*/

global $session;
Expand Down
56 changes: 50 additions & 6 deletions modules/xiaomimiio/xiaomimiio.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* @package project
* @author <[email protected]>
* @copyright 2017-2018 Agaphonov Dmitri aka skysilver <[email protected]> (c)
* @version 1.2b
* @version 1.4b
*/

define ('MIIO_YEELIGHT_WHITE_BULB_PROPS', 'power,bright');
define ('MIIO_YEELIGHT_COLOR_BULB_PROPS', 'power,bright,ct,rgb,hue,sat,color_mode');
define ('MIIO_YEELIGHT_STRIP_PROPS', 'power,bright,ct,rgb,color_mode');
define ('MIIO_YEELIGHT_CEILING_LIGHT_PROPS', 'power,bright,ct');
define ('MIIO_YEELIGHT_CEILING_LIGHT_PROPS', 'power,bright,ct,nl_br,color_mode,flowing');
define ('MIIO_YEELIGHT_LAMP_LIGHT_PROPS', 'power,bright,ct');
define ('MIIO_YEELIGHT_BSLAMP1_PROPS', 'power,bright,ct,rgb,hue,sat,color_mode,flowing,pdo_status,save_state,flow_params,nl_br,nighttime,miband_sleep');

Expand All @@ -20,6 +20,8 @@
define ('MIIO_PHILIPS_EYECARE_LAMP_2_PROPS', 'power,bright,notifystatus,ambstatus,ambvalue,eyecare,scene_num,bls,dvalue');

define ('MIIO_CHUANGMI_PLUG_M1_PROPS', 'power,temperature');
define ('MIIO_CHUANGMI_PLUG_V1_PROPS', 'power,temperature,usb_on,wifi_led');

define ('MIIO_ZIMI_POWERSTRIP_2_PROPS', 'power,temperature,current,power_consume_rate,wifi_led');

define ('MIIO_ZHIMI_HUMIDIFIER_PROPS', 'power,mode,temp_dec,humidity,buzzer,led_b');
Expand Down Expand Up @@ -509,6 +511,14 @@ function requestStatus($device_id) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
} elseif ($device_rec['DEVICE_TYPE'] == 'chuangmi.plug.v1') {
//
$props = explode(',', MIIO_CHUANGMI_PLUG_V1_PROPS);
$total = count($props);
for ($i = 0; $i < $total; $i++) {
$props[$i] = '"' . $props[$i] . '"';
}
$this->addToQueue($device_id, 'get_prop', '[' . implode(',', $props) . ']');
} elseif ($device_rec['DEVICE_TYPE'] == 'lumi.gateway.v3') {
//
$this->addToQueue($device_id, 'get_prop_fm', '[]');
Expand Down Expand Up @@ -723,11 +733,12 @@ function propertySetHandle($object, $property, $value) {
$table = 'miio_commands';

$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
ID TITLE NOTE VALUE DEVICE_ID LINKED_OBJECT LINKED_PROPERTY LINKED_METHOD UPDATE TOKEN DEVICE_TYPE
122 power "" 0 19 miioRelay01 status "" 2018-03-20 00:50:34 xxxxx yeelink.light.mono1
*/

$total = count($properties);

if ($total) {
Expand Down Expand Up @@ -756,6 +767,7 @@ function propertySetHandle($object, $property, $value) {
} else {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_power', '["off"]');
}
// TO-DO: Если у-во yeelight, то используем дополнительные опции команды (effect, duration, mode).
} elseif ($properties[$i]['TITLE'] == 'buzzer') {
// Команда на включение и выключение
if ($value) {
Expand Down Expand Up @@ -796,6 +808,13 @@ function propertySetHandle($object, $property, $value) {
} else {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_wifi_led', '["off"]');
}
} elseif ($properties[$i]['TITLE'] == 'usb_on') {
// Команда на включение и выключение usb-порта розетки
if ($value) {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_usb_on', '[]');
} else {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_usb_off', '[]');
}
} elseif ($properties[$i]['TITLE'] == 'ir_play') {
// Команда для отправки IR-кода
$this->addToQueue($properties[$i]['DEVICE_ID'], 'miIO.ir_play', '{"freq":38400,"code":"' . $value . '"}');
Expand Down Expand Up @@ -824,6 +843,15 @@ function propertySetHandle($object, $property, $value) {
} else {
$this->addToQueue($properties[$i]['DEVICE_ID'], 'enable_ac', '[0]');
}
} elseif ($properties[$i]['TITLE'] == 'nl_br') {
// Ночной режим (ночник, "луна")
if ($value) {
$bright = SQLSelectOne("SELECT miio_commands.VALUE FROM miio_commands WHERE miio_commands.TITLE LIKE 'bright' AND DEVICE_ID=" . $properties[$i]['DEVICE_ID']);
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_scene', '["nightlight",' . $bright['VALUE'] . ']');
} else {
$ct = SQLSelectOne("SELECT miio_commands.VALUE FROM miio_commands WHERE miio_commands.TITLE LIKE 'ct' AND DEVICE_ID=" . $properties[$i]['DEVICE_ID']);
$this->addToQueue($properties[$i]['DEVICE_ID'], 'set_ct_abx', '[' . $ct['VALUE'] . ',"sudden",100]');
}
} elseif ($properties[$i]['TITLE'] == 'vol_up') {
// Команда увеличения громкости на указанную величину
$value = (int)$value;
Expand Down Expand Up @@ -1077,6 +1105,18 @@ function processMessage($message, $command, $device_id) {
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'chuangmi.plug.v1' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_CHUANGMI_PLUG_V1_PROPS);
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
if ($key == 'usb_on') {
if ($value == 'true') $value = 1;
else if ($value == 'false') $value = 0;
}
$res_commands[] = array('command' => $key, 'value' => $value);
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'philips.light.ceiling' && $command == 'get_prop' && is_array($data['result'])) {
$props = explode(',', MIIO_PHILIPS_LIGHT_CEILING_PROPS);
$i = 0;
Expand All @@ -1090,7 +1130,11 @@ function processMessage($message, $command, $device_id) {
$i = 0;
foreach($props as $key) {
$value = $data['result'][$i];
$res_commands[] = array('command' => $key, 'value' => $value);
if ($key == 'nl_br' && $value != 0) {
$res_commands[4]['value'] = $value; // свойство bright
} else {
$res_commands[] = array('command' => $key, 'value' => $value);
}
$i++;
}
} elseif ($device['DEVICE_TYPE'] == 'yeelink.light.lamp1' && $command == 'get_prop' && is_array($data['result'])) {
Expand Down
5 changes: 2 additions & 3 deletions templates/xiaomimiio/action_admin.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<!-- action usual -->
[#if DATA_SOURCE="miio_devices" || DATA_SOURCE=""#]
<!-- table miio_devices search -->
Expand All @@ -20,7 +19,7 @@ <h4 class="modal-title">Xiaomi miIO</h4>
<div class="modal-body">
<div class="float-right">
<img src="../templates/xiaomimiio/milogo.png" width="48" height="48">
<br><br><p><b>v.1.3b</b></p>
<br><br><p><b>v.1.4b</b></p>
</div>
<p class="float-left">
<#LANG_XIMI_APP_MODULE#><br><br>
Expand All @@ -37,7 +36,7 @@ <h4 class="modal-title">Xiaomi miIO</h4>
<li><#LANG_XIMI_APP_DONATE2#><a href="https://connect.smartliving.ru/tasks/51.html" target="_blank">Connect</a></li>
</ul>
</p>
<h6><#LANG_XIMI_APP_THANKS#>: <b>webms</b>, <b>srvsrvsrv</b>, <b>SergeJey</b>, <b>Gelezako</b>, <b>horas</b>, <b>ингвар</b>, <b>Dicont</b>, <b>shawk</b>, <b>ypiter2006</b>, <b>Genplane</b>, <b>TurburatoR</b>.</h6>
<h6><#LANG_XIMI_APP_THANKS#>: <b>webms</b>, <b>srvsrvsrv</b>, <b>SergeJey</b>, <b>Gelezako</b>, <b>horas</b>, <b>ингвар</b>, <b>Dicont</b>, <b>shawk</b>, <b>ypiter2006</b>, <b>Genplane</b>, <b>TurburatoR</b>, <b>Alex77</b>.</h6>
</div>
<div class="modal-footer">
<div class="pull-left"><#LANG_XIMI_APP_Author#>: <a href="https://telegram.me/agafonov_d" target="_blank">skysilver</a></div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions templates/xiaomimiio/miio_devices_edit_default.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
<option value="yeelink.light.lamp1" [#if DEVICE_TYPE="yeelink.light.lamp1"#] selected[#endif#]>Mi LED Desk Lamp</option>
<option value="lumi.gateway.v3" [#if DEVICE_TYPE="lumi.gateway.v3"#] selected[#endif#]>Mi Smart Home Gateway 2</option>
<option value="zimi.powerstrip.v2" [#if DEVICE_TYPE="zimi.powerstrip.v2"#] selected[#endif#]>Mi Smart Power Strip 6 Plugs</option>
<option value="chuangmi.plug.m1" [#if DEVICE_TYPE="chuangmi.plug.m1"#] selected[#endif#]>Mi Smart Socket Plug 2</option>
<option value="chuangmi.plug.v1" [#if DEVICE_TYPE="chuangmi.plug.v1"#] selected[#endif#]>Mi Smart Socket Plug with USB</option>
<option value="chuangmi.plug.m1" [#if DEVICE_TYPE="chuangmi.plug.m1"#] selected[#endif#]>Mi Smart Socket Plug 2</option>
<option value="isa.camera.isc5" [#if DEVICE_TYPE="isa.camera.isc5"#] selected[#endif#]>Mi Square Smart Camera</option>
<option value="isa.camera.df3" [#if DEVICE_TYPE="isa.camera.df3"#] selected[#endif#]>Mi Dafang Smart Camera 120</option>
<option value="isa.camera.df3" [#if DEVICE_TYPE="isa.camera.df3"#] selected[#endif#]>Mi Dafang Smart Camera 120</option>
<option value="rockrobo.vacuum.v1" [#if DEVICE_TYPE="rockrobo.vacuum.v1"#] selected[#endif#]>Mi Vacuum Cleaner</option>
<option value="xiaomi.repeater.v2" [#if DEVICE_TYPE="xiaomi.repeater.v2"#] selected[#endif#]>Mi WiFi Amplifier 2</option>
</optgroup>
Expand Down

0 comments on commit 0ea629e

Please sign in to comment.