meross-cli 0.1.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 (72) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +110 -0
  4. package/cli/commands/control/execute.js +23 -0
  5. package/cli/commands/control/index.js +12 -0
  6. package/cli/commands/control/menu.js +193 -0
  7. package/cli/commands/control/params/generic.js +229 -0
  8. package/cli/commands/control/params/index.js +56 -0
  9. package/cli/commands/control/params/light.js +188 -0
  10. package/cli/commands/control/params/thermostat.js +166 -0
  11. package/cli/commands/control/params/timer.js +242 -0
  12. package/cli/commands/control/params/trigger.js +206 -0
  13. package/cli/commands/dump.js +35 -0
  14. package/cli/commands/index.js +34 -0
  15. package/cli/commands/info.js +221 -0
  16. package/cli/commands/list.js +112 -0
  17. package/cli/commands/mqtt.js +187 -0
  18. package/cli/commands/sniffer/device-sniffer.js +217 -0
  19. package/cli/commands/sniffer/fake-app.js +233 -0
  20. package/cli/commands/sniffer/index.js +7 -0
  21. package/cli/commands/sniffer/message-queue.js +65 -0
  22. package/cli/commands/sniffer/sniffer-menu.js +676 -0
  23. package/cli/commands/stats.js +90 -0
  24. package/cli/commands/status/device-status.js +1403 -0
  25. package/cli/commands/status/hub-status.js +72 -0
  26. package/cli/commands/status/index.js +50 -0
  27. package/cli/commands/status/subdevices/hub-smoke-detector.js +82 -0
  28. package/cli/commands/status/subdevices/hub-temp-hum-sensor.js +43 -0
  29. package/cli/commands/status/subdevices/hub-thermostat-valve.js +83 -0
  30. package/cli/commands/status/subdevices/hub-water-leak-sensor.js +27 -0
  31. package/cli/commands/status/subdevices/index.js +23 -0
  32. package/cli/commands/test/index.js +185 -0
  33. package/cli/config/users.js +108 -0
  34. package/cli/control-registry.js +875 -0
  35. package/cli/helpers/client.js +89 -0
  36. package/cli/helpers/meross.js +106 -0
  37. package/cli/menu/index.js +10 -0
  38. package/cli/menu/main.js +648 -0
  39. package/cli/menu/settings.js +789 -0
  40. package/cli/meross-cli.js +547 -0
  41. package/cli/tests/README.md +365 -0
  42. package/cli/tests/test-alarm.js +144 -0
  43. package/cli/tests/test-child-lock.js +248 -0
  44. package/cli/tests/test-config.js +133 -0
  45. package/cli/tests/test-control.js +189 -0
  46. package/cli/tests/test-diffuser.js +505 -0
  47. package/cli/tests/test-dnd.js +246 -0
  48. package/cli/tests/test-electricity.js +209 -0
  49. package/cli/tests/test-encryption.js +281 -0
  50. package/cli/tests/test-garage.js +259 -0
  51. package/cli/tests/test-helper.js +313 -0
  52. package/cli/tests/test-hub-mts100.js +355 -0
  53. package/cli/tests/test-hub-sensors.js +489 -0
  54. package/cli/tests/test-light.js +253 -0
  55. package/cli/tests/test-presence.js +497 -0
  56. package/cli/tests/test-registry.js +419 -0
  57. package/cli/tests/test-roller-shutter.js +628 -0
  58. package/cli/tests/test-runner.js +415 -0
  59. package/cli/tests/test-runtime.js +234 -0
  60. package/cli/tests/test-screen.js +133 -0
  61. package/cli/tests/test-sensor-history.js +146 -0
  62. package/cli/tests/test-smoke-config.js +138 -0
  63. package/cli/tests/test-spray.js +131 -0
  64. package/cli/tests/test-temp-unit.js +133 -0
  65. package/cli/tests/test-template.js +238 -0
  66. package/cli/tests/test-thermostat.js +919 -0
  67. package/cli/tests/test-timer.js +372 -0
  68. package/cli/tests/test-toggle.js +342 -0
  69. package/cli/tests/test-trigger.js +279 -0
  70. package/cli/utils/display.js +86 -0
  71. package/cli/utils/terminal.js +137 -0
  72. package/package.json +53 -0
