yoto-nodejs-client 0.0.2 → 0.0.3
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.
- package/README.md +523 -30
- package/bin/auth.js +36 -46
- package/bin/content.js +0 -0
- package/bin/device-model.d.ts +3 -0
- package/bin/device-model.d.ts.map +1 -0
- package/bin/device-model.js +360 -0
- package/bin/device-tui.TODO.md +125 -0
- package/bin/device-tui.d.ts +31 -0
- package/bin/device-tui.d.ts.map +1 -0
- package/bin/device-tui.js +1123 -0
- package/bin/devices.js +166 -28
- package/bin/groups.js +0 -0
- package/bin/icons.js +0 -0
- package/bin/lib/cli-helpers.d.ts +1 -1
- package/bin/lib/cli-helpers.d.ts.map +1 -1
- package/bin/lib/cli-helpers.js +5 -5
- package/bin/refresh-token.js +6 -6
- package/bin/token-info.js +3 -3
- package/index.d.ts +4 -585
- package/index.d.ts.map +1 -1
- package/index.js +11 -689
- package/lib/api-client.d.ts +576 -0
- package/lib/api-client.d.ts.map +1 -0
- package/lib/api-client.js +681 -0
- package/lib/api-endpoints/auth.d.ts +199 -8
- package/lib/api-endpoints/auth.d.ts.map +1 -1
- package/lib/api-endpoints/auth.js +224 -7
- package/lib/api-endpoints/auth.test.js +54 -2
- package/lib/api-endpoints/constants.d.ts +14 -8
- package/lib/api-endpoints/constants.d.ts.map +1 -1
- package/lib/api-endpoints/constants.js +17 -10
- package/lib/api-endpoints/content.test.js +1 -1
- package/lib/api-endpoints/devices.d.ts +405 -117
- package/lib/api-endpoints/devices.d.ts.map +1 -1
- package/lib/api-endpoints/devices.js +114 -52
- package/lib/api-endpoints/devices.test.js +1 -1
- package/lib/api-endpoints/{test-helpers.d.ts → endpoint-test-helpers.d.ts} +1 -1
- package/lib/api-endpoints/endpoint-test-helpers.d.ts.map +1 -0
- package/lib/api-endpoints/family-library-groups.test.js +1 -1
- package/lib/api-endpoints/family.test.js +1 -1
- package/lib/api-endpoints/icons.test.js +1 -1
- package/lib/helpers/power-state.d.ts +53 -0
- package/lib/helpers/power-state.d.ts.map +1 -0
- package/lib/helpers/power-state.js +73 -0
- package/lib/helpers/power-state.test.js +100 -0
- package/lib/helpers/temperature.d.ts +24 -0
- package/lib/helpers/temperature.d.ts.map +1 -0
- package/lib/helpers/temperature.js +61 -0
- package/lib/helpers/temperature.test.js +58 -0
- package/lib/helpers/typed-keys.d.ts +7 -0
- package/lib/helpers/typed-keys.d.ts.map +1 -0
- package/lib/helpers/typed-keys.js +8 -0
- package/lib/mqtt/client.d.ts +348 -22
- package/lib/mqtt/client.d.ts.map +1 -1
- package/lib/mqtt/client.js +213 -31
- package/lib/mqtt/factory.d.ts +22 -4
- package/lib/mqtt/factory.d.ts.map +1 -1
- package/lib/mqtt/factory.js +27 -5
- package/lib/mqtt/mqtt.test.js +85 -28
- package/lib/mqtt/topics.d.ts +41 -13
- package/lib/mqtt/topics.d.ts.map +1 -1
- package/lib/mqtt/topics.js +54 -20
- package/lib/pkg.d.cts +9 -0
- package/lib/token.d.ts +21 -6
- package/lib/token.d.ts.map +1 -1
- package/lib/token.js +30 -23
- package/lib/yoto-account.d.ts +163 -0
- package/lib/yoto-account.d.ts.map +1 -0
- package/lib/yoto-account.js +340 -0
- package/lib/yoto-device.d.ts +656 -0
- package/lib/yoto-device.d.ts.map +1 -0
- package/lib/yoto-device.js +2850 -0
- package/package.json +22 -15
- package/lib/api-endpoints/test-helpers.d.ts.map +0 -1
- /package/lib/api-endpoints/{test-helpers.js → endpoint-test-helpers.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["devices.js"],"names":[],"mappings":"AAaA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;GAQG;AACH,uEALG;IAAyB,WAAW,EAA3B,MAAM;IACW,SAAS;IACD,cAAc;;;CAChD,GAAS,OAAO,CAAC,mBAAmB,CAAC,CAkBvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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icestatus/
|
|
64
64
|
* @typedef {Object} YotoDeviceStatusResponse
|
|
65
65
|
* @property {string} deviceId - Unique identifier of the device
|
|
66
|
-
* @property {string}
|
|
67
|
-
* @property {number}
|
|
68
|
-
* @property {number}
|
|
69
|
-
* @property {number}
|
|
70
|
-
* @property {number}
|
|
71
|
-
* @property {number}
|
|
72
|
-
* @property {0 | 1 | 2}
|
|
73
|
-
* @property {-1 | 0 | 1}
|
|
74
|
-
* @property {number}
|
|
75
|
-
* @property {string}
|
|
76
|
-
* @property {number}
|
|
77
|
-
* @property {boolean}
|
|
78
|
-
* @property {boolean}
|
|
79
|
-
* @property {boolean}
|
|
80
|
-
* @property {boolean}
|
|
81
|
-
* @property {number}
|
|
82
|
-
* @property {boolean}
|
|
83
|
-
* @property {string}
|
|
84
|
-
* @property {string}
|
|
85
|
-
* @property {number}
|
|
86
|
-
* @property {string | null}
|
|
87
|
-
* @property {0 | 1 | 2 | 3}
|
|
88
|
-
* @property {number}
|
|
89
|
-
* @property {number}
|
|
90
|
-
* @property {
|
|
91
|
-
* @property {number}
|
|
92
|
-
* @property {string}
|
|
93
|
-
* @property {number}
|
|
94
|
-
* @property {number}
|
|
95
|
-
* @property {number}
|
|
96
|
-
* @property {number}
|
|
97
|
-
* @property {number}
|
|
66
|
+
* @property {string} activeCard - Active card on the device (can be 'none')
|
|
67
|
+
* @property {number} ambientLightSensorReading - Reading from ambient light sensor
|
|
68
|
+
* @property {number} averageDownloadSpeedBytesSecond - Average download speed in bytes per second
|
|
69
|
+
* @property {number} batteryLevelPercentage - Battery level in percentage
|
|
70
|
+
* @property {number} batteryLevelPercentageRaw - Raw battery level percentage
|
|
71
|
+
* @property {number} buzzErrors - Number of buzz errors
|
|
72
|
+
* @property {0 | 1 | 2} cardInsertionState - Card insertion state from API (0=none, 1=physical, 2=remote) - converted to CardInsertionState string union in YotoDeviceStatus
|
|
73
|
+
* @property {-1 | 0 | 1} dayMode - Day mode status (-1=unknown, 0=night, 1=day)
|
|
74
|
+
* @property {number} errorsLogged - Number of errors logged
|
|
75
|
+
* @property {string} firmwareVersion - Firmware version (e.g., 'v2.23.2')
|
|
76
|
+
* @property {number} freeDiskSpaceBytes - Free disk space in bytes
|
|
77
|
+
* @property {boolean} isAudioDeviceConnected - Whether audio device is connected
|
|
78
|
+
* @property {boolean} isBackgroundDownloadActive - Whether background download is active
|
|
79
|
+
* @property {boolean} isBluetoothAudioConnected - Whether Bluetooth audio is connected
|
|
80
|
+
* @property {boolean} isCharging - Whether device is currently charging
|
|
81
|
+
* @property {number} isNfcLocked - NFC lock status
|
|
82
|
+
* @property {boolean} isOnline - Whether device is currently online
|
|
83
|
+
* @property {string} networkSsid - Network SSID device is connected to
|
|
84
|
+
* @property {string} nightlightMode - Current nightlight color (HTTP returns 'off' or '0x000000'; MQTT provides actual hex color like '0xff5733')
|
|
85
|
+
* @property {number} playingSource - Currently playing source
|
|
86
|
+
* @property {string | null} powerCapabilities - Power capabilities (e.g., '0x02')
|
|
87
|
+
* @property {0 | 1 | 2 | 3} powerSource - Power source (0=battery, 1=V2 dock, 2=USB-C, 3=Qi)
|
|
88
|
+
* @property {number} systemVolumePercentage - System/max volume in percentage (0-100, represents 0-16 hardware scale, maps to volumeMax in events)
|
|
89
|
+
* @property {number} taskWatchdogTimeoutCount - Task watchdog timeout count
|
|
90
|
+
* @property {string | number} temperatureCelcius - Temperature in Celsius (can be number or string like "0" or "notSupported") - Note: API misspells "Celsius"
|
|
91
|
+
* @property {number} totalDiskSpaceBytes - Total disk space in bytes
|
|
92
|
+
* @property {string} updatedAt - Timestamp of last update
|
|
93
|
+
* @property {number} uptime - Uptime of the device in seconds
|
|
94
|
+
* @property {number} userVolumePercentage - User volume in percentage (0-100, represents 0-16 hardware scale, maps to volume in events)
|
|
95
|
+
* @property {number} utcOffsetSeconds - UTC offset in seconds
|
|
96
|
+
* @property {number} utcTime - UTC time as Unix timestamp
|
|
97
|
+
* @property {number} wifiStrength - WiFi connection strength in decibels
|
|
98
98
|
*/
|
|
99
99
|
|
|
100
100
|
/**
|
|
@@ -152,45 +152,107 @@ export async function getDeviceStatus ({
|
|
|
152
152
|
* @property {string} releaseChannelId - Release channel identifier
|
|
153
153
|
* @property {string} releaseChannelVersion - Release channel version
|
|
154
154
|
* @property {string} fwVersion - Firmware version (undocumented)
|
|
155
|
-
* @property {
|
|
156
|
-
* @property {YotoDeviceShortcuts}
|
|
155
|
+
* @property {YotoDeviceFullStatus} status - Comprehensive device status object (undocumented)
|
|
156
|
+
* @property {YotoDeviceShortcuts} shortcuts - Button shortcuts configuration (beta feature)
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Comprehensive device status from HTTP config endpoint (undocumented)
|
|
161
|
+
* Contains both user-facing fields and low-level hardware/diagnostic data
|
|
162
|
+
* Note: Many fields are nullable when device hasn't synced settings yet
|
|
163
|
+
* @typedef {Object} YotoDeviceFullStatus
|
|
164
|
+
* @property {string} activeCard - Active card ID or 'none'
|
|
165
|
+
* @property {number | null} aliveTime - Total time device has been alive
|
|
166
|
+
* @property {number} als - Ambient light sensor reading
|
|
167
|
+
* @property {number | null} battery - Raw battery voltage
|
|
168
|
+
* @property {number} batteryLevel - Battery level percentage
|
|
169
|
+
* @property {number} batteryLevelRaw - Raw battery level percentage
|
|
170
|
+
* @property {number | null} batteryRemaining - Battery remaining time estimate
|
|
171
|
+
* @property {0 | 1} bgDownload - Background download status (0 or 1)
|
|
172
|
+
* @property {0 | 1} bluetoothHp - Bluetooth headphones enabled (0 or 1)
|
|
173
|
+
* @property {number} buzzErrors - Number of buzz errors
|
|
174
|
+
* @property {number} bytesPS - Bytes per second transfer rate
|
|
175
|
+
* @property {0 | 1 | 2} cardInserted - Card insertion state (0=none, 1=physical, 2=remote)
|
|
176
|
+
* @property {number | null} chgStatLevel - Charge state level
|
|
177
|
+
* @property {0 | 1} charging - Charging state (0 or 1)
|
|
178
|
+
* @property {-1 | 0 | 1} day - Day mode (0=night, 1=day, -1=unknown)
|
|
179
|
+
* @property {number | null} dayBright - Day brightness setting
|
|
180
|
+
* @property {number | null} dbatTimeout - DBAT timeout value
|
|
181
|
+
* @property {string} deviceId - Device unique identifier
|
|
182
|
+
* @property {number | null} dnowBrightness - Current display brightness
|
|
183
|
+
* @property {number} errorsLogged - Number of errors logged
|
|
184
|
+
* @property {any} failData - Failure data (null if none)
|
|
185
|
+
* @property {any} failReason - Failure reason (null if none)
|
|
186
|
+
* @property {number | null} free - Free memory in bytes
|
|
187
|
+
* @property {number | null} free32 - Free 32-bit memory pool
|
|
188
|
+
* @property {number} freeDisk - Free disk space in bytes
|
|
189
|
+
* @property {number | null} freeDMA - Free DMA memory
|
|
190
|
+
* @property {string} fwVersion - Firmware version
|
|
191
|
+
* @property {0 | 1} headphones - Headphones connected (0 or 1)
|
|
192
|
+
* @property {string | null} lastSeenAt - Last seen timestamp
|
|
193
|
+
* @property {number | null} missedLogs - Number of missed log entries
|
|
194
|
+
* @property {string} nfcErrs - NFC errors (e.g., 'n/a')
|
|
195
|
+
* @property {number} nfcLock - NFC lock status
|
|
196
|
+
* @property {number | null} nightBright - Night brightness setting
|
|
197
|
+
* @property {string} nightlightMode - Current nightlight color (hex color like '0xff5733' or 'off')
|
|
198
|
+
* @property {number} playingStatus - Playing status code
|
|
199
|
+
* @property {string | null} powerCaps - Power capabilities
|
|
200
|
+
* @property {0 | 1 | 2 | 3} powerSrc - Power source (0=battery, 1=V2 dock, 2=USB-C, 3=Qi)
|
|
201
|
+
* @property {number | null} qiOtp - Qi OTP value
|
|
202
|
+
* @property {string | null} sd_info - SD card information
|
|
203
|
+
* @property {string | null} shutDown - Shutdown reason ('nA' = running, 'userShutdown' = powered off, etc.)
|
|
204
|
+
* @property {number | null} shutdownTimeout - Shutdown timeout in seconds
|
|
205
|
+
* @property {string} ssid - WiFi SSID
|
|
206
|
+
* @property {number | null} statusVersion - Status version number
|
|
207
|
+
* @property {string} temp - Temperature readings (format: 'value1:value2' or 'value1:notSupported')
|
|
208
|
+
* @property {'12' | '24' | null} timeFormat - Time format ('12' or '24')
|
|
209
|
+
* @property {number} totalDisk - Total disk space in bytes
|
|
210
|
+
* @property {number} twdt - Task watchdog timeout count
|
|
211
|
+
* @property {string} updatedAt - Last update timestamp (ISO 8601)
|
|
212
|
+
* @property {number} upTime - Uptime in seconds
|
|
213
|
+
* @property {number} userVolume - User volume setting (0-100 percentage, represents 0-16 hardware scale, maps to volume in events)
|
|
214
|
+
* @property {number} utcOffset - UTC offset in seconds
|
|
215
|
+
* @property {number} utcTime - UTC time as Unix timestamp
|
|
216
|
+
* @property {number} volume - System/max volume level (0-100 percentage, represents 0-16 hardware scale, maps to volumeMax in events)
|
|
217
|
+
* @property {number | null} wifiRestarts - Number of WiFi restarts
|
|
218
|
+
* @property {number} wifiStrength - WiFi signal strength in dBm
|
|
157
219
|
*/
|
|
158
220
|
|
|
159
221
|
/**
|
|
160
222
|
* @see https://yoto.dev/api/getdeviceconfig/
|
|
161
223
|
* @typedef {Object} YotoDeviceConfig
|
|
162
|
-
* @property {string[]}
|
|
224
|
+
* @property {string[]} alarms - Array of alarm strings in comma-separated format (e.g., '1111111,1100,5WsQg,,,8')
|
|
163
225
|
* @property {string} ambientColour - Ambient light color (hex code)
|
|
164
226
|
* @property {string} bluetoothEnabled - Bluetooth enabled state ('0' or '1')
|
|
165
227
|
* @property {boolean} btHeadphonesEnabled - Bluetooth headphones enabled
|
|
166
|
-
* @property {string}
|
|
167
|
-
* @property {string} dayDisplayBrightness - Day display brightness (e.g., 'auto')
|
|
168
|
-
* @property {string} dayTime - Day mode start time (e.g., '07:
|
|
228
|
+
* @property {string} clockFace - Clock face style (e.g., 'digital-sun')
|
|
229
|
+
* @property {string} dayDisplayBrightness - Day display brightness (e.g., 'auto', '100')
|
|
230
|
+
* @property {string} dayTime - Day mode start time (e.g., '07:00')
|
|
169
231
|
* @property {string} dayYotoDaily - Day mode Yoto Daily card path
|
|
170
232
|
* @property {string} dayYotoRadio - Day mode Yoto Radio card path
|
|
171
|
-
* @property {string}
|
|
172
|
-
* @property {string}
|
|
233
|
+
* @property {string} daySoundsOff - Day sounds off setting ('0' or '1') (undocumented)
|
|
234
|
+
* @property {string} displayDimBrightness - Display dim brightness level (undocumented)
|
|
173
235
|
* @property {string} displayDimTimeout - Display dim timeout in seconds
|
|
174
236
|
* @property {boolean} headphonesVolumeLimited - Whether headphones volume is limited
|
|
175
|
-
* @property {string}
|
|
176
|
-
* @property {string}
|
|
177
|
-
* @property {string}
|
|
237
|
+
* @property {string} hourFormat - Hour format ('12' or '24') (undocumented)
|
|
238
|
+
* @property {string} logLevel - Log level (e.g., 'none') (undocumented)
|
|
239
|
+
* @property {string} locale - Device locale (e.g., 'en') (undocumented)
|
|
178
240
|
* @property {string} maxVolumeLimit - Maximum volume limit
|
|
179
241
|
* @property {string} nightAmbientColour - Night ambient light color (hex code)
|
|
180
242
|
* @property {string} nightDisplayBrightness - Night display brightness
|
|
181
243
|
* @property {string} nightMaxVolumeLimit - Night maximum volume limit
|
|
182
|
-
* @property {string} nightTime - Night mode start time (e.g., '19:
|
|
244
|
+
* @property {string} nightTime - Night mode start time (e.g., '19:20')
|
|
183
245
|
* @property {string} nightYotoDaily - Night mode Yoto Daily card path
|
|
184
|
-
* @property {string} nightYotoRadio - Night mode Yoto Radio card path
|
|
185
|
-
* @property {string}
|
|
186
|
-
* @property {boolean}
|
|
187
|
-
* @property {boolean}
|
|
246
|
+
* @property {string} nightYotoRadio - Night mode Yoto Radio card path (can be '0' for none)
|
|
247
|
+
* @property {string} nightSoundsOff - Night sounds off setting ('0' or '1') (undocumented)
|
|
248
|
+
* @property {boolean} pausePowerButton - Pause on power button press (undocumented)
|
|
249
|
+
* @property {boolean} pauseVolumeDown - Pause on volume down (undocumented)
|
|
188
250
|
* @property {boolean} repeatAll - Whether repeat all is enabled
|
|
189
|
-
* @property {boolean}
|
|
251
|
+
* @property {boolean} showDiagnostics - Show diagnostics (undocumented)
|
|
190
252
|
* @property {string} shutdownTimeout - Shutdown timeout in seconds
|
|
191
|
-
* @property {string}
|
|
192
|
-
* @property {string}
|
|
193
|
-
* @property {string}
|
|
253
|
+
* @property {string} systemVolume - System volume level (e.g., '100') (undocumented)
|
|
254
|
+
* @property {string} timezone - Timezone setting (empty string if not set) (undocumented)
|
|
255
|
+
* @property {string} volumeLevel - Volume level preset (e.g., 'safe') (undocumented)
|
|
194
256
|
*/
|
|
195
257
|
|
|
196
258
|
/**
|
|
@@ -2,7 +2,7 @@ import test from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert'
|
|
3
3
|
import { getDevices, getDeviceStatus, getDeviceConfig } from './devices.js'
|
|
4
4
|
import { YotoAPIError } from './helpers.js'
|
|
5
|
-
import { loadTestTokens, logResponse } from './test-helpers.js'
|
|
5
|
+
import { loadTestTokens, logResponse } from './endpoint-test-helpers.js'
|
|
6
6
|
|
|
7
7
|
const { accessToken } = loadTestTokens()
|
|
8
8
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-test-helpers.d.ts","sourceRoot":"","sources":["endpoint-test-helpers.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH,kCAFa;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,CAiCzE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,mCAPW,MAAM,YACN,GAAG,QASb"}
|
|
@@ -2,7 +2,7 @@ import test from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert'
|
|
3
3
|
import { getGroups, createGroup, getGroup, updateGroup, deleteGroup } from './family-library-groups.js'
|
|
4
4
|
import { YotoAPIError } from './helpers.js'
|
|
5
|
-
import { loadTestTokens, logResponse } from './test-helpers.js'
|
|
5
|
+
import { loadTestTokens, logResponse } from './endpoint-test-helpers.js'
|
|
6
6
|
|
|
7
7
|
const { accessToken } = loadTestTokens()
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import test from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert'
|
|
3
3
|
import { getFamilyImages, getAFamilyImage } from './family.js'
|
|
4
4
|
import { YotoAPIError } from './helpers.js'
|
|
5
|
-
import { loadTestTokens, logResponse } from './test-helpers.js'
|
|
5
|
+
import { loadTestTokens, logResponse } from './endpoint-test-helpers.js'
|
|
6
6
|
|
|
7
7
|
const { accessToken } = loadTestTokens()
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import test from 'node:test'
|
|
|
2
2
|
import assert from 'node:assert'
|
|
3
3
|
import { getPublicIcons, getUserIcons } from './icons.js'
|
|
4
4
|
import { YotoAPIError } from './helpers.js'
|
|
5
|
-
import { loadTestTokens, logResponse } from './test-helpers.js'
|
|
5
|
+
import { loadTestTokens, logResponse } from './endpoint-test-helpers.js'
|
|
6
6
|
|
|
7
7
|
const { accessToken } = loadTestTokens()
|
|
8
8
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Power state detection helper for Yoto device status
|
|
3
|
+
*
|
|
4
|
+
* Analyzes shutdown field and uptime to determine device power state changes
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Power state detection result
|
|
8
|
+
* @typedef {Object} PowerStateResult
|
|
9
|
+
* @property {'running' | 'shutdown' | 'startup'} state - Device power state
|
|
10
|
+
* @property {string | null} shutDownReason - Shutdown reason if state is 'shutdown'
|
|
11
|
+
* @property {number | null} upTime - Device uptime in seconds if state is 'startup'
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Detect device power state from legacy status
|
|
15
|
+
*
|
|
16
|
+
* @param {string | null | undefined} shutDown - shutDown field from legacy status
|
|
17
|
+
* @param {number | null | undefined} upTime - upTime field from legacy status in seconds
|
|
18
|
+
* @returns {PowerStateResult}
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Device running normally
|
|
22
|
+
* detectPowerState('nA', 3600)
|
|
23
|
+
* // { state: 'running', shutDownReason: null, upTime: null }
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Device just started (low uptime)
|
|
27
|
+
* detectPowerState('nA', 45)
|
|
28
|
+
* // { state: 'startup', shutDownReason: null, upTime: 45 }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Device shutting down
|
|
32
|
+
* detectPowerState('userShutdown', 3600)
|
|
33
|
+
* // { state: 'shutdown', shutDownReason: 'userShutdown', upTime: null }
|
|
34
|
+
*/
|
|
35
|
+
export function detectPowerState(shutDown: string | null | undefined, upTime: number | null | undefined): PowerStateResult;
|
|
36
|
+
/**
|
|
37
|
+
* Power state detection result
|
|
38
|
+
*/
|
|
39
|
+
export type PowerStateResult = {
|
|
40
|
+
/**
|
|
41
|
+
* - Device power state
|
|
42
|
+
*/
|
|
43
|
+
state: "running" | "shutdown" | "startup";
|
|
44
|
+
/**
|
|
45
|
+
* - Shutdown reason if state is 'shutdown'
|
|
46
|
+
*/
|
|
47
|
+
shutDownReason: string | null;
|
|
48
|
+
/**
|
|
49
|
+
* - Device uptime in seconds if state is 'startup'
|
|
50
|
+
*/
|
|
51
|
+
upTime: number | null;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=power-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"power-state.d.ts","sourceRoot":"","sources":["power-state.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,2CAnBW,MAAM,GAAG,IAAI,GAAG,SAAS,UACzB,MAAM,GAAG,IAAI,GAAG,SAAS,GACvB,gBAAgB,CAqD5B;;;;;;;;WA/Da,SAAS,GAAG,UAAU,GAAG,SAAS;;;;oBAClC,MAAM,GAAG,IAAI;;;;YACb,MAAM,GAAG,IAAI"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Power state detection helper for Yoto device status
|
|
3
|
+
*
|
|
4
|
+
* Analyzes shutdown field and uptime to determine device power state changes
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Power state detection result
|
|
9
|
+
* @typedef {Object} PowerStateResult
|
|
10
|
+
* @property {'running' | 'shutdown' | 'startup'} state - Device power state
|
|
11
|
+
* @property {string | null} shutDownReason - Shutdown reason if state is 'shutdown'
|
|
12
|
+
* @property {number | null} upTime - Device uptime in seconds if state is 'startup'
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Detect device power state from legacy status
|
|
17
|
+
*
|
|
18
|
+
* @param {string | null | undefined} shutDown - shutDown field from legacy status
|
|
19
|
+
* @param {number | null | undefined} upTime - upTime field from legacy status in seconds
|
|
20
|
+
* @returns {PowerStateResult}
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Device running normally
|
|
24
|
+
* detectPowerState('nA', 3600)
|
|
25
|
+
* // { state: 'running', shutDownReason: null, upTime: null }
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Device just started (low uptime)
|
|
29
|
+
* detectPowerState('nA', 45)
|
|
30
|
+
* // { state: 'startup', shutDownReason: null, upTime: 45 }
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Device shutting down
|
|
34
|
+
* detectPowerState('userShutdown', 3600)
|
|
35
|
+
* // { state: 'shutdown', shutDownReason: 'userShutdown', upTime: null }
|
|
36
|
+
*/
|
|
37
|
+
export function detectPowerState (shutDown, upTime) {
|
|
38
|
+
// No shutdown field - assume running
|
|
39
|
+
if (shutDown == null) {
|
|
40
|
+
return {
|
|
41
|
+
state: 'running',
|
|
42
|
+
shutDownReason: null,
|
|
43
|
+
upTime: null
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// shutDown: 'nA' means "not applicable" - device is running
|
|
48
|
+
if (shutDown === 'nA') {
|
|
49
|
+
// Low uptime indicates recent startup (< 2 minutes)
|
|
50
|
+
if (upTime != null && upTime < 120) {
|
|
51
|
+
return {
|
|
52
|
+
state: 'startup',
|
|
53
|
+
shutDownReason: null,
|
|
54
|
+
upTime
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Normal running state
|
|
59
|
+
return {
|
|
60
|
+
state: 'running',
|
|
61
|
+
shutDownReason: null,
|
|
62
|
+
upTime: null
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Any other value means device is shutting down or has shut down
|
|
67
|
+
// Examples: 'userShutdown', 'lowBattery', 'timeout', etc.
|
|
68
|
+
return {
|
|
69
|
+
state: 'shutdown',
|
|
70
|
+
shutDownReason: shutDown,
|
|
71
|
+
upTime: null
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
import { detectPowerState } from './power-state.js'
|
|
4
|
+
|
|
5
|
+
test('detectPowerState', async (t) => {
|
|
6
|
+
await t.test('should detect normal running state', () => {
|
|
7
|
+
const result = detectPowerState('nA', 3600)
|
|
8
|
+
assert.strictEqual(result.state, 'running')
|
|
9
|
+
assert.strictEqual(result.shutDownReason, null)
|
|
10
|
+
assert.strictEqual(result.upTime, null)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
await t.test('should detect startup state with low uptime', () => {
|
|
14
|
+
const result = detectPowerState('nA', 45)
|
|
15
|
+
assert.strictEqual(result.state, 'startup')
|
|
16
|
+
assert.strictEqual(result.shutDownReason, null)
|
|
17
|
+
assert.strictEqual(result.upTime, 45)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
await t.test('should detect startup at exactly 119 seconds', () => {
|
|
21
|
+
const result = detectPowerState('nA', 119)
|
|
22
|
+
assert.strictEqual(result.state, 'startup')
|
|
23
|
+
assert.strictEqual(result.upTime, 119)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
await t.test('should detect running at exactly 120 seconds (threshold)', () => {
|
|
27
|
+
const result = detectPowerState('nA', 120)
|
|
28
|
+
assert.strictEqual(result.state, 'running')
|
|
29
|
+
assert.strictEqual(result.upTime, null)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
await t.test('should detect user shutdown', () => {
|
|
33
|
+
const result = detectPowerState('userShutdown', 3600)
|
|
34
|
+
assert.strictEqual(result.state, 'shutdown')
|
|
35
|
+
assert.strictEqual(result.shutDownReason, 'userShutdown')
|
|
36
|
+
assert.strictEqual(result.upTime, null)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await t.test('should detect any non-nA value as shutdown', () => {
|
|
40
|
+
const testCases = [
|
|
41
|
+
'lowBattery',
|
|
42
|
+
'timeout',
|
|
43
|
+
'powerLoss',
|
|
44
|
+
'unknown',
|
|
45
|
+
'anyOtherValue'
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
for (const shutDownValue of testCases) {
|
|
49
|
+
const result = detectPowerState(shutDownValue, 1000)
|
|
50
|
+
assert.strictEqual(result.state, 'shutdown')
|
|
51
|
+
assert.strictEqual(result.shutDownReason, shutDownValue)
|
|
52
|
+
assert.strictEqual(result.upTime, null)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
await t.test('should handle null shutDown as running', () => {
|
|
57
|
+
const result = detectPowerState(null, 500)
|
|
58
|
+
assert.strictEqual(result.state, 'running')
|
|
59
|
+
assert.strictEqual(result.shutDownReason, null)
|
|
60
|
+
assert.strictEqual(result.upTime, null)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await t.test('should handle undefined shutDown as running', () => {
|
|
64
|
+
const result = detectPowerState(undefined, 500)
|
|
65
|
+
assert.strictEqual(result.state, 'running')
|
|
66
|
+
assert.strictEqual(result.shutDownReason, null)
|
|
67
|
+
assert.strictEqual(result.upTime, null)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
await t.test('should handle null upTime with nA', () => {
|
|
71
|
+
const result = detectPowerState('nA', null)
|
|
72
|
+
assert.strictEqual(result.state, 'running')
|
|
73
|
+
assert.strictEqual(result.upTime, null)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
await t.test('should handle undefined upTime with nA', () => {
|
|
77
|
+
const result = detectPowerState('nA', undefined)
|
|
78
|
+
assert.strictEqual(result.state, 'running')
|
|
79
|
+
assert.strictEqual(result.upTime, null)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
await t.test('should detect startup with uptime 0', () => {
|
|
83
|
+
const result = detectPowerState('nA', 0)
|
|
84
|
+
assert.strictEqual(result.state, 'startup')
|
|
85
|
+
assert.strictEqual(result.upTime, 0)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
await t.test('should detect startup with uptime 1', () => {
|
|
89
|
+
const result = detectPowerState('nA', 1)
|
|
90
|
+
assert.strictEqual(result.state, 'startup')
|
|
91
|
+
assert.strictEqual(result.upTime, 1)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
await t.test('should ignore upTime when shutting down', () => {
|
|
95
|
+
const result = detectPowerState('userShutdown', 10)
|
|
96
|
+
assert.strictEqual(result.state, 'shutdown')
|
|
97
|
+
assert.strictEqual(result.shutDownReason, 'userShutdown')
|
|
98
|
+
assert.strictEqual(result.upTime, null)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temperature parsing helper for Yoto device status
|
|
3
|
+
*
|
|
4
|
+
* Temperature field format: colon-separated string where second value (index [1]) is temperature in Celsius
|
|
5
|
+
* Examples: '0:19' → 19°C, '12:20:23' → 20°C, '0:0' → 0°C, '0:unavailable' → null
|
|
6
|
+
* Plain string format: '19' → 19°C, '0' → 0°C
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Parse temperature from Yoto status message
|
|
10
|
+
*
|
|
11
|
+
* @param {string | number | null | undefined} tempValue - Temperature value from status message
|
|
12
|
+
* @returns {number | null} Temperature in Celsius, or null if unavailable/invalid
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* parseTemperature('0:19') // 19
|
|
16
|
+
* parseTemperature('12:20:23') // 20
|
|
17
|
+
* parseTemperature('0:0') // 0
|
|
18
|
+
* parseTemperature('0:unavailable') // null
|
|
19
|
+
* parseTemperature('0') // 0
|
|
20
|
+
* parseTemperature('19') // 19
|
|
21
|
+
* parseTemperature(null) // null
|
|
22
|
+
*/
|
|
23
|
+
export function parseTemperature(tempValue: string | number | null | undefined): number | null;
|
|
24
|
+
//# sourceMappingURL=temperature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temperature.d.ts","sourceRoot":"","sources":["temperature.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AACH,4CAZW,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAChC,MAAM,GAAG,IAAI,CAgDzB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Temperature parsing helper for Yoto device status
|
|
3
|
+
*
|
|
4
|
+
* Temperature field format: colon-separated string where second value (index [1]) is temperature in Celsius
|
|
5
|
+
* Examples: '0:19' → 19°C, '12:20:23' → 20°C, '0:0' → 0°C, '0:unavailable' → null
|
|
6
|
+
* Plain string format: '19' → 19°C, '0' → 0°C
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse temperature from Yoto status message
|
|
11
|
+
*
|
|
12
|
+
* @param {string | number | null | undefined} tempValue - Temperature value from status message
|
|
13
|
+
* @returns {number | null} Temperature in Celsius, or null if unavailable/invalid
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* parseTemperature('0:19') // 19
|
|
17
|
+
* parseTemperature('12:20:23') // 20
|
|
18
|
+
* parseTemperature('0:0') // 0
|
|
19
|
+
* parseTemperature('0:unavailable') // null
|
|
20
|
+
* parseTemperature('0') // 0
|
|
21
|
+
* parseTemperature('19') // 19
|
|
22
|
+
* parseTemperature(null) // null
|
|
23
|
+
*/
|
|
24
|
+
export function parseTemperature (tempValue) {
|
|
25
|
+
// Handle null/undefined
|
|
26
|
+
if (tempValue == null) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Convert to string
|
|
31
|
+
const tempStr = String(tempValue)
|
|
32
|
+
|
|
33
|
+
// Empty string
|
|
34
|
+
if (!tempStr) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Colon-separated format (e.g., '0:19', '12:20:23', '0:unavailable')
|
|
39
|
+
if (tempStr.includes(':')) {
|
|
40
|
+
const parts = tempStr.split(':')
|
|
41
|
+
const secondValue = parts[1] ?? ''
|
|
42
|
+
|
|
43
|
+
// Parse second value as number
|
|
44
|
+
const parsed = parseFloat(secondValue)
|
|
45
|
+
|
|
46
|
+
// Return null if not a valid number (e.g., 'unavailable', 'notSupported')
|
|
47
|
+
if (isNaN(parsed)) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return parsed
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Fallback: try to parse as plain number (e.g., '19' or '0')
|
|
55
|
+
const parsed = parseFloat(tempStr)
|
|
56
|
+
if (isNaN(parsed)) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return parsed
|
|
61
|
+
}
|