node-miio 0.0.0-dev-20250810-f1674d0

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 (104) hide show
  1. package/.editorconfig +21 -0
  2. package/.eslintrc +32 -0
  3. package/.github/workflows/build.yml +50 -0
  4. package/.github/workflows/codecov.yml +35 -0
  5. package/.github/workflows/codeql.yml +24 -0
  6. package/.github/workflows/publish-dev-from-main.yml +92 -0
  7. package/.github/workflows/publish-release-to-npm.yml +48 -0
  8. package/CONTRIBUTING.md +104 -0
  9. package/LICENSE.md +20 -0
  10. package/README.md +216 -0
  11. package/cli/commands/configure.js +69 -0
  12. package/cli/commands/control.js +54 -0
  13. package/cli/commands/discover.js +36 -0
  14. package/cli/commands/inspect.js +197 -0
  15. package/cli/commands/protocol/call.js +66 -0
  16. package/cli/commands/protocol/json-dump.js +52 -0
  17. package/cli/commands/protocol/packet.js +29 -0
  18. package/cli/commands/protocol.js +8 -0
  19. package/cli/commands/tokens/update.js +58 -0
  20. package/cli/commands/tokens.js +8 -0
  21. package/cli/device-finder.js +66 -0
  22. package/cli/index.js +9 -0
  23. package/cli/log.js +89 -0
  24. package/docs/advanced-api.md +103 -0
  25. package/docs/devices/README.md +111 -0
  26. package/docs/devices/air-purifier.md +142 -0
  27. package/docs/devices/controller.md +89 -0
  28. package/docs/devices/gateway.md +41 -0
  29. package/docs/devices/humidifier.md +136 -0
  30. package/docs/devices/light.md +141 -0
  31. package/docs/devices/power-outlet.md +56 -0
  32. package/docs/devices/power-plug.md +69 -0
  33. package/docs/devices/power-strip.md +73 -0
  34. package/docs/devices/sensor.md +74 -0
  35. package/docs/devices/vacuum.md +80 -0
  36. package/docs/devices/wall-switch.md +62 -0
  37. package/docs/management.md +109 -0
  38. package/docs/missing-devices.md +48 -0
  39. package/docs/protocol.md +77 -0
  40. package/docs/reporting-issues.md +47 -0
  41. package/example.js +11 -0
  42. package/lib/checkResult.js +13 -0
  43. package/lib/connectToDevice.js +62 -0
  44. package/lib/device.js +290 -0
  45. package/lib/device_info.js +329 -0
  46. package/lib/device_info.test.js +337 -0
  47. package/lib/devices/air-monitor.js +53 -0
  48. package/lib/devices/air-purifier.js +162 -0
  49. package/lib/devices/capabilities/battery-level.js +16 -0
  50. package/lib/devices/capabilities/buzzer.js +78 -0
  51. package/lib/devices/capabilities/changeable-led-brightness.js +48 -0
  52. package/lib/devices/capabilities/colorable.js +14 -0
  53. package/lib/devices/capabilities/dimmable.js +14 -0
  54. package/lib/devices/capabilities/mode.js +13 -0
  55. package/lib/devices/capabilities/power.js +14 -0
  56. package/lib/devices/capabilities/sensor.js +50 -0
  57. package/lib/devices/capabilities/switchable-led.js +49 -0
  58. package/lib/devices/chuangmi.plug.v1.js +61 -0
  59. package/lib/devices/eyecare-lamp2.js +179 -0
  60. package/lib/devices/gateway/86sw1.js +28 -0
  61. package/lib/devices/gateway/86sw2.js +44 -0
  62. package/lib/devices/gateway/ctrl_ln1.js +44 -0
  63. package/lib/devices/gateway/ctrl_ln2.js +53 -0
  64. package/lib/devices/gateway/ctrl_neutral1.js +44 -0
  65. package/lib/devices/gateway/ctrl_neutral2.js +53 -0
  66. package/lib/devices/gateway/cube.js +55 -0
  67. package/lib/devices/gateway/developer-api.js +120 -0
  68. package/lib/devices/gateway/light-channel.js +32 -0
  69. package/lib/devices/gateway/light-mixin.js +71 -0
  70. package/lib/devices/gateway/magnet.js +29 -0
  71. package/lib/devices/gateway/magnet2.js +13 -0
  72. package/lib/devices/gateway/motion.js +27 -0
  73. package/lib/devices/gateway/motion2.js +31 -0
  74. package/lib/devices/gateway/plug.js +45 -0
  75. package/lib/devices/gateway/sensor_ht.js +17 -0
  76. package/lib/devices/gateway/subdevice.js +227 -0
  77. package/lib/devices/gateway/subdevices.js +37 -0
  78. package/lib/devices/gateway/switch.js +29 -0
  79. package/lib/devices/gateway/switch2.js +27 -0
  80. package/lib/devices/gateway/voltage.js +28 -0
  81. package/lib/devices/gateway/weather.js +22 -0
  82. package/lib/devices/gateway.js +244 -0
  83. package/lib/devices/humidifier.js +162 -0
  84. package/lib/devices/mijiavacuum.js +22 -0
  85. package/lib/devices/philips-light-bulb.js +73 -0
  86. package/lib/devices/power-plug.js +26 -0
  87. package/lib/devices/power-strip.js +38 -0
  88. package/lib/devices/vacuum.js +412 -0
  89. package/lib/devices/viomivacuum.js +250 -0
  90. package/lib/devices/yeelight.color.js +6 -0
  91. package/lib/devices/yeelight.js +286 -0
  92. package/lib/devices/yeelight.mono.js +9 -0
  93. package/lib/discovery.js +192 -0
  94. package/lib/index.js +40 -0
  95. package/lib/infoFromHostname.js +24 -0
  96. package/lib/management.js +102 -0
  97. package/lib/models.js +77 -0
  98. package/lib/network.js +234 -0
  99. package/lib/packet.js +191 -0
  100. package/lib/placeholder.js +12 -0
  101. package/lib/safeishJSON.js +14 -0
  102. package/lib/tokens.js +129 -0
  103. package/npm-shrinkwrap.json +853 -0
  104. package/package.json +40 -0
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ const { Thing } = require('abstract-things');
4
+ const { Light, SwitchablePower, Dimmable, Colorable } = require('abstract-things/lights');
5
+ const { color } = require('abstract-things/values');
6
+
7
+ /**
8
+ * Capability that register the
9
+ */
10
+ module.exports = Thing.mixin(Appliance => class extends Appliance {
11
+ initCallback() {
12
+ this.addExtraChild(new GatewayLight(this));
13
+
14
+ return super.initCallback();
15
+ }
16
+ });
17
+
18
+ /**
19
+ * Capability that is mixed in if a gateway is also a light.
20
+ */
21
+ const GatewayLight = class extends Light.with(SwitchablePower, Dimmable, Colorable) {
22
+ static get types() {
23
+ return [ 'miio:subdevice', 'miio:gateway-light' ];
24
+ }
25
+
26
+ constructor(gateway) {
27
+ super();
28
+
29
+ this.model = gateway.miioModel + '.light';
30
+ this.internalId = gateway.id.substring(5) + ':light';
31
+ this.id = gateway.id + ':light';
32
+ this.gateway = gateway;
33
+
34
+ // Hijack the property updated event to make control easier
35
+ const propertyUpdated = this.gateway.propertyUpdated;
36
+ this.gateway.propertyUpdated = (key, value, oldValue) => {
37
+ propertyUpdated.call(this.gateway, key, value, oldValue);
38
+
39
+ this.propertyUpdated(key, value);
40
+ };
41
+ }
42
+
43
+ changePower(power) {
44
+ return this.changeBrightness(power ? 50 : 0);
45
+ }
46
+
47
+ changeBrightness(brightness, options) {
48
+ const color = this.gateway.property('rgb');
49
+ const rgb = brightness << 24 | (color.red << 16) | (color.green << 8) | color.blue;
50
+
51
+ return this.gateway.call('set_rgb', [ rgb >>> 0 ], { refresh: [ 'rgb' ] });
52
+ }
53
+
54
+ changeColor(color, options) {
55
+ color = color.rgb;
56
+ const a = this.gateway.property('brightness');
57
+ const rgb = a << 24 | (color.red << 16) | (color.green << 8) | color.blue;
58
+
59
+ return this.gateway.call('set_rgb', [ rgb >>> 0 ], { refresh: [ 'rgb' ] });
60
+ }
61
+
62
+ propertyUpdated(key, value) {
63
+ if(key === 'rgb') {
64
+ this.updateColor(color.rgb(value.red, value.green, value.blue));
65
+ } else if(key === 'brightness') {
66
+ //this.updateBrightness(Math.round(value / 255 * 100));
67
+ this.updateBrightness(value);
68
+ this.updatePower(value > 0);
69
+ }
70
+ }
71
+ };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+
4
+ const SubDevice = require('./subdevice');
5
+ const { Contact } = require('abstract-things/sensors');
6
+ const Voltage = require('./voltage');
7
+
8
+ /**
9
+ * Magnet device, emits events `open` and `close` if the state changes.
10
+ */
11
+ module.exports = class Magnet extends SubDevice.with(Contact, Voltage) {
12
+ constructor(parent, info) {
13
+ super(parent, info);
14
+
15
+ this.miioModel = 'lumi.magnet';
16
+
17
+ this.defineProperty('status');
18
+ }
19
+
20
+ propertyUpdated(key, value, oldValue) {
21
+ if(key === 'status') {
22
+ // Change the contact state
23
+ const isContact = value === 'close';
24
+ this.updateContact(isContact);
25
+ }
26
+
27
+ super.propertyUpdated(key, value, oldValue);
28
+ }
29
+ };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const Magnet = require('./magnet');
4
+
5
+ module.exports = class Magnet2 extends Magnet {
6
+
7
+ constructor(...args) {
8
+ super(...args);
9
+
10
+ this.miioModel = 'lumi.magnet.aq2';
11
+ }
12
+
13
+ };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const SubDevice = require('./subdevice');
4
+ const { Motion } = require('abstract-things/sensors');
5
+ const Voltage = require('./voltage');
6
+
7
+ /**
8
+ * Motion sensing device, emits the event `motion` whenever motion is detected.
9
+ */
10
+ module.exports = class extends SubDevice.with(Motion, Voltage) {
11
+ constructor(parent, info) {
12
+ super(parent, info);
13
+
14
+ this.miioModel = 'lumi.motion';
15
+
16
+ this.updateMotion(false);
17
+
18
+ }
19
+
20
+ _report(data) {
21
+ super._report(data);
22
+
23
+ if(typeof data.status !== 'undefined' && data.status === 'motion') {
24
+ this.updateMotion(true, '1m');
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const SubDevice = require('./subdevice');
4
+ const { Motion } = require('abstract-things/sensors');
5
+ const { Illuminance } = require('../capabilities/sensor');
6
+ const Voltage = require('./voltage');
7
+
8
+ /**
9
+ * Motion sensing device, emits the event `motion` whenever motion is detected.
10
+ */
11
+ module.exports = class extends SubDevice.with(Motion, Illuminance, Voltage) {
12
+ constructor(parent, info) {
13
+ super(parent, info);
14
+
15
+ this.miioModel = 'lumi.motion.aq2';
16
+
17
+ this.defineProperty('status');
18
+
19
+ this.defineProperty('lux', {
20
+ name: 'illuminance'
21
+ });
22
+ }
23
+
24
+ _report(data) {
25
+ super._report(data);
26
+
27
+ if(typeof data.status !== 'undefined' && data.status === 'motion') {
28
+ this.updateMotion(true, '1m');
29
+ }
30
+ }
31
+ };
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+
4
+ const { PowerPlug, PowerOutlet } = require('abstract-things/electrical');
5
+
6
+ const SubDevice = require('./subdevice');
7
+ const Power = require('../capabilities/power');
8
+ const { PowerLoad, PowerConsumed } = require('../capabilities/sensor');
9
+
10
+ /**
11
+ * Wall plug. Can be turned on or off.
12
+ */
13
+ module.exports = class Plug extends SubDevice
14
+ .with(PowerPlug, PowerOutlet, Power, PowerLoad, PowerConsumed)
15
+ {
16
+
17
+ constructor(parent, info) {
18
+ super(parent, info);
19
+
20
+ this.miioModel = 'lumi.plug';
21
+
22
+ this.defineProperty('status', {
23
+ name: 'power',
24
+ mapper: v => (v === '') ? undefined : (v === 'on')
25
+ });
26
+
27
+ this.defineProperty('load_voltage', {
28
+ name: 'loadVoltage',
29
+ mapper: parseInt
30
+ });
31
+ this.defineProperty('load_power', {
32
+ name: 'powerLoad',
33
+ mapper: parseInt
34
+ });
35
+ this.defineProperty('power_consumed', {
36
+ name: 'powerConsumed',
37
+ mapper: parseFloat
38
+ });
39
+ }
40
+
41
+ changePower(power) {
42
+ return this.call('toggle_plug', [ 'neutral_0', power ? 'on' : 'off' ]);
43
+ }
44
+
45
+ };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+
4
+ const SubDevice = require('./subdevice');
5
+ const { Temperature, Humidity } = require('../capabilities/sensor');
6
+ const Voltage = require('./voltage');
7
+
8
+ module.exports = class SensorHT extends SubDevice.with(Temperature, Humidity, Voltage) {
9
+ constructor(parent, info) {
10
+ super(parent, info);
11
+
12
+ this.miioModel = 'lumi.sensor_ht';
13
+
14
+ this.defineProperty('temperature', v => v / 100.0);
15
+ this.defineProperty('humidity', v => v / 100.0);
16
+ }
17
+ };
@@ -0,0 +1,227 @@
1
+ 'use strict';
2
+
3
+ const util = require('util');
4
+ const isDeepEqual = require('deep-equal');
5
+ const { Thing } = require('abstract-things');
6
+
7
+ const IDENTITY_MAPPER = v => v;
8
+
9
+ class SubDeviceManagement {
10
+ constructor(device, parent) {
11
+ this._device = device;
12
+ this.parent = parent;
13
+ }
14
+
15
+ get token() {
16
+ return null;
17
+ }
18
+
19
+ get model() {
20
+ return this._device.miioModel;
21
+ }
22
+
23
+ info() {
24
+ const device = this._device;
25
+ return Promise.resolve({
26
+ id: device.id,
27
+ model: device.model
28
+ });
29
+ }
30
+ }
31
+
32
+ module.exports = Thing.type(Parent => class SubDevice extends Parent {
33
+ static get types() {
34
+ return [ 'miio', 'miio:subdevice' ];
35
+ }
36
+
37
+ constructor(parent, info) {
38
+ super();
39
+
40
+ this.miioModel = info.model;
41
+ this.id = info.id;
42
+
43
+ // Store the internal id by removing the `miio:` prefix
44
+ this.internalId = info.id.substring(5);
45
+
46
+ this._properties = {};
47
+ this._propertiesToMonitor = [];
48
+ this._propertyDefinitions = {};
49
+
50
+ this._parent = parent;
51
+
52
+ // Bind the _report function for use with developer API
53
+ this._report = this._report.bind(this);
54
+
55
+ this.management = new SubDeviceManagement(this, parent);
56
+ }
57
+
58
+ hasCapability(name) {
59
+ return this.capabilities.indexOf(name) >= 0;
60
+ }
61
+
62
+ initCallback() {
63
+ return super.initCallback()
64
+ .then(() => this._parent.devApi.on('properties:' + this.internalId, this._report))
65
+ .then(() => this.loadProperties());
66
+ }
67
+
68
+ destroyCallback() {
69
+ return super.destroyCallback()
70
+ .then(() => this._parent.devApi.removeListener('properties:' + this.internalId, this._report));
71
+ }
72
+
73
+ _report(data) {
74
+ this._propertiesToMonitor.forEach(key => {
75
+ const def = this._propertyDefinitions[key];
76
+ let name = key;
77
+ let value = data[key];
78
+ if(typeof value === 'undefined') return;
79
+
80
+ if(def) {
81
+ name = def.name || name;
82
+ value = def.mapper(value);
83
+ }
84
+
85
+ this.setProperty(name, value);
86
+ });
87
+
88
+ if(this._currentRead) {
89
+ this._currentRead.resolve();
90
+ this._currentRead = null;
91
+ }
92
+ }
93
+
94
+ get properties() {
95
+ return Object.assign({}, this._properties);
96
+ }
97
+
98
+ property(key) {
99
+ return this._properties[key];
100
+ }
101
+
102
+ /**
103
+ * Define a property and how the value should be mapped. All defined
104
+ * properties are monitored if #monitor() is called.
105
+ */
106
+ defineProperty(name, def) {
107
+ if(! def || typeof def.poll === 'undefined' || def.poll) {
108
+ this._propertiesToMonitor.push(name);
109
+ }
110
+
111
+ if(typeof def === 'function') {
112
+ def = {
113
+ mapper: def
114
+ };
115
+ } else if(typeof def === 'undefined') {
116
+ def = {
117
+ mapper: IDENTITY_MAPPER
118
+ };
119
+ }
120
+
121
+ if(! def.mapper) {
122
+ def.mapper = IDENTITY_MAPPER;
123
+ }
124
+
125
+ this._propertyDefinitions[name] = def;
126
+ }
127
+
128
+ setProperty(key, value) {
129
+ const oldValue = this._properties[key];
130
+
131
+ if(! isDeepEqual(oldValue, value)) {
132
+ this._properties[key] = value;
133
+ this.debug('Property', key, 'changed from', oldValue, 'to', value);
134
+
135
+ this.propertyUpdated(key, value, oldValue);
136
+ }
137
+ }
138
+
139
+ propertyUpdated(key, value, oldValue) {
140
+ }
141
+
142
+ getProperties(props=[]) {
143
+ const result = {};
144
+ props.forEach(key => {
145
+ result[key] = this._properties[key];
146
+ });
147
+ return result;
148
+ }
149
+
150
+ /**
151
+ * Stub for loadProperties to match full device.
152
+ */
153
+ loadProperties(props) {
154
+ if(this._propertiesToMonitor.length === 0) Promise.resolve();
155
+
156
+ if(this._currentRead) {
157
+ return this._currentRead.promise;
158
+ }
159
+
160
+ // Store information about the current read promise and how to resolve it
161
+ this._currentRead = {};
162
+ this._currentRead.promise = new Promise((resolve, reject) => {
163
+ // Request the read
164
+ this._parent.devApi.read(this.internalId);
165
+
166
+ // Store the resolve to be used in _report
167
+ this._currentRead.resolve = () => {
168
+ resolve(this.getProperties(props));
169
+ };
170
+
171
+ /*
172
+ * Fallback behavior, use a regular call if properties have not
173
+ * been resolved in a second.
174
+ */
175
+ setTimeout(() => {
176
+ this.debug('Read via DEV timed out, using fallback API');
177
+ this._parent.call('get_device_prop_exp', [ [ 'lumi.' + this.internalId, ...this._propertiesToMonitor ]])
178
+ .then(result => {
179
+ for(let i=0; i<result[0].length; i++) {
180
+ let name = this._propertiesToMonitor[i];
181
+ const def = this._propertyDefinitions[name];
182
+ let value = result[0][i];
183
+
184
+ name = def.name || name;
185
+ value = def.mapper(value);
186
+
187
+ this.setProperty(name, value);
188
+ }
189
+
190
+ this._currentRead.resolve();
191
+ })
192
+ .catch(err => {
193
+ this._currentRead = null;
194
+ reject(err);
195
+ });
196
+ }, 1000);
197
+ });
198
+
199
+ return this._currentRead.promise;
200
+ }
201
+
202
+ /**
203
+ * Call a method for this sub device.
204
+ */
205
+ call(method, args, options) {
206
+ if(! options) {
207
+ options = {};
208
+ }
209
+
210
+ options.sid = this.internalId;
211
+ return this._parent.call(method, args, options);
212
+ }
213
+
214
+ [util.inspect.custom](depth, options) {
215
+ if(depth === 0) {
216
+ return options.stylize('MiioDevice', 'special')
217
+ + '[' + this.miioModel + ']';
218
+ }
219
+
220
+ return options.stylize('MiioDevice', 'special')
221
+ + ' {\n'
222
+ + ' model=' + this.miioModel + ',\n'
223
+ + ' types=' + Array.from(this.metadata.types).join(', ') + ',\n'
224
+ + ' capabilities=' + Array.from(this.metadata.capabilities).join(', ')
225
+ + '\n}';
226
+ }
227
+ });
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ // Switch (button) controller
5
+ 1: require('./switch'),
6
+ // Motion sensor
7
+ 2: require('./motion'),
8
+ // Magnet sensor for doors and windows
9
+ 3: require('./magnet'),
10
+
11
+ // TODO: What is 4, 5 and 6? plug, 86sw1 and 86sw2 are left
12
+
13
+ // Light switch with two channels
14
+ 7: require('./ctrl_neutral2'),
15
+ // Cube controller
16
+ 8: require('./cube'),
17
+ // Light switch with one channel
18
+ 9: require('./ctrl_neutral1'),
19
+ // Temperature and Humidity sensor
20
+ 10: require('./sensor_ht'),
21
+ // Plug
22
+ 11: require('./plug'),
23
+
24
+ // Aqara Temperature/Humidity/Pressure sensor
25
+ 19: require('./weather'),
26
+ // Light switch (live+neutral wire version) with one channel
27
+ 20: require('./ctrl_ln1'),
28
+ // Light switch (live+neutral wire version) with two channels
29
+ 21: require('./ctrl_ln2'),
30
+
31
+ // AQ2 switch (square version)
32
+ 51: require('./switch2'),
33
+ // AQ2 motion sensor
34
+ 52: require('./motion2'),
35
+ // AQ2 manget sensor
36
+ 53: require('./magnet2')
37
+ };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const SubDevice = require('./subdevice');
4
+ const { Button, Actions } = require('abstract-things/controllers');
5
+ const Voltage = require('./voltage');
6
+
7
+ module.exports = class Switch extends SubDevice.with(Button, Actions, Voltage) {
8
+ constructor(parent, info) {
9
+ super(parent, info);
10
+
11
+ this.miioModel = 'lumi.switch';
12
+
13
+ this.updateActions([
14
+ 'click',
15
+ 'double_click',
16
+ 'long_click_press',
17
+ 'long_click_release'
18
+ ]);
19
+ }
20
+
21
+ _report(data) {
22
+ super._report(data);
23
+
24
+ if(typeof data.status !== 'undefined') {
25
+ this.debug('Action performed:', data.status);
26
+ this.emitAction(data.status);
27
+ }
28
+ }
29
+ };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const SubDevice = require('./subdevice');
4
+ const { Button, Actions } = require('abstract-things/controllers');
5
+ const Voltage = require('./voltage');
6
+
7
+ module.exports = class Switch extends SubDevice.with(Button, Actions, Voltage) {
8
+ constructor(parent, info) {
9
+ super(parent, info);
10
+
11
+ this.miioModel = 'lumi.switch.v2';
12
+
13
+ this.updateActions([
14
+ 'click',
15
+ 'double_click'
16
+ ]);
17
+ }
18
+
19
+ _report(data) {
20
+ super._report(data);
21
+
22
+ if(typeof data.status !== 'undefined') {
23
+ this.debug('Action performed:', data.status);
24
+ this.emitAction(data.status);
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ const { Thing, BatteryLevel } = require('abstract-things');
4
+
5
+ const VOLTAGE_MIN = 2800;
6
+ const VOLTAGE_MAX = 3300;
7
+
8
+ /**
9
+ * Mixin for subdevices that support reporting voltage and that can be
10
+ * transformed into a battery level.
11
+ */
12
+ module.exports = Thing.mixin(Parent => class extends Parent.with(BatteryLevel) {
13
+
14
+ constructor(...args) {
15
+ super(...args);
16
+
17
+ this.defineProperty('voltage');
18
+ }
19
+
20
+ propertyUpdated(key, value, oldValue) {
21
+ if(key === 'voltage' && value) {
22
+ this.updateBatteryLevel(Number((value - VOLTAGE_MIN) / (VOLTAGE_MAX - VOLTAGE_MIN) * 100).toFixed(2));
23
+ }
24
+
25
+ super.propertyUpdated(key, value, oldValue);
26
+ }
27
+
28
+ });
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+
4
+ const SubDevice = require('./subdevice');
5
+ const { Temperature, Humidity, AtmosphericPressure } = require('../capabilities/sensor');
6
+ const Voltage = require('./voltage');
7
+
8
+ module.exports = class WeatherSensor extends SubDevice
9
+ .with(Temperature, Humidity, AtmosphericPressure, Voltage)
10
+ {
11
+ constructor(parent, info) {
12
+ super(parent, info);
13
+
14
+ this.miioModel = 'lumi.weather';
15
+
16
+ this.defineProperty('temperature', v => v / 100.0);
17
+ this.defineProperty('humidity', v => v / 100.0);
18
+ this.defineProperty('pressure', {
19
+ name: 'atmosphericPressure'
20
+ });
21
+ }
22
+ };