@@ -0,0 +1,253 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Light Device Tests
5
+ * Tests RGB color, brightness, and temperature control for light devices
6
+ */
7
+
8
+ const { findDevicesByAbility, waitForDeviceConnection, getDeviceName, OnlineStatus } = require('./test-helper');
9
+
10
+ const metadata = {
11
+ name: 'light',
12
+ description: 'Tests RGB color, brightness, and temperature control for light devices',
13
+ requiredAbilities: ['Appliance.Control.Light'],
14
+ minDevices: 1
15
+ };
16
+
17
+ async function runTests(context) {
18
+ const { manager, devices, options = {} } = context;
19
+ const timeout = options.timeout || 30000;
20
+ const results = [];
21
+
22
+ // If no devices provided, discover them
23
+ let lightDevices = devices || [];
24
+ if (lightDevices.length === 0) {
25
+ lightDevices = await findDevicesByAbility(manager, 'Appliance.Control.Light', OnlineStatus.ONLINE);
26
+ }
27
+
28
+ // Wait for devices to be connected and update their states
29
+ for (const device of lightDevices) {
30
+ await waitForDeviceConnection(device, timeout);
31
+ await device.getLightState();
32
+ await new Promise(resolve => setTimeout(resolve, 1000));
33
+ }
34
+
35
+ // Find RGB-capable devices
36
+ const rgbCapable = lightDevices.filter(d => d.getSupportsRgb && d.getSupportsRgb(0));
37
+
38
+ if (rgbCapable.length < 1) {
39
+ results.push({
40
+ name: 'should set RGB color',
41
+ passed: false,
42
+ skipped: true,
43
+ error: 'Could not find any RGB-capable Light device within the given set of devices',
44
+ device: null
45
+ });
46
+ return results;
47
+ }
48
+
49
+ const testLight = rgbCapable[0];
50
+ const deviceName = getDeviceName(testLight);
51
+
52
+ // Test 1: Set RGB color
53
+ try {
54
+ await testLight.getLightState();
55
+
56
+ // Set a random color
57
+ const r = Math.floor(Math.random() * 256);
58
+ const g = Math.floor(Math.random() * 256);
59
+ const b = Math.floor(Math.random() * 256);
60
+
61
+ await testLight.setLightColor({
62
+ rgb: [r, g, b],
63
+ onoff: true
64
+ });
65
+
66
+ await new Promise(resolve => setTimeout(resolve, 1000));
67
+
68
+ // Check the color property returns the set color
69
+ const color = testLight.getLightRgbColor(0);
70
+
71
+ if (!color || !Array.isArray(color) || color.length !== 3) {
72
+ results.push({
73
+ name: 'should set RGB color',
74
+ passed: false,
75
+ skipped: false,
76
+ error: `Invalid color returned: ${JSON.stringify(color)}`,
77
+ device: deviceName
78
+ });
79
+ } else if (color[0] !== r || color[1] !== g || color[2] !== b) {
80
+ results.push({
81
+ name: 'should set RGB color',
82
+ passed: false,
83
+ skipped: false,
84
+ error: `Color mismatch. Expected [${r}, ${g}, ${b}], got [${color[0]}, ${color[1]}, ${color[2]}]`,
85
+ device: deviceName
86
+ });
87
+ } else {
88
+ results.push({
89
+ name: 'should set RGB color',
90
+ passed: true,
91
+ skipped: false,
92
+ error: null,
93
+ device: deviceName,
94
+ details: { rgb: [r, g, b] }
95
+ });
96
+ }
97
+ } catch (error) {
98
+ results.push({
99
+ name: 'should set RGB color',
100
+ passed: false,
101
+ skipped: false,
102
+ error: error.message,
103
+ device: deviceName
104
+ });
105
+ }
106
+
107
+ // Test 2: Turn light on and off
108
+ try {
109
+ await testLight.getLightState();
110
+
111
+ // Turn device off
112
+ await testLight.setLightColor({
113
+ rgb: [255, 255, 255],
114
+ onoff: false
115
+ });
116
+ await new Promise(resolve => setTimeout(resolve, 1000));
117
+
118
+ // Make sure device is now off
119
+ const isOff = testLight.getLightIsOn(0);
120
+ if (isOff !== false) {
121
+ results.push({
122
+ name: 'should turn light on and off',
123
+ passed: false,
124
+ skipped: false,
125
+ error: `Device should be off but isOn returned ${isOff}`,
126
+ device: deviceName
127
+ });
128
+ return results;
129
+ }
130
+
131
+ // Set a color and turn the device on
132
+ await testLight.setLightColor({
133
+ rgb: [0, 255, 0],
134
+ onoff: true
135
+ });
136
+ await new Promise(resolve => setTimeout(resolve, 1000));
137
+
138
+ // Make sure device is now on with that specific color set
139
+ const isOn = testLight.getLightIsOn(0);
140
+ const color = testLight.getLightRgbColor(0);
141
+
142
+ if (!isOn) {
143
+ results.push({
144
+ name: 'should turn light on and off',
145
+ passed: false,
146
+ skipped: false,
147
+ error: 'Device should be on but isOn returned false',
148
+ device: deviceName
149
+ });
150
+ return results;
151
+ }
152
+
153
+ if (!color || !Array.isArray(color) || color.length !== 3 ||
154
+ color[0] !== 0 || color[1] !== 255 || color[2] !== 0) {
155
+ results.push({
156
+ name: 'should turn light on and off',
157
+ passed: false,
158
+ skipped: false,
159
+ error: `Color mismatch. Expected [0, 255, 0], got ${JSON.stringify(color)}`,
160
+ device: deviceName
161
+ });
162
+ return results;
163
+ }
164
+
165
+ // Set a color without changing the on-off state
166
+ await testLight.setLightColor({
167
+ rgb: [255, 0, 0]
168
+ });
169
+ await new Promise(resolve => setTimeout(resolve, 1000));
170
+
171
+ // Make sure device is still on and showing the specific color
172
+ const stillOn = testLight.getLightIsOn(0);
173
+ const newColor = testLight.getLightRgbColor(0);
174
+
175
+ if (!stillOn) {
176
+ results.push({
177
+ name: 'should turn light on and off',
178
+ passed: false,
179
+ skipped: false,
180
+ error: 'Device should still be on after color change',
181
+ device: deviceName
182
+ });
183
+ return results;
184
+ }
185
+
186
+ if (!newColor || !Array.isArray(newColor) || newColor.length !== 3 ||
187
+ newColor[0] !== 255 || newColor[1] !== 0 || newColor[2] !== 0) {
188
+ results.push({
189
+ name: 'should turn light on and off',
190
+ passed: false,
191
+ skipped: false,
192
+ error: `Color mismatch. Expected [255, 0, 0], got ${JSON.stringify(newColor)}`,
193
+ device: deviceName
194
+ });
195
+ return results;
196
+ }
197
+
198
+ // Turn off device without changing color
199
+ await testLight.setLightColor({
200
+ onoff: false
201
+ });
202
+ await new Promise(resolve => setTimeout(resolve, 1000));
203
+
204
+ // Make sure device is now off
205
+ const finalIsOff = testLight.getLightIsOn(0);
206
+ if (finalIsOff !== false) {
207
+ results.push({
208
+ name: 'should turn light on and off',
209
+ passed: false,
210
+ skipped: false,
211
+ error: 'Device should be off but isOn returned true',
212
+ device: deviceName
213
+ });
214
+ return results;
215
+ }
216
+
217
+ results.push({
218
+ name: 'should turn light on and off',
219
+ passed: true,
220
+ skipped: false,
221
+ error: null,
222
+ device: deviceName
223
+ });
224
+
225
+ } catch (error) {
226
+ results.push({
227
+ name: 'should turn light on and off',
228
+ passed: false,
229
+ skipped: false,
230
+ error: error.message,
231
+ device: deviceName
232
+ });
233
+ }
234
+
235
+ // Test 3: RGB Push Notification
236
+ // Note: This test requires a second MerossManager instance which is complex to set up
237
+ // For now, we'll skip this test or simplify it
238
+ results.push({
239
+ name: 'should receive push notification when RGB color changes',
240
+ passed: true,
241
+ skipped: true,
242
+ error: 'Push notification test requires second MerossManager instance - skipped for simplicity',
243
+ device: deviceName,
244
+ details: { note: 'Test can be implemented later if needed' }
245
+ });
246
+
247
+ return results;
248
+ }
249
+
250
+ module.exports = {
251
+ metadata,
252
+ runTests
253
+ };