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.
Files changed (75) hide show
  1. package/README.md +523 -30
  2. package/bin/auth.js +36 -46
  3. package/bin/content.js +0 -0
  4. package/bin/device-model.d.ts +3 -0
  5. package/bin/device-model.d.ts.map +1 -0
  6. package/bin/device-model.js +360 -0
  7. package/bin/device-tui.TODO.md +125 -0
  8. package/bin/device-tui.d.ts +31 -0
  9. package/bin/device-tui.d.ts.map +1 -0
  10. package/bin/device-tui.js +1123 -0
  11. package/bin/devices.js +166 -28
  12. package/bin/groups.js +0 -0
  13. package/bin/icons.js +0 -0
  14. package/bin/lib/cli-helpers.d.ts +1 -1
  15. package/bin/lib/cli-helpers.d.ts.map +1 -1
  16. package/bin/lib/cli-helpers.js +5 -5
  17. package/bin/refresh-token.js +6 -6
  18. package/bin/token-info.js +3 -3
  19. package/index.d.ts +4 -585
  20. package/index.d.ts.map +1 -1
  21. package/index.js +11 -689
  22. package/lib/api-client.d.ts +576 -0
  23. package/lib/api-client.d.ts.map +1 -0
  24. package/lib/api-client.js +681 -0
  25. package/lib/api-endpoints/auth.d.ts +199 -8
  26. package/lib/api-endpoints/auth.d.ts.map +1 -1
  27. package/lib/api-endpoints/auth.js +224 -7
  28. package/lib/api-endpoints/auth.test.js +54 -2
  29. package/lib/api-endpoints/constants.d.ts +14 -8
  30. package/lib/api-endpoints/constants.d.ts.map +1 -1
  31. package/lib/api-endpoints/constants.js +17 -10
  32. package/lib/api-endpoints/content.test.js +1 -1
  33. package/lib/api-endpoints/devices.d.ts +405 -117
  34. package/lib/api-endpoints/devices.d.ts.map +1 -1
  35. package/lib/api-endpoints/devices.js +114 -52
  36. package/lib/api-endpoints/devices.test.js +1 -1
  37. package/lib/api-endpoints/{test-helpers.d.ts → endpoint-test-helpers.d.ts} +1 -1
  38. package/lib/api-endpoints/endpoint-test-helpers.d.ts.map +1 -0
  39. package/lib/api-endpoints/family-library-groups.test.js +1 -1
  40. package/lib/api-endpoints/family.test.js +1 -1
  41. package/lib/api-endpoints/icons.test.js +1 -1
  42. package/lib/helpers/power-state.d.ts +53 -0
  43. package/lib/helpers/power-state.d.ts.map +1 -0
  44. package/lib/helpers/power-state.js +73 -0
  45. package/lib/helpers/power-state.test.js +100 -0
  46. package/lib/helpers/temperature.d.ts +24 -0
  47. package/lib/helpers/temperature.d.ts.map +1 -0
  48. package/lib/helpers/temperature.js +61 -0
  49. package/lib/helpers/temperature.test.js +58 -0
  50. package/lib/helpers/typed-keys.d.ts +7 -0
  51. package/lib/helpers/typed-keys.d.ts.map +1 -0
  52. package/lib/helpers/typed-keys.js +8 -0
  53. package/lib/mqtt/client.d.ts +348 -22
  54. package/lib/mqtt/client.d.ts.map +1 -1
  55. package/lib/mqtt/client.js +213 -31
  56. package/lib/mqtt/factory.d.ts +22 -4
  57. package/lib/mqtt/factory.d.ts.map +1 -1
  58. package/lib/mqtt/factory.js +27 -5
  59. package/lib/mqtt/mqtt.test.js +85 -28
  60. package/lib/mqtt/topics.d.ts +41 -13
  61. package/lib/mqtt/topics.d.ts.map +1 -1
  62. package/lib/mqtt/topics.js +54 -20
  63. package/lib/pkg.d.cts +9 -0
  64. package/lib/token.d.ts +21 -6
  65. package/lib/token.d.ts.map +1 -1
  66. package/lib/token.js +30 -23
  67. package/lib/yoto-account.d.ts +163 -0
  68. package/lib/yoto-account.d.ts.map +1 -0
  69. package/lib/yoto-account.js +340 -0
  70. package/lib/yoto-device.d.ts +656 -0
  71. package/lib/yoto-device.d.ts.map +1 -0
  72. package/lib/yoto-device.js +2850 -0
  73. package/package.json +22 -15
  74. package/lib/api-endpoints/test-helpers.d.ts.map +0 -1
  75. /package/lib/api-endpoints/{test-helpers.js → endpoint-test-helpers.js} +0 -0
