node-miio 0.3.0-beta.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/AGENTS.md +117 -0
  2. package/README.md +41 -2
  3. package/dist/cli/commands/configure.js +60 -0
  4. package/dist/cli/commands/configure.js.map +1 -0
  5. package/dist/cli/commands/control.js +47 -0
  6. package/dist/cli/commands/control.js.map +1 -0
  7. package/dist/cli/commands/discover.js +32 -0
  8. package/dist/cli/commands/discover.js.map +1 -0
  9. package/dist/cli/commands/inspect.js +183 -0
  10. package/dist/cli/commands/inspect.js.map +1 -0
  11. package/dist/cli/commands/miot-spec.js +60 -0
  12. package/dist/cli/commands/miot-spec.js.map +1 -0
  13. package/dist/cli/commands/protocol/call.js +59 -0
  14. package/dist/cli/commands/protocol/call.js.map +1 -0
  15. package/dist/cli/commands/protocol/json-dump.js +56 -0
  16. package/dist/cli/commands/protocol/json-dump.js.map +1 -0
  17. package/dist/cli/commands/protocol/packet.js +30 -0
  18. package/dist/cli/commands/protocol/packet.js.map +1 -0
  19. package/dist/cli/commands/protocol.js +49 -0
  20. package/dist/cli/commands/protocol.js.map +1 -0
  21. package/dist/cli/commands/tokens/update.js +53 -0
  22. package/dist/cli/commands/tokens/update.js.map +1 -0
  23. package/dist/cli/commands/tokens.js +44 -0
  24. package/dist/cli/commands/tokens.js.map +1 -0
  25. package/dist/cli/device-finder.js +72 -0
  26. package/dist/cli/device-finder.js.map +1 -0
  27. package/dist/cli/index.js +64 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/cli/log.js +69 -0
  30. package/dist/cli/log.js.map +1 -0
  31. package/dist/lib/check_result.js +18 -0
  32. package/dist/lib/check_result.js.map +1 -0
  33. package/dist/lib/connect_to_device.js +123 -0
  34. package/dist/lib/connect_to_device.js.map +1 -0
  35. package/dist/lib/device.js +259 -0
  36. package/dist/lib/device.js.map +1 -0
  37. package/dist/lib/device_info.js +297 -0
  38. package/dist/lib/device_info.js.map +1 -0
  39. package/dist/lib/devices/air-monitor.js +42 -0
  40. package/dist/lib/devices/air-monitor.js.map +1 -0
  41. package/dist/lib/devices/air-purifier.js +144 -0
  42. package/dist/lib/devices/air-purifier.js.map +1 -0
  43. package/dist/lib/devices/capabilities/battery-level.js +13 -0
  44. package/dist/lib/devices/capabilities/battery-level.js.map +1 -0
  45. package/dist/lib/devices/capabilities/buzzer.js +69 -0
  46. package/dist/lib/devices/capabilities/buzzer.js.map +1 -0
  47. package/dist/lib/devices/capabilities/changeable-led-brightness.js +44 -0
  48. package/dist/lib/devices/capabilities/changeable-led-brightness.js.map +1 -0
  49. package/dist/lib/devices/capabilities/colorable.js +14 -0
  50. package/dist/lib/devices/capabilities/colorable.js.map +1 -0
  51. package/dist/lib/devices/capabilities/dimmable.js +14 -0
  52. package/dist/lib/devices/capabilities/dimmable.js.map +1 -0
  53. package/dist/lib/devices/capabilities/mode.js +13 -0
  54. package/dist/lib/devices/capabilities/mode.js.map +1 -0
  55. package/dist/lib/devices/capabilities/power.js +13 -0
  56. package/dist/lib/devices/capabilities/power.js.map +1 -0
  57. package/dist/lib/devices/capabilities/sensor.js +46 -0
  58. package/dist/lib/devices/capabilities/sensor.js.map +1 -0
  59. package/dist/lib/devices/capabilities/switchable-led.js +48 -0
  60. package/dist/lib/devices/capabilities/switchable-led.js.map +1 -0
  61. package/dist/lib/devices/chuangmi.plug.v1.js +47 -0
  62. package/dist/lib/devices/chuangmi.plug.v1.js.map +1 -0
  63. package/dist/lib/devices/eyecare-lamp2.js +151 -0
  64. package/dist/lib/devices/eyecare-lamp2.js.map +1 -0
  65. package/dist/lib/devices/gateway/86sw1.js +20 -0
  66. package/dist/lib/devices/gateway/86sw1.js.map +1 -0
  67. package/dist/lib/devices/gateway/86sw2.js +36 -0
  68. package/dist/lib/devices/gateway/86sw2.js.map +1 -0
  69. package/dist/lib/devices/gateway/ctrl_ln1.js +37 -0
  70. package/dist/lib/devices/gateway/ctrl_ln1.js.map +1 -0
  71. package/dist/lib/devices/gateway/ctrl_ln2.js +45 -0
  72. package/dist/lib/devices/gateway/ctrl_ln2.js.map +1 -0
  73. package/dist/lib/devices/gateway/ctrl_neutral1.js +37 -0
  74. package/dist/lib/devices/gateway/ctrl_neutral1.js.map +1 -0
  75. package/dist/lib/devices/gateway/ctrl_neutral2.js +45 -0
  76. package/dist/lib/devices/gateway/ctrl_neutral2.js.map +1 -0
  77. package/dist/lib/devices/gateway/cube.js +49 -0
  78. package/dist/lib/devices/gateway/cube.js.map +1 -0
  79. package/dist/lib/devices/gateway/developer-api.js +104 -0
  80. package/dist/lib/devices/gateway/developer-api.js.map +1 -0
  81. package/dist/lib/devices/gateway/light-channel.js +24 -0
  82. package/dist/lib/devices/gateway/light-channel.js.map +1 -0
  83. package/dist/lib/devices/gateway/light-mixin.js +59 -0
  84. package/dist/lib/devices/gateway/light-mixin.js.map +1 -0
  85. package/dist/lib/devices/gateway/magnet.js +23 -0
  86. package/dist/lib/devices/gateway/magnet.js.map +1 -0
  87. package/dist/lib/devices/gateway/magnet2.js +9 -0
  88. package/dist/lib/devices/gateway/magnet2.js.map +1 -0
  89. package/dist/lib/devices/gateway/motion.js +21 -0
  90. package/dist/lib/devices/gateway/motion.js.map +1 -0
  91. package/dist/lib/devices/gateway/motion2.js +25 -0
  92. package/dist/lib/devices/gateway/motion2.js.map +1 -0
  93. package/dist/lib/devices/gateway/plug.js +34 -0
  94. package/dist/lib/devices/gateway/plug.js.map +1 -0
  95. package/dist/lib/devices/gateway/sensor_ht.js +13 -0
  96. package/dist/lib/devices/gateway/sensor_ht.js.map +1 -0
  97. package/dist/lib/devices/gateway/subdevice.js +203 -0
  98. package/dist/lib/devices/gateway/subdevice.js.map +1 -0
  99. package/dist/lib/devices/gateway/subdevices.js +33 -0
  100. package/dist/lib/devices/gateway/subdevices.js.map +1 -0
  101. package/dist/lib/devices/gateway/switch.js +24 -0
  102. package/dist/lib/devices/gateway/switch.js.map +1 -0
  103. package/dist/lib/devices/gateway/switch2.js +19 -0
  104. package/dist/lib/devices/gateway/switch2.js.map +1 -0
  105. package/dist/lib/devices/gateway/voltage.js +21 -0
  106. package/dist/lib/devices/gateway/voltage.js.map +1 -0
  107. package/dist/lib/devices/gateway/weather.js +16 -0
  108. package/dist/lib/devices/gateway/weather.js.map +1 -0
  109. package/dist/lib/devices/gateway.js +212 -0
  110. package/dist/lib/devices/gateway.js.map +1 -0
  111. package/dist/lib/devices/humidifier.js +141 -0
  112. package/dist/lib/devices/humidifier.js.map +1 -0
  113. package/dist/lib/devices/philips-light-bulb.js +63 -0
  114. package/dist/lib/devices/philips-light-bulb.js.map +1 -0
  115. package/dist/lib/devices/power-plug.js +22 -0
  116. package/dist/lib/devices/power-plug.js.map +1 -0
  117. package/dist/lib/devices/power-strip.js +27 -0
  118. package/dist/lib/devices/power-strip.js.map +1 -0
  119. package/dist/lib/devices/vacuums/dreamevacuum.js +312 -0
  120. package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -0
  121. package/dist/lib/devices/vacuums/mijiavacuum.js +21 -0
  122. package/dist/lib/devices/vacuums/mijiavacuum.js.map +1 -0
  123. package/dist/lib/devices/vacuums/miot-vacuum.js +444 -0
  124. package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -0
  125. package/dist/lib/devices/vacuums/vacuum.js +669 -0
  126. package/dist/lib/devices/vacuums/vacuum.js.map +1 -0
  127. package/dist/lib/devices/vacuums/vacuum_modes.js +171 -0
  128. package/dist/lib/devices/vacuums/vacuum_modes.js.map +1 -0
  129. package/dist/lib/devices/vacuums/viomivacuum.js +222 -0
  130. package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -0
  131. package/dist/lib/devices/yeelight.color.js +5 -0
  132. package/dist/lib/devices/yeelight.color.js.map +1 -0
  133. package/dist/lib/devices/yeelight.js +242 -0
  134. package/dist/lib/devices/yeelight.js.map +1 -0
  135. package/dist/lib/devices/yeelight.mono.js +5 -0
  136. package/dist/lib/devices/yeelight.mono.js.map +1 -0
  137. package/dist/lib/discovery.js +147 -0
  138. package/dist/lib/discovery.js.map +1 -0
  139. package/dist/lib/index.js +89 -0
  140. package/dist/lib/index.js.map +1 -0
  141. package/dist/lib/info_from_hostname.js +27 -0
  142. package/dist/lib/info_from_hostname.js.map +1 -0
  143. package/dist/lib/management.js +101 -0
  144. package/dist/lib/management.js.map +1 -0
  145. package/dist/lib/miio_error.js +23 -0
  146. package/dist/lib/miio_error.js.map +1 -0
  147. package/dist/lib/miot/miot_api.js +73 -0
  148. package/dist/lib/miot/miot_api.js.map +1 -0
  149. package/dist/lib/miot/miot_spec.js +105 -0
  150. package/dist/lib/miot/miot_spec.js.map +1 -0
  151. package/dist/lib/miot/spec_client.js +290 -0
  152. package/dist/lib/miot/spec_client.js.map +1 -0
  153. package/dist/lib/models.js +69 -0
  154. package/dist/lib/models.js.map +1 -0
  155. package/dist/lib/network.js +194 -0
  156. package/dist/lib/network.js.map +1 -0
  157. package/dist/lib/packet.js +177 -0
  158. package/dist/lib/packet.js.map +1 -0
  159. package/dist/lib/placeholder.js +16 -0
  160. package/dist/lib/placeholder.js.map +1 -0
  161. package/dist/lib/protocol.js +3 -0
  162. package/dist/lib/protocol.js.map +1 -0
  163. package/dist/lib/safeish_json.js +22 -0
  164. package/dist/lib/safeish_json.js.map +1 -0
  165. package/dist/lib/tokens.js +30 -0
  166. package/dist/lib/tokens.js.map +1 -0
  167. package/docs/devices/vacuum.md +63 -3
  168. package/example.js +1 -1
  169. package/package.json +49 -16
  170. package/snapshots/vacuum-specs.json.gz +0 -0
  171. package/.editorconfig +0 -26
  172. package/.eslintrc +0 -32
  173. package/.github/release.yml +0 -20
  174. package/.github/workflows/build.yml +0 -50
  175. package/.github/workflows/codecov.yml +0 -35
  176. package/.github/workflows/codeql.yml +0 -24
  177. package/.github/workflows/publish-dev-from-main.yml +0 -92
  178. package/.github/workflows/publish-release-to-npm.yml +0 -45
  179. package/cli/commands/configure.js +0 -69
  180. package/cli/commands/control.js +0 -54
  181. package/cli/commands/discover.js +0 -36
  182. package/cli/commands/inspect.js +0 -197
  183. package/cli/commands/protocol/call.js +0 -66
  184. package/cli/commands/protocol/json-dump.js +0 -52
  185. package/cli/commands/protocol/packet.js +0 -29
  186. package/cli/commands/protocol.js +0 -8
  187. package/cli/commands/tokens/update.js +0 -58
  188. package/cli/commands/tokens.js +0 -8
  189. package/cli/device-finder.js +0 -69
  190. package/cli/index.js +0 -9
  191. package/cli/log.js +0 -89
  192. package/lib/checkResult.js +0 -13
  193. package/lib/connectToDevice.js +0 -66
  194. package/lib/device.js +0 -290
  195. package/lib/device_info.js +0 -329
  196. package/lib/device_info.test.js +0 -337
  197. package/lib/devices/air-monitor.js +0 -53
  198. package/lib/devices/air-purifier.js +0 -162
  199. package/lib/devices/capabilities/battery-level.js +0 -16
  200. package/lib/devices/capabilities/buzzer.js +0 -78
  201. package/lib/devices/capabilities/changeable-led-brightness.js +0 -48
  202. package/lib/devices/capabilities/colorable.js +0 -14
  203. package/lib/devices/capabilities/dimmable.js +0 -14
  204. package/lib/devices/capabilities/mode.js +0 -13
  205. package/lib/devices/capabilities/power.js +0 -14
  206. package/lib/devices/capabilities/sensor.js +0 -50
  207. package/lib/devices/capabilities/switchable-led.js +0 -49
  208. package/lib/devices/chuangmi.plug.v1.js +0 -61
  209. package/lib/devices/eyecare-lamp2.js +0 -179
  210. package/lib/devices/gateway/86sw1.js +0 -28
  211. package/lib/devices/gateway/86sw2.js +0 -44
  212. package/lib/devices/gateway/ctrl_ln1.js +0 -44
  213. package/lib/devices/gateway/ctrl_ln2.js +0 -53
  214. package/lib/devices/gateway/ctrl_neutral1.js +0 -44
  215. package/lib/devices/gateway/ctrl_neutral2.js +0 -53
  216. package/lib/devices/gateway/cube.js +0 -55
  217. package/lib/devices/gateway/developer-api.js +0 -120
  218. package/lib/devices/gateway/light-channel.js +0 -32
  219. package/lib/devices/gateway/light-mixin.js +0 -71
  220. package/lib/devices/gateway/magnet.js +0 -29
  221. package/lib/devices/gateway/magnet2.js +0 -13
  222. package/lib/devices/gateway/motion.js +0 -27
  223. package/lib/devices/gateway/motion2.js +0 -31
  224. package/lib/devices/gateway/plug.js +0 -45
  225. package/lib/devices/gateway/sensor_ht.js +0 -17
  226. package/lib/devices/gateway/subdevice.js +0 -227
  227. package/lib/devices/gateway/subdevices.js +0 -37
  228. package/lib/devices/gateway/switch.js +0 -29
  229. package/lib/devices/gateway/switch2.js +0 -27
  230. package/lib/devices/gateway/voltage.js +0 -28
  231. package/lib/devices/gateway/weather.js +0 -22
  232. package/lib/devices/gateway.js +0 -244
  233. package/lib/devices/humidifier.js +0 -162
  234. package/lib/devices/philips-light-bulb.js +0 -73
  235. package/lib/devices/power-plug.js +0 -26
  236. package/lib/devices/power-strip.js +0 -38
  237. package/lib/devices/vacuums/dreamevacuum.js +0 -350
  238. package/lib/devices/vacuums/mijiavacuum.js +0 -22
  239. package/lib/devices/vacuums/vacuum.js +0 -518
  240. package/lib/devices/vacuums/viomivacuum.js +0 -250
  241. package/lib/devices/yeelight.color.js +0 -6
  242. package/lib/devices/yeelight.js +0 -286
  243. package/lib/devices/yeelight.mono.js +0 -9
  244. package/lib/discovery.js +0 -192
  245. package/lib/index.js +0 -40
  246. package/lib/infoFromHostname.js +0 -24
  247. package/lib/management.js +0 -102
  248. package/lib/models.js +0 -76
  249. package/lib/network.js +0 -234
  250. package/lib/packet.js +0 -191
  251. package/lib/placeholder.js +0 -12
  252. package/lib/safeishJSON.js +0 -14
  253. package/lib/tokens.js +0 -129
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing } = require('abstract-things');
4
- const { Colorable } = require('abstract-things/lights');
5
-
6
- module.exports = Thing.mixin(Parent => class extends Parent.with(Colorable) {
7
- propertyUpdated(key, value) {
8
- if(key === 'color') {
9
- this.updateColor(value);
10
- }
11
-
12
- super.propertyUpdated(key, value);
13
- }
14
- });
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing } = require('abstract-things');
4
- const { Dimmable } = require('abstract-things/lights');
5
-
6
- module.exports = Thing.mixin(Parent => class extends Parent.with(Dimmable) {
7
- propertyUpdated(key, value) {
8
- if(key === 'brightness') {
9
- this.updateBrightness(value);
10
- }
11
-
12
- super.propertyUpdated(key, value);
13
- }
14
- });
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing, SwitchableMode } = require('abstract-things');
4
-
5
- module.exports = Thing.mixin(Parent => class extends Parent.with(SwitchableMode) {
6
- propertyUpdated(key, value) {
7
- if(key === 'mode') {
8
- this.updateMode(value);
9
- }
10
-
11
- super.propertyUpdated(key, value);
12
- }
13
- });
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing, SwitchablePower } = require('abstract-things');
4
-
5
- module.exports = Thing.mixin(Parent => class extends Parent.with(SwitchablePower) {
6
- propertyUpdated(key, value) {
7
- if(key === 'power' && value !== undefined) {
8
- this.updatePower(value);
9
- }
10
-
11
- super.propertyUpdated(key, value);
12
- }
13
- });
14
-
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing } = require('abstract-things');
4
- const {
5
- Temperature,
6
- RelativeHumidity,
7
- PM2_5,
8
- Illuminance,
9
- AtmosphericPressure,
10
- PowerLoad,
11
- PowerConsumed
12
- } = require('abstract-things/sensors');
13
-
14
- function bind(Type, updateName, property) {
15
- return Thing.mixin(Parent => class extends Parent.with(Type) {
16
- propertyUpdated(key, value) {
17
- if(key === property) {
18
- this[updateName](value);
19
- }
20
-
21
- super.propertyUpdated(key, value);
22
- }
23
- });
24
- }
25
-
26
- module.exports.Temperature = bind(Temperature, 'updateTemperature', 'temperature');
27
- module.exports.Humidity = bind(RelativeHumidity, 'updateRelativeHumidity', 'humidity');
28
- module.exports.Illuminance = bind(Illuminance, 'updateIlluminance', 'illuminance');
29
- module.exports.AQI = bind(PM2_5, 'updatePM2_5', 'aqi');
30
- module.exports.AtmosphericPressure = bind(AtmosphericPressure, 'updateAtmosphericPressure', 'atmosphericPressure');
31
- module.exports.PowerLoad = bind(PowerLoad, 'updatePowerLoad', 'powerLoad');
32
- module.exports.PowerConsumed = bind(PowerConsumed, 'updatePowerConsumed', 'poweConsumed');
33
-
34
- /**
35
- * Setup sensor support for a device.
36
- */
37
- function mixin(device, options) {
38
- if(device.capabilities.indexOf('sensor') < 0) {
39
- device.capabilities.push('sensor');
40
- }
41
-
42
- device.capabilities.push(options.name);
43
- Object.defineProperty(device, options.name, {
44
- get: function() {
45
- return this.property(options.name);
46
- }
47
- });
48
- }
49
-
50
- module.exports.extend = mixin;
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing, State } = require('abstract-things');
4
- const { boolean } = require('abstract-things/values');
5
-
6
- module.exports = Thing.mixin(Parent => class extends Parent.with(State) {
7
- static get capability() {
8
- return 'miio:switchable-led';
9
- }
10
-
11
- static availableAPI(builder) {
12
- builder.action('led')
13
- .description('Get or set if the LED should be used')
14
- .argument('boolean', true, 'If provided, set the LED power to this value')
15
- .returns('boolean', 'If the LED is on')
16
- .done();
17
- }
18
-
19
- propertyUpdated(key, value) {
20
- if(key === 'led') {
21
- this.updateState('led', value);
22
- }
23
-
24
- super.propertyUpdated(key, value);
25
- }
26
-
27
- /**
28
- * Get or set if the LED should be on.
29
- *
30
- * @param {boolean} power Optional power to set LED to
31
- */
32
- led(power) {
33
- if(typeof power === 'undefined') {
34
- return this.getState('led');
35
- }
36
-
37
- power = boolean(power);
38
- return this.changeLED(power)
39
- .then(() => this.getState('led'));
40
- }
41
-
42
- /**
43
- * Set if the LED should be on when the device is running.
44
- */
45
- changeLED(power) {
46
- return this.call('set_led', [ power ? 'on' : 'off' ], { refresh: [ 'led' ] })
47
- .then(() => null);
48
- }
49
- });
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- const { Thing, SwitchablePower } = require('abstract-things');
4
- const { PowerPlug, PowerOutlet } = require('abstract-things/electrical');
5
-
6
- const MiioApi = require('../device');
7
- const MiioPower = require('./capabilities/power');
8
-
9
- module.exports = class extends Thing.with(PowerPlug, PowerOutlet, MiioApi, MiioPower) {
10
- static get type() {
11
- return 'miio:power-plug';
12
- }
13
-
14
- constructor(options) {
15
- super(options);
16
-
17
- this.defineProperty('on', {
18
- name: 'power'
19
- });
20
-
21
- this.addChild(new USBOutlet(this));
22
- }
23
-
24
- setName(name) {
25
- return super.setName(name)
26
- .then(n => {
27
- this.child('usb').updateName();
28
- return n;
29
- });
30
- }
31
-
32
- propertyUpdated(key, value) {
33
- switch(key) {
34
- case 'powerChannelUsb':
35
- this.child('usb').updatePower(value);
36
- break;
37
- }
38
- }
39
- };
40
-
41
- class USBOutlet extends PowerOutlet.with(SwitchablePower) {
42
-
43
- constructor(parent) {
44
- super();
45
-
46
- this.id = parent.id + ':usb';
47
-
48
- this.parent = parent;
49
-
50
- this.updateName();
51
- }
52
-
53
- updateName() {
54
- this.metadata.name = this.parent.name + ' - USB';
55
- }
56
-
57
- changePower(power) {
58
- return this.parent.call(power ? 'set_usb_on' : 'set_usb_off', [], { refresh: true });
59
- }
60
-
61
- }
@@ -1,179 +0,0 @@
1
- 'use strict';
2
-
3
- const MiioApi = require('../device');
4
-
5
- const { Children } = require('abstract-things');
6
- const { Light, Dimmable, SwitchablePower } = require('abstract-things/lights');
7
- const { percentage } = require('abstract-things/values');
8
-
9
- const MiioDimmable = require('./capabilities/dimmable');
10
- const MiioPower = require('./capabilities/power');
11
-
12
- module.exports = class EyecareLamp2 extends Light
13
- .with(MiioPower, MiioDimmable, Children, MiioApi)
14
- {
15
-
16
- constructor(options) {
17
- super(options);
18
-
19
- this.defineProperty('power', {
20
- name: 'power',
21
- mapper: v => v === 'on'
22
- });
23
-
24
- this.defineProperty('bright', {
25
- name: 'brightness',
26
- mapper: parseInt
27
- });
28
-
29
- // Get if the
30
- this.defineProperty('notifystatus', {
31
- name: 'notifyStatus',
32
- mapper: v => v === 'on'
33
- });
34
-
35
- // Power of the secondary light
36
- this.defineProperty('ambstatus', {
37
- name: 'ambientPower',
38
- mapper: v => v === 'on'
39
- });
40
-
41
- // Brightness of the secondary light
42
- this.defineProperty('ambvalue', {
43
- name: 'ambientBrightness',
44
- mapper: parseInt
45
- });
46
-
47
- // If the main light is on
48
- this.defineProperty('eyecare', {
49
- name: 'eyeCare',
50
- mapper: v => v === 'on'
51
- });
52
-
53
- // The current user-defined scene
54
- this.defineProperty('scene_num', {
55
- name: 'userScene',
56
- mapper: v => {
57
- switch (v) {
58
- case 1:
59
- return 'study';
60
- case 2:
61
- return 'reading';
62
- case 3:
63
- return 'phone';
64
- }
65
- }
66
- });
67
-
68
- this.setModes([ 'study', 'reading', 'phone' ]);
69
-
70
- this.defineProperty('bls', {
71
- name: 'bls',
72
- mapper: v => v === 'on'
73
- });
74
-
75
- this.defineProperty('dvalue', {
76
- name: 'dvalue',
77
- mapper: parseInt
78
- });
79
-
80
- this.ambient = new AmbientLight(this);
81
- this.addChild(this.ambient);
82
- }
83
-
84
- changePower(power) {
85
- return this.call('set_power', [power ? 'on' : 'off'], {
86
- refresh: true
87
- });
88
- }
89
-
90
- changeBrightness(brightness) {
91
- return this.call('set_bright', [ brightness ], {
92
- refresh: true
93
- }).then(MiioApi.checkOk);
94
- }
95
-
96
- /**
97
- * Is eyeCare active?
98
- */
99
- eyeCare() {
100
- return Promise.resolve(this.property('eyeCare'));
101
- }
102
-
103
- /**
104
- * Enable the eyeCare
105
- */
106
- setEyeCare(enable) {
107
- return this.call('set_eyecare', [enable ? 'on' : 'off'], {
108
- refresh: true
109
- })
110
- .then(() => null);
111
- }
112
-
113
- /**
114
- * Set the current eyeCare mode
115
- *
116
- changeMode(mode) {
117
-
118
- switch (mode) {
119
- case 'study':
120
- mode = 1;
121
- break;
122
- case 'reading':
123
- mode = 2;
124
- break;
125
- case 'phone':
126
- mode = 3;
127
- break;
128
- default:
129
- return Promise.reject(new Error('Invalid EyeCare Mode: ' + mode));
130
- }
131
- return this.call('set_user_scene', [mode], {
132
- refresh: true
133
- });
134
- }
135
- */
136
-
137
- setAmbientPower(power) {
138
- return this.call.send('enable_amb', [ power ? 'on' : 'off' ])
139
- .then(MiioApi.checkOk);
140
- }
141
-
142
- setAmbientBrightness(brightness) {
143
- brightness = percentage(brightness, { min: 0, max: 100 });
144
-
145
- return this.call.send('set_amb_bright', [ brightness ])
146
- .then(MiioApi.checkOk);
147
- }
148
-
149
- propertyUpdated(key, value) {
150
- super.propertyUpdated(key, value);
151
-
152
- switch(key) {
153
- case 'ambientPower':
154
- this.ambient.updatePower(value);
155
- break;
156
- case 'ambientBrightness':
157
- this.ambient.updateBrightness(value);
158
- break;
159
- }
160
- }
161
- };
162
-
163
- class AmbientLight extends Light.with(Dimmable, SwitchablePower) {
164
-
165
- constructor(parent) {
166
- super();
167
-
168
- this.parent = parent;
169
- this.id = parent.id + ':ambient';
170
- }
171
-
172
- changePower(power) {
173
- return this.parent.setAmbientPower(power);
174
- }
175
-
176
- changeBrightness(brightness) {
177
- return this.parent.setAmbientBrightness(brightness);
178
- }
179
- }
@@ -1,28 +0,0 @@
1
- 'use strict';
2
-
3
- const SubDevice = require('./subdevice');
4
- const { WallController, Actions } = require('abstract-things/controllers');
5
-
6
- module.exports = class Switch1 extends SubDevice.with(WallController, Actions) {
7
- constructor(parent, info) {
8
- super(parent, info);
9
-
10
- this.type = 'controller';
11
- this.miioModel = 'lumi.86sw1';
12
-
13
- this.updateActions([
14
- 'click',
15
- 'double_click'
16
- ]);
17
- }
18
-
19
- _report(data) {
20
- super._report(data);
21
-
22
- if(typeof data['channel_0'] !== 'undefined') {
23
- const action = data['channel_0'];
24
- this.debug('Action performed:', action);
25
- this.emitAction(action);
26
- }
27
- }
28
- };
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- const SubDevice = require('./subdevice');
4
- const { WallController, Actions } = require('abstract-things/controllers');
5
-
6
- module.exports = class Switch2 extends SubDevice.with(WallController, Actions) {
7
- constructor(parent, info) {
8
- super(parent, info);
9
-
10
- this.type = 'controller';
11
- this.miioModel = 'lumi.86sw2';
12
-
13
- this.updateActions([
14
- 'btn0-click',
15
- 'btn0-double_click',
16
- 'btn1-click',
17
- 'btn1-double_click',
18
- 'both_click'
19
- ]);
20
- }
21
-
22
- _report(data) {
23
- super._report(data);
24
-
25
- if(typeof data['channel_0'] !== 'undefined') {
26
- const action = 'btn0-' + data['channel_0'];
27
- this.debug('Action performed:', action);
28
- this.emitAction(action);
29
- }
30
-
31
- if(typeof data['channel_1'] !== 'undefined') {
32
- const action = 'btn1-' + data['channel_1'];
33
- this.debug('Action performed:', action);
34
- this.emitAction(action);
35
- }
36
-
37
- if(typeof data['dual_channel'] !== 'undefined') {
38
- const action = data['dual_channel'];
39
-
40
- this.debug('Action performed:', action);
41
- this.emitAction(action);
42
- }
43
- }
44
- };
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- const { Children } = require('abstract-things');
4
- const { WallSwitch } = require('abstract-things/electrical');
5
-
6
- const SubDevice = require('./subdevice');
7
- const LightChannel = require('./light-channel');
8
-
9
- /**
10
- * Single-channel L-N version of light switch.
11
- */
12
- module.exports = class CtrlLN1 extends WallSwitch.with(SubDevice, Children) {
13
-
14
- static get type() {
15
- return 'miio:power-switch';
16
- }
17
-
18
- constructor(parent, info) {
19
- super(parent, info);
20
-
21
- this.miioModel = 'lumi.ctrl_ln1';
22
-
23
- this.defineProperty('channel_0', {
24
- name: 'powerChannel0',
25
- mapper: v => v === 'on'
26
- });
27
-
28
- this.addChild(new LightChannel(this, 0));
29
- }
30
-
31
- changePowerChannel(channel, power) {
32
- return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
33
- }
34
-
35
- propertyUpdated(key, value) {
36
- super.propertyUpdated(key, value);
37
-
38
- switch(key) {
39
- case 'powerChannel0':
40
- this.child('0').updatePower(value);
41
- break;
42
- }
43
- }
44
- };
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const { Children } = require('abstract-things');
4
- const { WallSwitch } = require('abstract-things/electrical');
5
-
6
- const SubDevice = require('./subdevice');
7
- const LightChannel = require('./light-channel');
8
-
9
-
10
- /**
11
- * Dual-channel L-N version of light switch.
12
- */
13
- module.exports = class CtrlLN2 extends WallSwitch.with(SubDevice, Children) {
14
-
15
- static get type() {
16
- return 'miio:power-switch';
17
- }
18
-
19
- constructor(parent, info) {
20
- super(parent, info);
21
-
22
- this.miioModel = 'lumi.ctrl_ln2';
23
-
24
- this.defineProperty('channel_0', {
25
- name: 'powerChannel0',
26
- mapper: v => v === 'on'
27
- });
28
- this.defineProperty('channel_1', {
29
- name: 'powerChannel1',
30
- mapper: v => v === 'on'
31
- });
32
-
33
- this.addChild(new LightChannel(this, 0));
34
- this.addChild(new LightChannel(this, 1));
35
- }
36
-
37
- changePowerChannel(channel, power) {
38
- return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
39
- }
40
-
41
- propertyUpdated(key, value) {
42
- super.propertyUpdated(key, value);
43
-
44
- switch(key) {
45
- case 'powerChannel0':
46
- this.child('0').updatePower(value);
47
- break;
48
- case 'powerChannel1':
49
- this.child('1').updatePower(value);
50
- break;
51
- }
52
- }
53
- };
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- const { Children } = require('abstract-things');
4
- const { WallSwitch } = require('abstract-things/electrical');
5
-
6
- const SubDevice = require('./subdevice');
7
- const LightChannel = require('./light-channel');
8
-
9
- /**
10
- * Single-channel light switch.
11
- */
12
- module.exports = class CtrlNeutral1 extends WallSwitch.with(SubDevice, Children) {
13
-
14
- static get type() {
15
- return 'miio:power-switch';
16
- }
17
-
18
- constructor(parent, info) {
19
- super(parent, info);
20
-
21
- this.miioModel = 'lumi.ctrl_neutral1';
22
-
23
- this.defineProperty('channel_0', {
24
- name: 'powerChannel0',
25
- mapper: v => v === 'on'
26
- });
27
-
28
- this.addChild(new LightChannel(this, 0));
29
- }
30
-
31
- changePowerChannel(channel, power) {
32
- return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
33
- }
34
-
35
- propertyUpdated(key, value) {
36
- super.propertyUpdated(key, value);
37
-
38
- switch(key) {
39
- case 'powerChannel0':
40
- this.child('0').updatePower(value);
41
- break;
42
- }
43
- }
44
- };
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const { Children } = require('abstract-things');
4
- const { WallSwitch } = require('abstract-things/electrical');
5
-
6
- const SubDevice = require('./subdevice');
7
- const LightChannel = require('./light-channel');
8
-
9
- /**
10
- * Dual-channel light switch.
11
- */
12
- module.exports = class CtrlNeutral2 extends WallSwitch.with(SubDevice, Children) {
13
-
14
- static get type() {
15
- return 'miio:power-switch';
16
- }
17
-
18
- constructor(parent, info) {
19
- super(parent, info);
20
-
21
- this.miioModel = 'lumi.ctrl_neutral2';
22
-
23
- this.defineProperty('channel_0', {
24
- name: 'powerChannel0',
25
- mapper: v => v === 'on'
26
- });
27
- this.defineProperty('channel_1', {
28
- name: 'powerChannel1',
29
- mapper: v => v === 'on'
30
- });
31
-
32
- this.addChild(new LightChannel(this, 0));
33
- this.addChild(new LightChannel(this, 1));
34
- }
35
-
36
- changePowerChannel(channel, power) {
37
- return this.call('toggle_ctrl_neutral', [ 'neutral_' + channel, power ? 'on' : 'off' ]);
38
- }
39
-
40
- propertyUpdated(key, value) {
41
- super.propertyUpdated(key, value);
42
-
43
- switch(key) {
44
- case 'powerChannel0':
45
- this.child('0').updatePower(value);
46
- break;
47
- case 'powerChannel1':
48
- this.child('1').updatePower(value);
49
- break;
50
- }
51
- }
52
- };
53
-