@@ -0,0 +1,656 @@
1
+ /**
2
+ * Get the official name for a nightlight color
3
+ * @param {string} colorValue - Nightlight color value (hex code or 'off')
4
+ * @returns {string} Official color name or the original value if not found
5
+ */
6
+ export function getNightlightColorName(colorValue: string): string;
7
+ /**
8
+ * Power source state
9
+ * @typedef {'battery' | 'dock' | 'usb-c' | 'wireless'} PowerSource
10
+ */
11
+ /**
12
+ * Official Yoto nightlight colors
13
+ *
14
+ * Maps raw nightlight values to official color names.
15
+ */
16
+ export const NIGHTLIGHT_COLORS: {
17
+ '0x643600': string;
18
+ '0x640000': string;
19
+ '0x602d3c': string;
20
+ '0x5a6400': string;
21
+ '0x644800': string;
22
+ '0x194a55': string;
23
+ '0x646464': string;
24
+ '0x000000': string;
25
+ off: string;
26
+ };
27
+ /**
28
+ * Canonical device status - normalized format for both HTTP and MQTT sources
29
+ *
30
+ * This unified format resolves differences between HTTP and MQTT:
31
+ * - HTTP uses string booleans ('0'/'1'), MQTT uses actual booleans
32
+ * - HTTP has nullable fields, MQTT fields are non-nullable
33
+ * - Field names match YotoDeviceStatusResponse with fallback to YotoDeviceFullStatus
34
+ *
35
+ * @typedef {Object} YotoDeviceStatus
36
+ * @property {string | null} activeCardId - Active card ID or null when no card is active
37
+ * @property {number} batteryLevelPercentage - Battery level percentage (integer 0-100)
38
+ * @property {boolean} isCharging - Whether device is currently charging
39
+ * @property {boolean} isOnline - Whether device is currently online
40
+ * @property {number} volume - User volume level (0-16 scale)
41
+ * @property {number} maxVolume - Maximum volume limit (0-16 scale)
42
+ * @property {CardInsertionState} cardInsertionState - Card insertion state
43
+ * @property {DayMode} dayMode - Day mode status
44
+ * @property {PowerSource} powerSource - Power source
45
+ * @property {string} firmwareVersion - Firmware version
46
+ * @property {number} wifiStrength - WiFi signal strength in dBm
47
+ * @property {number} freeDiskSpaceBytes - Free disk space in bytes
48
+ * @property {number} totalDiskSpaceBytes - Total disk space in bytes
49
+ * @property {boolean} isAudioDeviceConnected - Whether headphones are connected
50
+ * @property {boolean} isBluetoothAudioConnected - Whether Bluetooth headphones are enabled
51
+ * @property {string} nightlightMode - Current nightlight color (6-digit hex color like '0xff5733' or 'off'). Most accurate value comes from MQTT status. HTTP endpoint returns either 'off' or '0x000000'. Note: This is the live status; configured colors are in config.ambientColour (day) and config.nightAmbientColour (night). Only available on devices with colored nightlight (v3).
52
+ * @property {string | number | null} temperatureCelsius - Temperature in Celsius (null if not supported, can be number, string "0", or "notSupported") TODO: Number or null only
53
+ * @property {number} ambientLightSensorReading - Ambient light sensor reading TODO: Figure out units
54
+ * @property {number | null} displayBrightness - Current display brightness (null when device is off) - from YotoDeviceFullStatus (dnowBrightness) TODO: Figure out units
55
+ * @property {'12' | '24' | null} timeFormat - Time format preference - from YotoDeviceFullStatus
56
+ * @property {number} uptime - Device uptime in seconds
57
+ * @property {string} updatedAt - ISO 8601 timestamp of last update
58
+ * @property {string} source - Data source ('http' or 'mqtt') - metadata field added by stateful client
59
+ */
60
+ export const YotoDeviceStatusType: {};
61
+ /**
62
+ * Playback state from MQTT events
63
+ * @typedef {Object} YotoPlaybackState
64
+ * @property {string | null} cardId - Currently playing card ID TODO: Figure out name of card
65
+ * @property {string | null} source - Playback source (e.g., 'card', 'remote', 'MQTT') TODO: Figure out what 'mqtt' source means. Card means card, remote means remotly played card.
66
+ * @property {'playing' | 'paused' | 'stopped' | 'loading' | string | null} playbackStatus - Playback status
67
+ * @property {string | null} trackTitle - Current track title
68
+ * @property {string | null} trackKey - Current track key
69
+ * @property {string | null} chapterTitle - Current chapter title
70
+ * @property {string | null} chapterKey - Current chapter key
71
+ * @property {number | null} position - Current position in seconds
72
+ * @property {number | null} trackLength - Track duration in seconds
73
+ * @property {boolean | null} streaming - Whether streaming
74
+ * @property {boolean | null} sleepTimerActive - Sleep timer active
75
+ * @property {number | null} sleepTimerSeconds - Seconds remaining on sleep timer
76
+ * @property {string} updatedAt - ISO 8601 timestamp of last update
77
+ */
78
+ export const YotoPlaybackStateType: {};
79
+ /**
80
+ * Complete device client state
81
+ * @typedef {Object} YotoDeviceClientState
82
+ * @property {YotoDevice} device - Basic device information
83
+ * @property {YotoDeviceConfig} config - Device configuration (always initialized)
84
+ * @property {YotoDeviceShortcuts} shortcuts - Button shortcuts (always initialized)
85
+ * @property {YotoDeviceStatus} status - Current device status (always initialized)
86
+ * @property {YotoPlaybackState} playback - Current playback state (always initialized)
87
+ * @property {boolean} initialized - Whether device has been initialized
88
+ * @property {boolean} running - Whether device client is currently running (started)
89
+ * @property {Object} lastUpdate - Timestamps of last updates
90
+ * @property {number | null} lastUpdate.config - Last config update timestamp
91
+ * @property {number | null} lastUpdate.status - Last status update timestamp
92
+ * @property {number | null} lastUpdate.playback - Last playback update timestamp
93
+ * @property {string | null} lastUpdate.source - Source of last status update ('http' or 'mqtt')
94
+ */
95
+ /**
96
+ * Device hardware capabilities based on deviceType
97
+ * @typedef {Object} YotoDeviceCapabilities
98
+ * @property {boolean} hasTemperatureSensor - Whether device has a temperature sensor
99
+ * @property {boolean} hasAmbientLightSensor - Whether device has an ambient light sensor
100
+ * @property {boolean} hasColoredNightlight - Whether device has a colored nightlight
101
+ * @property {boolean} supported - Whether this device type is supported
102
+ */
103
+ /**
104
+ * Nightlight information
105
+ * @typedef {Object} YotoDeviceNightlightInfo
106
+ * @property {string} value - Raw nightlight value (hex color like '0x643600' or 'off')
107
+ * @property {string} name - Official color name (e.g., 'Orange Peel', 'Off (screen up)')
108
+ * @property {boolean} supported - Whether this device supports colored nightlight
109
+ */
110
+ /**
111
+ * Device client initialization options
112
+ * @typedef {Object} YotoDeviceModelOptions
113
+ * @property {MqttClientOptions} [mqttOptions] - MQTT.js client options to pass through to factory
114
+ * @property {number} [httpPollIntervalMs=600000] - Background HTTP polling interval for config+status sync (default: 10 minutes)
115
+ */
116
+ /**
117
+ * Online event metadata
118
+ * @typedef {Object} YotoDeviceOnlineMetadata
119
+ * @property {'startup' | 'activity'} reason - Reason device came online
120
+ * @property {number | null} [upTime] - Device uptime in seconds (only present for 'startup' reason)
121
+ */
122
+ /**
123
+ * Offline event metadata
124
+ * @typedef {Object} YotoDeviceOfflineMetadata
125
+ * @property {'shutdown' | 'timeout' | 'http-status'} reason - Reason device went offline
126
+ * @property {string | null} [shutDownReason] - Shutdown reason from device (only present for 'shutdown' reason)
127
+ * @property {number | null} [timeSinceLastSeen] - Time since last seen in ms (only present for 'timeout' reason)
128
+ * @property {string} [source] - Source of status update (only present for 'http-status' reason)
129
+ */
130
+ /**
131
+ * Started event metadata
132
+ * @typedef {Object} YotoDeviceStartedMetadata
133
+ * @property {YotoDevice} device - Device information
134
+ * @property {YotoDeviceConfig} config - Device configuration
135
+ * @property {YotoDeviceShortcuts} shortcuts - Device shortcuts
136
+ * @property {YotoDeviceStatus} status - Device status
137
+ * @property {YotoPlaybackState} playback - Playback state
138
+ * @property {boolean} initialized - Whether initialized
139
+ * @property {boolean} running - Whether running
140
+ */
141
+ /**
142
+ * Event map for YotoDeviceModel
143
+ * @typedef {{
144
+ * 'started': [YotoDeviceStartedMetadata],
145
+ * 'stopped': [],
146
+ * 'statusUpdate': [YotoDeviceStatus, string, Set<keyof YotoDeviceStatus>],
147
+ * 'configUpdate': [YotoDeviceConfig, Set<keyof YotoDeviceConfig>],
148
+ * 'playbackUpdate': [YotoPlaybackState, Set<keyof YotoPlaybackState>],
149
+ * 'online': [YotoDeviceOnlineMetadata],
150
+ * 'offline': [YotoDeviceOfflineMetadata],
151
+ * 'mqttConnected': [],
152
+ * 'mqttDisconnected': [],
153
+ * 'error': [Error]
154
+ * }} YotoDeviceModelEventMap
155
+ */
156
+ /**
157
+ * Stateful device client that manages device state primarily from MQTT with HTTP background sync
158
+ *
159
+ * Philosophy:
160
+ * - MQTT is the primary source for all real-time status updates
161
+ * - MQTT connection is always maintained and handles its own reconnection
162
+ * - Device online/offline state is tracked by MQTT activity (sets online) and explicit shutdown messages
163
+ * - HTTP background polling runs every 10 minutes to sync config+status regardless of online state
164
+ * - HTTP status updates emit offline events if device state changes to offline
165
+ *
166
+ * Events:
167
+ * - 'started' - Emitted when device client is started, passes metadata object
168
+ * - 'stopped' - Emitted when device client is stopped
169
+ * - 'statusUpdate' - Emitted when status changes, passes (status, source, changedFields)
170
+ * - 'configUpdate' - Emitted when config changes, passes (config, changedFields)
171
+ * - 'playbackUpdate' - Emitted when playback state changes, passes (playback, changedFields)
172
+ * - 'online' - Emitted when device comes online, passes metadata with reason and optional upTime
173
+ * - 'offline' - Emitted when device goes offline, passes metadata with reason and optional shutDownReason or timeSinceLastSeen
174
+ * - 'mqttConnected' - Emitted when MQTT client connects
175
+ * - 'mqttDisconnected' - Emitted when MQTT client disconnects
176
+ * - 'error' - Emitted when an error occurs, passes error
177
+ *
178
+ * @extends {EventEmitter<YotoDeviceModelEventMap>}
179
+ */
180
+ export class YotoDeviceModel extends EventEmitter<YotoDeviceModelEventMap> {
181
+ /**
182
+ * Static reference to nightlight colors map
183
+ *
184
+ * @type {Record<string, string>}
185
+ */
186
+ static NIGHTLIGHT_COLORS: Record<string, string>;
187
+ /**
188
+ * Static method to get nightlight color name
189
+ *
190
+ * @param {string} colorValue - Nightlight color value (hex code or 'off')
191
+ * @returns {string} Official color name or the original value if not found
192
+ */
193
+ static getNightlightColorName: typeof getNightlightColorName;
194
+ /**
195
+ * Create a Yoto device client
196
+ * @param {YotoClient} client - Authenticated YotoClient instance
197
+ * @param {YotoDevice} device - Device object from getDevices()
198
+ * @param {YotoDeviceModelOptions} [options] - Client options
199
+ */
200
+ constructor(client: YotoClient, device: YotoDevice, options?: YotoDeviceModelOptions);
201
+ /**
202
+ * Get device information
203
+ * @returns {YotoDevice}
204
+ */
205
+ get device(): YotoDevice;
206
+ /**
207
+ * Get current device status
208
+ * @returns { YotoDeviceStatus }
209
+ */
210
+ get status(): YotoDeviceStatus;
211
+ /**
212
+ * Get device configuration
213
+ * @returns {YotoDeviceConfig}
214
+ */
215
+ get config(): YotoDeviceConfig;
216
+ /**
217
+ * Get device shortcuts
218
+ * @returns {YotoDeviceShortcuts }
219
+ */
220
+ get shortcuts(): YotoDeviceShortcuts;
221
+ /**
222
+ * Get current playback state
223
+ * @returns {YotoPlaybackState}
224
+ */
225
+ get playback(): YotoPlaybackState;
226
+ /**
227
+ * Check if device has been initialized
228
+ * @returns {boolean}
229
+ */
230
+ get initialized(): boolean;
231
+ /**
232
+ * Check if device client is running (started)
233
+ * @returns {boolean}
234
+ */
235
+ get running(): boolean;
236
+ /**
237
+ * Check if MQTT client is connected
238
+ * @returns {boolean}
239
+ */
240
+ get mqttConnected(): boolean;
241
+ /**
242
+ * Check if device is currently online (based on MQTT activity)
243
+ * @returns {boolean}
244
+ */
245
+ get deviceOnline(): boolean;
246
+ /**
247
+ * Get device hardware capabilities based on deviceType
248
+ * @returns {YotoDeviceCapabilities}
249
+ */
250
+ get capabilities(): YotoDeviceCapabilities;
251
+ /**
252
+ * Get nightlight information including color name
253
+ * @returns {YotoDeviceNightlightInfo}
254
+ */
255
+ get nightlight(): YotoDeviceNightlightInfo;
256
+ /**
257
+ * Start the device client - fetches config, connects to MQTT, begins monitoring
258
+ * @returns {Promise<void>}
259
+ * @throws {Error} If start fails
260
+ */
261
+ start(): Promise<void>;
262
+ /**
263
+ * Stop the device client - disconnects MQTT, stops background polling
264
+ * @returns {Promise<void>}
265
+ */
266
+ stop(): Promise<void>;
267
+ /**
268
+ * Restart the device client - stops and starts again
269
+ * @returns {Promise<void>}
270
+ */
271
+ restart(): Promise<void>;
272
+ /**
273
+ * Get MQTT client instance
274
+ * @returns {YotoMqttClient | null}
275
+ */
276
+ get mqttClient(): YotoMqttClient | null;
277
+ /**
278
+ * Refresh device status from HTTP API
279
+ * This is primarily used as a fallback when device is offline
280
+ * @returns {Promise<YotoDeviceStatus>}
281
+ */
282
+ /**
283
+ * Refresh device config from HTTP API
284
+ * @returns {Promise<YotoDeviceConfig>}
285
+ */
286
+ refreshConfig(): Promise<YotoDeviceConfig>;
287
+ /**
288
+ * Update device configuration
289
+ * @param {Partial<YotoDeviceConfig>} configUpdate - Configuration changes
290
+ * @returns {Promise<void>}
291
+ */
292
+ updateConfig(configUpdate: Partial<YotoDeviceConfig>): Promise<void>;
293
+ /**
294
+ * Send a device command via HTTP API
295
+ * @param {YotoDeviceCommand} command - Command to send
296
+ * @returns {Promise<YotoDeviceCommandResponse>}
297
+ */
298
+ sendCommand(command: YotoDeviceCommand): Promise<YotoDeviceCommandResponse>;
299
+ #private;
300
+ }
301
+ /**
302
+ * Card insertion state values
303
+ */
304
+ export type CardInsertionState = "none" | "physical" | "remote";
305
+ /**
306
+ * Day mode state
307
+ */
308
+ export type DayMode = "unknown" | "night" | "day";
309
+ /**
310
+ * Power source state
311
+ */
312
+ export type PowerSource = "battery" | "dock" | "usb-c" | "wireless";
313
+ /**
314
+ * Canonical device status - normalized format for both HTTP and MQTT sources
315
+ *
316
+ * This unified format resolves differences between HTTP and MQTT:
317
+ * - HTTP uses string booleans ('0'/'1'), MQTT uses actual booleans
318
+ * - HTTP has nullable fields, MQTT fields are non-nullable
319
+ * - Field names match YotoDeviceStatusResponse with fallback to YotoDeviceFullStatus
320
+ */
321
+ export type YotoDeviceStatus = {
322
+ /**
323
+ * - Active card ID or null when no card is active
324
+ */
325
+ activeCardId: string | null;
326
+ /**
327
+ * - Battery level percentage (integer 0-100)
328
+ */
329
+ batteryLevelPercentage: number;
330
+ /**
331
+ * - Whether device is currently charging
332
+ */
333
+ isCharging: boolean;
334
+ /**
335
+ * - Whether device is currently online
336
+ */
337
+ isOnline: boolean;
338
+ /**
339
+ * - User volume level (0-16 scale)
340
+ */
341
+ volume: number;
342
+ /**
343
+ * - Maximum volume limit (0-16 scale)
344
+ */
345
+ maxVolume: number;
346
+ /**
347
+ * - Card insertion state
348
+ */
349
+ cardInsertionState: CardInsertionState;
350
+ /**
351
+ * - Day mode status
352
+ */
353
+ dayMode: DayMode;
354
+ /**
355
+ * - Power source
356
+ */
357
+ powerSource: PowerSource;
358
+ /**
359
+ * - Firmware version
360
+ */
361
+ firmwareVersion: string;
362
+ /**
363
+ * - WiFi signal strength in dBm
364
+ */
365
+ wifiStrength: number;
366
+ /**
367
+ * - Free disk space in bytes
368
+ */
369
+ freeDiskSpaceBytes: number;
370
+ /**
371
+ * - Total disk space in bytes
372
+ */
373
+ totalDiskSpaceBytes: number;
374
+ /**
375
+ * - Whether headphones are connected
376
+ */
377
+ isAudioDeviceConnected: boolean;
378
+ /**
379
+ * - Whether Bluetooth headphones are enabled
380
+ */
381
+ isBluetoothAudioConnected: boolean;
382
+ /**
383
+ * - Current nightlight color (6-digit hex color like '0xff5733' or 'off'). Most accurate value comes from MQTT status. HTTP endpoint returns either 'off' or '0x000000'. Note: This is the live status; configured colors are in config.ambientColour (day) and config.nightAmbientColour (night). Only available on devices with colored nightlight (v3).
384
+ */
385
+ nightlightMode: string;
386
+ /**
387
+ * - Temperature in Celsius (null if not supported, can be number, string "0", or "notSupported") TODO: Number or null only
388
+ */
389
+ temperatureCelsius: string | number | null;
390
+ /**
391
+ * - Ambient light sensor reading TODO: Figure out units
392
+ */
393
+ ambientLightSensorReading: number;
394
+ /**
395
+ * - Current display brightness (null when device is off) - from YotoDeviceFullStatus (dnowBrightness) TODO: Figure out units
396
+ */
397
+ displayBrightness: number | null;
398
+ /**
399
+ * - Time format preference - from YotoDeviceFullStatus
400
+ */
401
+ timeFormat: "12" | "24" | null;
402
+ /**
403
+ * - Device uptime in seconds
404
+ */
405
+ uptime: number;
406
+ /**
407
+ * - ISO 8601 timestamp of last update
408
+ */
409
+ updatedAt: string;
410
+ /**
411
+ * - Data source ('http' or 'mqtt') - metadata field added by stateful client
412
+ */
413
+ source: string;
414
+ };
415
+ /**
416
+ * Playback state from MQTT events
417
+ */
418
+ export type YotoPlaybackState = {
419
+ /**
420
+ * - Currently playing card ID TODO: Figure out name of card
421
+ */
422
+ cardId: string | null;
423
+ /**
424
+ * - Playback source (e.g., 'card', 'remote', 'MQTT') TODO: Figure out what 'mqtt' source means. Card means card, remote means remotly played card.
425
+ */
426
+ source: string | null;
427
+ /**
428
+ * - Playback status
429
+ */
430
+ playbackStatus: "playing" | "paused" | "stopped" | "loading" | string | null;
431
+ /**
432
+ * - Current track title
433
+ */
434
+ trackTitle: string | null;
435
+ /**
436
+ * - Current track key
437
+ */
438
+ trackKey: string | null;
439
+ /**
440
+ * - Current chapter title
441
+ */
442
+ chapterTitle: string | null;
443
+ /**
444
+ * - Current chapter key
445
+ */
446
+ chapterKey: string | null;
447
+ /**
448
+ * - Current position in seconds
449
+ */
450
+ position: number | null;
451
+ /**
452
+ * - Track duration in seconds
453
+ */
454
+ trackLength: number | null;
455
+ /**
456
+ * - Whether streaming
457
+ */
458
+ streaming: boolean | null;
459
+ /**
460
+ * - Sleep timer active
461
+ */
462
+ sleepTimerActive: boolean | null;
463
+ /**
464
+ * - Seconds remaining on sleep timer
465
+ */
466
+ sleepTimerSeconds: number | null;
467
+ /**
468
+ * - ISO 8601 timestamp of last update
469
+ */
470
+ updatedAt: string;
471
+ };
472
+ /**
473
+ * Complete device client state
474
+ */
475
+ export type YotoDeviceClientState = {
476
+ /**
477
+ * - Basic device information
478
+ */
479
+ device: YotoDevice;
480
+ /**
481
+ * - Device configuration (always initialized)
482
+ */
483
+ config: YotoDeviceConfig;
484
+ /**
485
+ * - Button shortcuts (always initialized)
486
+ */
487
+ shortcuts: YotoDeviceShortcuts;
488
+ /**
489
+ * - Current device status (always initialized)
490
+ */
491
+ status: YotoDeviceStatus;
492
+ /**
493
+ * - Current playback state (always initialized)
494
+ */
495
+ playback: YotoPlaybackState;
496
+ /**
497
+ * - Whether device has been initialized
498
+ */
499
+ initialized: boolean;
500
+ /**
501
+ * - Whether device client is currently running (started)
502
+ */
503
+ running: boolean;
504
+ /**
505
+ * - Timestamps of last updates
506
+ */
507
+ lastUpdate: {
508
+ config: number | null;
509
+ status: number | null;
510
+ playback: number | null;
511
+ source: string | null;
512
+ };
513
+ };
514
+ /**
515
+ * Device hardware capabilities based on deviceType
516
+ */
517
+ export type YotoDeviceCapabilities = {
518
+ /**
519
+ * - Whether device has a temperature sensor
520
+ */
521
+ hasTemperatureSensor: boolean;
522
+ /**
523
+ * - Whether device has an ambient light sensor
524
+ */
525
+ hasAmbientLightSensor: boolean;
526
+ /**
527
+ * - Whether device has a colored nightlight
528
+ */
529
+ hasColoredNightlight: boolean;
530
+ /**
531
+ * - Whether this device type is supported
532
+ */
533
+ supported: boolean;
534
+ };
535
+ /**
536
+ * Nightlight information
537
+ */
538
+ export type YotoDeviceNightlightInfo = {
539
+ /**
540
+ * - Raw nightlight value (hex color like '0x643600' or 'off')
541
+ */
542
+ value: string;
543
+ /**
544
+ * - Official color name (e.g., 'Orange Peel', 'Off (screen up)')
545
+ */
546
+ name: string;
547
+ /**
548
+ * - Whether this device supports colored nightlight
549
+ */
550
+ supported: boolean;
551
+ };
552
+ /**
553
+ * Device client initialization options
554
+ */
555
+ export type YotoDeviceModelOptions = {
556
+ /**
557
+ * - MQTT.js client options to pass through to factory
558
+ */
559
+ mqttOptions?: MqttClientOptions;
560
+ /**
561
+ * - Background HTTP polling interval for config+status sync (default: 10 minutes)
562
+ */
563
+ httpPollIntervalMs?: number;
564
+ };
565
+ /**
566
+ * Online event metadata
567
+ */
568
+ export type YotoDeviceOnlineMetadata = {
569
+ /**
570
+ * - Reason device came online
571
+ */
572
+ reason: "startup" | "activity";
573
+ /**
574
+ * - Device uptime in seconds (only present for 'startup' reason)
575
+ */
576
+ upTime?: number | null;
577
+ };
578
+ /**
579
+ * Offline event metadata
580
+ */
581
+ export type YotoDeviceOfflineMetadata = {
582
+ /**
583
+ * - Reason device went offline
584
+ */
585
+ reason: "shutdown" | "timeout" | "http-status";
586
+ /**
587
+ * - Shutdown reason from device (only present for 'shutdown' reason)
588
+ */
589
+ shutDownReason?: string | null;
590
+ /**
591
+ * - Time since last seen in ms (only present for 'timeout' reason)
592
+ */
593
+ timeSinceLastSeen?: number | null;
594
+ /**
595
+ * - Source of status update (only present for 'http-status' reason)
596
+ */
597
+ source?: string;
598
+ };
599
+ /**
600
+ * Started event metadata
601
+ */
602
+ export type YotoDeviceStartedMetadata = {
603
+ /**
604
+ * - Device information
605
+ */
606
+ device: YotoDevice;
607
+ /**
608
+ * - Device configuration
609
+ */
610
+ config: YotoDeviceConfig;
611
+ /**
612
+ * - Device shortcuts
613
+ */
614
+ shortcuts: YotoDeviceShortcuts;
615
+ /**
616
+ * - Device status
617
+ */
618
+ status: YotoDeviceStatus;
619
+ /**
620
+ * - Playback state
621
+ */
622
+ playback: YotoPlaybackState;
623
+ /**
624
+ * - Whether initialized
625
+ */
626
+ initialized: boolean;
627
+ /**
628
+ * - Whether running
629
+ */
630
+ running: boolean;
631
+ };
632
+ /**
633
+ * Event map for YotoDeviceModel
634
+ */
635
+ export type YotoDeviceModelEventMap = {
636
+ "started": [YotoDeviceStartedMetadata];
637
+ "stopped": [];
638
+ "statusUpdate": [YotoDeviceStatus, string, Set<keyof YotoDeviceStatus>];
639
+ "configUpdate": [YotoDeviceConfig, Set<keyof YotoDeviceConfig>];
640
+ "playbackUpdate": [YotoPlaybackState, Set<keyof YotoPlaybackState>];
641
+ "online": [YotoDeviceOnlineMetadata];
642
+ "offline": [YotoDeviceOfflineMetadata];
643
+ "mqttConnected": [];
644
+ "mqttDisconnected": [];
645
+ "error": [Error];
646
+ };
647
+ import { EventEmitter } from 'events';
648
+ import type { YotoDevice } from './api-endpoints/devices.js';
649
+ import type { YotoDeviceConfig } from './api-endpoints/devices.js';
650
+ import type { YotoDeviceShortcuts } from './api-endpoints/devices.js';
651
+ import type { YotoMqttClient } from './mqtt/client.js';
652
+ import type { YotoDeviceCommand } from './api-endpoints/devices.js';
653
+ import type { YotoDeviceCommandResponse } from './api-endpoints/devices.js';
654
+ import type { YotoClient } from './api-client.js';
655
+ import type { MqttClientOptions } from './mqtt/factory.js';
656
+ //# sourceMappingURL=yoto-device.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yoto-device.d.ts","sourceRoot":"","sources":["yoto-device.js"],"names":[],"mappings":"AAmGA;;;;GAIG;AACH,mDAHW,MAAM,GACJ,MAAM,CAIlB;AA7BD;;;GAGG;AAEH;;;;GAIG;AACH;;;;;;;;;;EAUC;AAWD;;;;;;;;;;;;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