@sebbo2002/node-pyatv 8.1.3-develop.2 → 9.0.0-develop.2

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.
@@ -1,41 +1,6 @@
1
1
  import { SpawnOptions, ChildProcess } from 'child_process';
2
2
  import { EventEmitter } from 'events';
3
3
 
4
- /**
5
- * @internal
6
- */
7
- declare class FakeChildProcessStdIn extends EventEmitter {
8
- write(data: string): void;
9
- }
10
- /**
11
- * @internal
12
- */
13
- declare class FakeChildProcess extends EventEmitter {
14
- cmd: string;
15
- args: ReadonlyArray<string>;
16
- timeout: NodeJS.Timeout | undefined;
17
- stdout: EventEmitter;
18
- stderr: EventEmitter;
19
- stdin: FakeChildProcessStdIn;
20
- constructor(command: string, args: ReadonlyArray<string>, options: SpawnOptions, callback: (cp: FakeChildProcessController) => void);
21
- kill(): void;
22
- }
23
- /**
24
- * @internal
25
- */
26
- declare class FakeChildProcessController {
27
- _cp: FakeChildProcess;
28
- _code: number | null;
29
- constructor(cp: FakeChildProcess);
30
- cmd(): string;
31
- stdout(content: string | Record<string, unknown>): this;
32
- stderr(content: string): this;
33
- onStdIn(listener: (...args: any[]) => void): this;
34
- error(error: Error): this;
35
- code(exitCode: number): this;
36
- end(content?: string | Record<string, unknown>): this;
37
- }
38
-
39
4
  /**
40
5
  * Represents an Apple TV. Use [[getState]] to query the current state (e.g. media
41
6
  * type and title). You can also use the attribute methods (e.g. [[getTitle]] to get
@@ -44,39 +9,32 @@ declare class FakeChildProcessController {
44
9
  * It's also possible to send key commands by using [[pressKey]] or methods like [[pause]].
45
10
  */
46
11
  declare class NodePyATVDevice implements EventEmitter {
47
- private readonly options;
48
- private readonly state;
49
- private readonly events;
50
- constructor(options: NodePyATVDeviceOptions);
51
12
  /**
52
- * Get the name of the Apple TV.
53
- *
54
- * ```typescript
55
- * import pyatv from '@sebbo2002/node-pyatv';
56
- * const devices = await pyatv.find();
57
- * devices.forEach(device =>
58
- * console.log(device.name)
59
- * );
60
- * ```
13
+ * Get all IDs of the Apple TV.
14
+ * Requires pyatv >= 0.14.5.
61
15
  */
62
- get name(): string;
16
+ get allIDs(): string[] | undefined;
63
17
  /**
64
- * Get the IP address of the Apple TV.
18
+ * Returns true, if debugging is enabled. Returns the custom
19
+ * logging method, if one was specified. Otherwise, if debug
20
+ * log is disabled, returns undefined.
65
21
  */
66
- get host(): string;
22
+ get debug(): ((msg: string) => void) | true | undefined;
67
23
  /**
68
- * Get the ID of the Apple TV.
24
+ * Enable or disable debugging or set a custom
25
+ * debugging method to use.
26
+ *
27
+ * @param debug
69
28
  */
70
- get id(): string | undefined;
29
+ set debug(debug: ((msg: string) => void) | true | undefined);
71
30
  /**
72
- * Get all IDs of the Apple TV.
73
- * Requires pyatv >= 0.14.5.
31
+ * Get the IP address of the Apple TV.
74
32
  */
75
- get allIDs(): string[] | undefined;
33
+ get host(): string | undefined;
76
34
  /**
77
- * Get the used protocol to connect to the Apple TV.
35
+ * Get the ID of the Apple TV.
78
36
  */
79
- get protocol(): NodePyATVProtocol | undefined;
37
+ get id(): string | undefined;
80
38
  /**
81
39
  * Get the MAC address of the Apple TV.
82
40
  * Requires pyatv >= 0.14.5.
@@ -96,6 +54,18 @@ declare class NodePyATVDevice implements EventEmitter {
96
54
  * @example device.modelName → "Apple TV 4K"
97
55
  */
98
56
  get modelName(): string | undefined;
57
+ /**
58
+ * Get the name of the Apple TV.
59
+ *
60
+ * ```typescript
61
+ * import pyatv from '@sebbo2002/node-pyatv';
62
+ * const devices = await pyatv.find();
63
+ * devices.forEach(device =>
64
+ * console.log(device.name)
65
+ * );
66
+ * ```
67
+ */
68
+ get name(): string;
99
69
  /**
100
70
  * Get the operating system of the device. Only set, if the
101
71
  * device was found with [[find()]]. Requires pyatv ≧ 0.10.3.
@@ -104,12 +74,9 @@ declare class NodePyATVDevice implements EventEmitter {
104
74
  */
105
75
  get os(): string | undefined;
106
76
  /**
107
- * Get the device version. Only set, if the device was found
108
- * during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.
109
- *
110
- * @example device.version → "15.5.1"
77
+ * Get the used protocol to connect to the Apple TV.
111
78
  */
112
- get version(): string | undefined;
79
+ get protocol(): NodePyATVProtocol | undefined;
113
80
  /**
114
81
  * Returns a list of services supported by the device. Ony set, if
115
82
  * the device was found during a scan using [[find()]]. Requires
@@ -128,232 +95,212 @@ declare class NodePyATVDevice implements EventEmitter {
128
95
  */
129
96
  get services(): NodePyATVService[] | undefined;
130
97
  /**
131
- * Returns true, if debugging is enabled. Returns the custom
132
- * logging method, if one was specified. Otherwise, if debug
133
- * log is disabled, returns undefined.
134
- */
135
- get debug(): true | ((msg: string) => void) | undefined;
136
- /**
137
- * Enable or disable debugging or set a custom
138
- * debugging method to use.
139
- *
140
- * @param debug
141
- */
142
- set debug(debug: true | ((msg: string) => void) | undefined);
143
- /**
144
- * Returns an object with `name`, `host`, `id` and `protocol`.
145
- * Can be used to initiate a new device instance.
146
- *
147
- * @category Basic
148
- */
149
- toJSON(): {
150
- name: string;
151
- host: string;
152
- id: string | undefined;
153
- protocol: NodePyATVProtocol | undefined;
154
- };
155
- /**
156
- * Returns a string. Just for debugging, etc.
98
+ * Get the device version. Only set, if the device was found
99
+ * during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.
157
100
  *
158
- * @category Basic
101
+ * @example device.version → "15.5.1"
159
102
  */
160
- toString(): string;
103
+ get version(): string | undefined;
104
+ private readonly events;
105
+ private readonly options;
106
+ private readonly state;
107
+ constructor(options: NodePyATVDeviceOptions);
161
108
  /**
162
- * Returns an [[NodePyATVState]] object representing the current state
163
- * of the device. Has an internal cache, which has a default TTL of 5s.
164
- * You can change this default value by passing the `maxAge` option.
165
- *
166
- * ```typescript
167
- * await device.getState({maxAge: 10000}); // cache TTL: 10s
168
- * ```
169
- *
170
- * @param options
171
- * @category State
109
+ * Add an event listener. Will start the event subscription with the
110
+ * Apple TV as long as there are listeners for any event registered.
111
+ * @param event
112
+ * @param listener
113
+ * @category Event
172
114
  */
173
- getState(options?: NodePyATVGetStateOptions): Promise<NodePyATVState>;
115
+ addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
174
116
  /**
175
117
  * Removes the state node-pyatv cached for this device.
176
118
  *
177
119
  * @category State
178
120
  */
179
121
  clearState(): void;
180
- private applyState;
181
122
  /**
182
- * Get the date and time when the state was last updated.
183
- * @param options
184
- * @category State
123
+ * Send the "down" command
124
+ * @category Control
185
125
  */
186
- getDateTime(options?: NodePyATVGetStateOptions): Promise<Date | null>;
126
+ down(): Promise<void>;
187
127
  /**
188
- * Get the hash of the current media
189
- * @param options
190
- * @category State
128
+ * Emit an event.
129
+ * @param event
130
+ * @param payload
131
+ * @category Event
191
132
  */
192
- getHash(options?: NodePyATVGetStateOptions): Promise<string | null>;
133
+ emit(event: string | symbol, payload: NodePyATVDeviceEvent): boolean;
193
134
  /**
194
- * Get the media type of the current media
195
- * @param options
196
- * @category State
135
+ * Get all event names which are currently known.
136
+ * @category Event
197
137
  */
198
- getMediaType(options?: NodePyATVGetStateOptions): Promise<NodePyATVMediaType | null>;
138
+ eventNames(): Array<string | symbol>;
199
139
  /**
200
- * Get the state of this device (e.g. playing, etc.)
140
+ * Returns the album of the current playing media
201
141
  * @param options
202
142
  * @category State
203
143
  */
204
- getDeviceState(options?: NodePyATVGetStateOptions): Promise<NodePyATVDeviceState | null>;
144
+ getAlbum(options?: NodePyATVGetStateOptions): Promise<null | string>;
205
145
  /**
206
- * Returns the title of the current playing media
146
+ * Returns the currently used app
207
147
  * @param options
208
148
  * @category State
209
149
  */
210
- getTitle(options?: NodePyATVGetStateOptions): Promise<string | null>;
150
+ getApp(options?: NodePyATVGetStateOptions): Promise<null | string>;
211
151
  /**
212
- * Returns the artist of the current playing media
152
+ * Returns the id of the currently used app
213
153
  * @param options
214
154
  * @category State
215
155
  */
216
- getArtist(options?: NodePyATVGetStateOptions): Promise<string | null>;
156
+ getAppId(options?: NodePyATVGetStateOptions): Promise<null | string>;
217
157
  /**
218
- * Returns the album of the current playing media
158
+ * Returns the artist of the current playing media
219
159
  * @param options
220
160
  * @category State
221
161
  */
222
- getAlbum(options?: NodePyATVGetStateOptions): Promise<string | null>;
162
+ getArtist(options?: NodePyATVGetStateOptions): Promise<null | string>;
223
163
  /**
224
- * Returns the genre of the current playing media
164
+ * Returns the app specific content identifier
225
165
  * @param options
226
166
  * @category State
227
167
  */
228
- getGenre(options?: NodePyATVGetStateOptions): Promise<string | null>;
168
+ getContentIdentifier(options?: NodePyATVGetStateOptions): Promise<null | string>;
229
169
  /**
230
- * Returns the media length of the current playing media
170
+ * Get the date and time when the state was last updated.
231
171
  * @param options
232
172
  * @category State
233
173
  */
234
- getTotalTime(options?: NodePyATVGetStateOptions): Promise<number | null>;
174
+ getDateTime(options?: NodePyATVGetStateOptions): Promise<Date | null>;
235
175
  /**
236
- * Returns the title of the current playing media
176
+ * Get the state of this device (e.g. playing, etc.)
237
177
  * @param options
238
178
  * @category State
239
179
  */
240
- getPosition(options?: NodePyATVGetStateOptions): Promise<number | null>;
180
+ getDeviceState(options?: NodePyATVGetStateOptions): Promise<NodePyATVDeviceState | null>;
241
181
  /**
242
- * Returns the shuffle state
182
+ * Returns the episode number.
183
+ * Probably only set [if MRP is used](https://pyatv.dev/development/metadata/#currently-playing).
243
184
  * @param options
244
185
  * @category State
245
186
  */
246
- getShuffle(options?: NodePyATVGetStateOptions): Promise<NodePyATVShuffleState | null>;
187
+ getEpisodeNumber(options?: NodePyATVGetStateOptions): Promise<null | number>;
247
188
  /**
248
- * Returns the repeat state
189
+ * Returns the current focus state of the device
249
190
  * @param options
250
191
  * @category State
251
192
  */
252
- getRepeat(options?: NodePyATVGetStateOptions): Promise<NodePyATVRepeatState | null>;
193
+ getFocusState(options?: NodePyATVGetStateOptions): Promise<NodePyATVFocusState | null>;
253
194
  /**
254
- * Returns the currently used app
195
+ * Returns the genre of the current playing media
255
196
  * @param options
256
197
  * @category State
257
198
  */
258
- getApp(options?: NodePyATVGetStateOptions): Promise<string | null>;
199
+ getGenre(options?: NodePyATVGetStateOptions): Promise<null | string>;
259
200
  /**
260
- * Returns the id of the currently used app
201
+ * Get the hash of the current media
261
202
  * @param options
262
203
  * @category State
263
204
  */
264
- getAppId(options?: NodePyATVGetStateOptions): Promise<string | null>;
205
+ getHash(options?: NodePyATVGetStateOptions): Promise<null | string>;
265
206
  /**
266
- * Returns the current power state (= is it on or off, see [[NodePyATVPowerState]]) of the device.
207
+ * Returns the iTunes Store identifier if available.
208
+ * Requires pyatv >= 0.16.0
267
209
  * @param options
268
210
  * @category State
211
+ * @alias getiTunesStoreIdentifier
269
212
  */
270
- getPowerState(options?: NodePyATVGetStateOptions): Promise<NodePyATVPowerState | null>;
213
+ getITunesStoreIdentifier(options?: NodePyATVGetStateOptions): Promise<null | number>;
214
+ getiTunesStoreIdentifier(options?: NodePyATVGetStateOptions): Promise<null | number>;
271
215
  /**
272
- * Returns the current volume of the device in percent (0 - 100)
273
- * @param options
274
- * @category State
216
+ * Get max number of listeners allowed
217
+ * @category Event
275
218
  */
276
- getVolume(options?: NodePyATVGetStateOptions): Promise<number | null>;
219
+ getMaxListeners(): number;
277
220
  /**
278
- * Returns the current focus state of the device
221
+ * Get the media type of the current media
279
222
  * @param options
280
223
  * @category State
281
224
  */
282
- getFocusState(options?: NodePyATVGetStateOptions): Promise<NodePyATVFocusState | null>;
225
+ getMediaType(options?: NodePyATVGetStateOptions): Promise<NodePyATVMediaType | null>;
283
226
  /**
284
227
  * Returns the current output devices of the device
285
228
  * @param options
286
229
  * @category State
287
230
  */
288
231
  getOutputDevices(options?: NodePyATVGetStateOptions): Promise<Array<{
289
- name: string;
290
232
  identifier: string;
233
+ name: string;
291
234
  }> | null>;
292
235
  /**
293
- * Returns the app specific content identifier
236
+ * Returns the title of the current playing media
294
237
  * @param options
295
238
  * @category State
296
239
  */
297
- getContentIdentifier(options?: NodePyATVGetStateOptions): Promise<string | null>;
240
+ getPosition(options?: NodePyATVGetStateOptions): Promise<null | number>;
298
241
  /**
299
- * Returns the iTunes Store identifier if available.
300
- * Requires pyatv >= 0.16.0
242
+ * Returns the current power state (= is it on or off, see [[NodePyATVPowerState]]) of the device.
301
243
  * @param options
302
244
  * @category State
303
- * @alias getiTunesStoreIdentifier
304
245
  */
305
- getITunesStoreIdentifier(options?: NodePyATVGetStateOptions): Promise<number | null>;
306
- getiTunesStoreIdentifier(options?: NodePyATVGetStateOptions): Promise<number | null>;
246
+ getPowerState(options?: NodePyATVGetStateOptions): Promise<NodePyATVPowerState | null>;
307
247
  /**
308
- * Returns the episode number.
309
- * Probably only set [if MRP is used](https://pyatv.dev/development/metadata/#currently-playing).
248
+ * Returns the repeat state
310
249
  * @param options
311
250
  * @category State
312
251
  */
313
- getEpisodeNumber(options?: NodePyATVGetStateOptions): Promise<number | null>;
252
+ getRepeat(options?: NodePyATVGetStateOptions): Promise<NodePyATVRepeatState | null>;
314
253
  /**
315
254
  * Returns the season number.
316
255
  * Probably only set [if MRP is used](https://pyatv.dev/development/metadata/#currently-playing).
317
256
  * @param options
318
257
  * @category State
319
258
  */
320
- getSeasonNumber(options?: NodePyATVGetStateOptions): Promise<number | null>;
259
+ getSeasonNumber(options?: NodePyATVGetStateOptions): Promise<null | number>;
321
260
  /**
322
261
  * Returns the season name.
323
262
  * Probably only set [if MRP is used](https://pyatv.dev/development/metadata/#currently-playing).
324
263
  * @param options
325
264
  * @category State
326
265
  */
327
- getSeriesName(options?: NodePyATVGetStateOptions): Promise<string | null>;
266
+ getSeriesName(options?: NodePyATVGetStateOptions): Promise<null | string>;
328
267
  /**
329
- * Returns the list of installed apps on the Apple TV. Probably requires `companionCredentials`,
330
- * see https://pyatv.dev/documentation/atvremote/#apps for more details.
268
+ * Returns the shuffle state
269
+ * @param options
270
+ * @category State
331
271
  */
332
- listApps(): Promise<NodePyATVApp[]>;
333
- private _pressKeyWithScript;
334
- private _pressKeyWithRemote;
272
+ getShuffle(options?: NodePyATVGetStateOptions): Promise<NodePyATVShuffleState | null>;
335
273
  /**
336
- * Send a key press to the Apple TV
274
+ * Returns an [[NodePyATVState]] object representing the current state
275
+ * of the device. Has an internal cache, which has a default TTL of 5s.
276
+ * You can change this default value by passing the `maxAge` option.
337
277
  *
338
278
  * ```typescript
339
- * await device.pressKey(NodePyATVKeys.home);
340
- * ```
341
- *
342
- * <br />
343
- *
344
- * ```javascript
345
- * await device.pressKey('home');
279
+ * await device.getState({maxAge: 10000}); // cache TTL: 10s
346
280
  * ```
347
281
  *
348
- * @param key
349
- * @category Control
282
+ * @param options
283
+ * @category State
350
284
  */
351
- pressKey(key: NodePyATVKeys): Promise<void>;
285
+ getState(options?: NodePyATVGetStateOptions): Promise<NodePyATVState>;
352
286
  /**
353
- * Send the "down" command
354
- * @category Control
287
+ * Returns the title of the current playing media
288
+ * @param options
289
+ * @category State
355
290
  */
356
- down(): Promise<void>;
291
+ getTitle(options?: NodePyATVGetStateOptions): Promise<null | string>;
292
+ /**
293
+ * Returns the media length of the current playing media
294
+ * @param options
295
+ * @category State
296
+ */
297
+ getTotalTime(options?: NodePyATVGetStateOptions): Promise<null | number>;
298
+ /**
299
+ * Returns the current volume of the device in percent (0 - 100)
300
+ * @param options
301
+ * @category State
302
+ */
303
+ getVolume(options?: NodePyATVGetStateOptions): Promise<null | number>;
357
304
  /**
358
305
  * Send the "home" command
359
306
  * @category Control
@@ -364,11 +311,36 @@ declare class NodePyATVDevice implements EventEmitter {
364
311
  * @category Control
365
312
  */
366
313
  homeHold(): Promise<void>;
314
+ /**
315
+ * Launch an application. Probably requires `companionCredentials`, see
316
+ * https://pyatv.dev/documentation/atvremote/#apps for more details.
317
+ * @param id App identifier, e.g. `com.netflix.Netflix`
318
+ */
319
+ launchApp(id: string): Promise<void>;
367
320
  /**
368
321
  * Send the "left" command
369
322
  * @category Control
370
323
  */
371
324
  left(): Promise<void>;
325
+ /**
326
+ * Returns the list of installed apps on the Apple TV. Probably requires `companionCredentials`,
327
+ * see https://pyatv.dev/documentation/atvremote/#apps for more details.
328
+ */
329
+ listApps(): Promise<NodePyATVApp[]>;
330
+ /**
331
+ * Get number of listeners for event
332
+ * @param event
333
+ * @category Event
334
+ */
335
+ listenerCount(event: string | symbol): number;
336
+ /**
337
+ * Get listeners for event. Will also return
338
+ * node-pyatv wrappers (e.g. once)
339
+ *
340
+ * @param event
341
+ * @category Event
342
+ */
343
+ listeners(event: string | symbol): Function[];
372
344
  /**
373
345
  * Send the "menu" command
374
346
  * @category Control
@@ -379,6 +351,31 @@ declare class NodePyATVDevice implements EventEmitter {
379
351
  * @category Control
380
352
  */
381
353
  next(): Promise<void>;
354
+ /**
355
+ * Remove an event listener. Will stop the event subscription with the
356
+ * Apple TV if this was the last event listener.
357
+ * @param event
358
+ * @param listener
359
+ * @category Event
360
+ */
361
+ off(event: string | symbol, listener: (event: Error | NodePyATVDeviceEvent) => void): this;
362
+ /**
363
+ * Add an event listener. Will start the event subscription with the
364
+ * Apple TV as long as there are listeners for any event registered.
365
+ * @param event
366
+ * @param listener
367
+ * @category Event
368
+ */
369
+ on(event: string | symbol, listener: (event: Error | NodePyATVDeviceEvent) => void): this;
370
+ /**
371
+ * Add an event listener. Will start the event subscription with the
372
+ * Apple TV as long as there are listeners for any event registered.
373
+ * Removes the listener automatically after the first occurrence.
374
+ * @param event
375
+ * @param listener
376
+ * @category Event
377
+ */
378
+ once(event: string | symbol, listener: (event: Error | NodePyATVDeviceEvent) => void): this;
382
379
  /**
383
380
  * Send the "pause" command
384
381
  * @category Control
@@ -394,11 +391,62 @@ declare class NodePyATVDevice implements EventEmitter {
394
391
  * @category Control
395
392
  */
396
393
  playPause(): Promise<void>;
394
+ /**
395
+ * @param event
396
+ * @param listener
397
+ * @category Event
398
+ */
399
+ prependListener(event: string | symbol, listener: (event: Error | NodePyATVDeviceEvent) => void): this;
400
+ /**
401
+ * @param event
402
+ * @param listener
403
+ * @category Event
404
+ */
405
+ prependOnceListener(event: string | symbol, listener: (event: Error | NodePyATVDeviceEvent) => void): this;
406
+ /**
407
+ * Send a key press to the Apple TV
408
+ *
409
+ * ```typescript
410
+ * await device.pressKey(NodePyATVKeys.home);
411
+ * ```
412
+ *
413
+ * <br />
414
+ *
415
+ * ```javascript
416
+ * await device.pressKey('home');
417
+ * ```
418
+ *
419
+ * @param key
420
+ * @category Control
421
+ */
422
+ pressKey(key: NodePyATVKeys): Promise<void>;
397
423
  /**
398
424
  * Send the "previous" command
399
425
  * @category Control
400
426
  */
401
427
  previous(): Promise<void>;
428
+ /**
429
+ * @param event
430
+ * @category Event
431
+ */
432
+ rawListeners(event: string | symbol): Function[];
433
+ /**
434
+ * Removes all listeners, either for the given event or
435
+ * for every event. Will stop the event subscription with
436
+ * the Apple TV if this was the last event listener.
437
+ *
438
+ * @param event
439
+ * @category Event
440
+ */
441
+ removeAllListeners(event?: string | symbol): this;
442
+ /**
443
+ * Remove an event listener. Will stop the event subscription with the
444
+ * Apple TV if this was the last event listener.
445
+ * @param event
446
+ * @param listener
447
+ * @category Event
448
+ */
449
+ removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
402
450
  /**
403
451
  * Send the "right" command
404
452
  * @category Control
@@ -409,6 +457,11 @@ declare class NodePyATVDevice implements EventEmitter {
409
457
  * @category Control
410
458
  */
411
459
  select(): Promise<void>;
460
+ /**
461
+ * @param n
462
+ * @category Event
463
+ */
464
+ setMaxListeners(n: number): this;
412
465
  /**
413
466
  * Send the "skipBackward" command
414
467
  * @category Control
@@ -431,31 +484,23 @@ declare class NodePyATVDevice implements EventEmitter {
431
484
  */
432
485
  suspend(): Promise<void>;
433
486
  /**
434
- * Send the "topMenu" command
435
- * @category Control
436
- */
437
- topMenu(): Promise<void>;
438
- /**
439
- * Send the "up" command
440
- * @category Control
441
- */
442
- up(): Promise<void>;
443
- /**
444
- * Send the "volumeDown" command
445
- * @category Control
487
+ * Returns an object with `name`, `host`, `mac`, `id` and `protocol`.
488
+ * Can be used to initiate a new device instance.
489
+ *
490
+ * @category Basic
446
491
  */
447
- volumeDown(): Promise<void>;
492
+ toJSON(): Pick<NodePyATVDeviceOptions, 'host' | 'id' | 'mac' | 'name' | 'protocol'>;
448
493
  /**
449
- * Send the "volumeUp" command
494
+ * Send the "topMenu" command
450
495
  * @category Control
451
496
  */
452
- volumeUp(): Promise<void>;
497
+ topMenu(): Promise<void>;
453
498
  /**
454
- * Send the "wakeup" command
455
- * @category Control
456
- * @deprecated
499
+ * Returns a string. Just for debugging, etc.
500
+ *
501
+ * @category Basic
457
502
  */
458
- wakeup(): Promise<void>;
503
+ toString(): string;
459
504
  /**
460
505
  * Send the "turn_off" command
461
506
  * @category Control
@@ -467,132 +512,66 @@ declare class NodePyATVDevice implements EventEmitter {
467
512
  */
468
513
  turnOn(): Promise<void>;
469
514
  /**
470
- * Launch an application. Probably requires `companionCredentials`, see
471
- * https://pyatv.dev/documentation/atvremote/#apps for more details.
472
- * @param id App identifier, e.g. `com.netflix.Netflix`
473
- */
474
- launchApp(id: string): Promise<void>;
475
- /**
476
- * Add an event listener. Will start the event subscription with the
477
- * Apple TV as long as there are listeners for any event registered.
478
- * @param event
479
- * @param listener
480
- * @category Event
481
- */
482
- addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
483
- /**
484
- * Emit an event.
485
- * @param event
486
- * @param payload
487
- * @category Event
488
- */
489
- emit(event: string | symbol, payload: NodePyATVDeviceEvent): boolean;
490
- /**
491
- * Get all event names which are currently known.
492
- * @category Event
493
- */
494
- eventNames(): Array<string | symbol>;
495
- /**
496
- * Get max number of listeners allowed
497
- * @category Event
498
- */
499
- getMaxListeners(): number;
500
- /**
501
- * Get number of listeners for event
502
- * @param event
503
- * @category Event
504
- */
505
- listenerCount(event: string | symbol): number;
506
- /**
507
- * Get listeners for event. Will also return
508
- * node-pyatv wrappers (e.g. once)
509
- *
510
- * @param event
511
- * @category Event
512
- */
513
- listeners(event: string | symbol): Function[];
514
- /**
515
- * Remove an event listener. Will stop the event subscription with the
516
- * Apple TV if this was the last event listener.
517
- * @param event
518
- * @param listener
519
- * @category Event
520
- */
521
- off(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this;
522
- /**
523
- * Add an event listener. Will start the event subscription with the
524
- * Apple TV as long as there are listeners for any event registered.
525
- * @param event
526
- * @param listener
527
- * @category Event
528
- */
529
- on(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this;
530
- /**
531
- * Add an event listener. Will start the event subscription with the
532
- * Apple TV as long as there are listeners for any event registered.
533
- * Removes the listener automatically after the first occurrence.
534
- * @param event
535
- * @param listener
536
- * @category Event
537
- */
538
- once(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this;
539
- /**
540
- * @param event
541
- * @param listener
542
- * @category Event
543
- */
544
- prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this;
545
- /**
546
- * @param event
547
- * @param listener
548
- * @category Event
549
- */
550
- prependOnceListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent | Error) => void): this;
551
- /**
552
- * @param event
553
- * @category Event
515
+ * Send the "up" command
516
+ * @category Control
554
517
  */
555
- rawListeners(event: string | symbol): Function[];
518
+ up(): Promise<void>;
556
519
  /**
557
- * Removes all listeners, either for the given event or
558
- * for every event. Will stop the event subscription with
559
- * the Apple TV if this was the last event listener.
560
- *
561
- * @param event
562
- * @category Event
520
+ * Send the "volumeDown" command
521
+ * @category Control
563
522
  */
564
- removeAllListeners(event?: string | symbol): this;
523
+ volumeDown(): Promise<void>;
565
524
  /**
566
- * Remove an event listener. Will stop the event subscription with the
567
- * Apple TV if this was the last event listener.
568
- * @param event
569
- * @param listener
570
- * @category Event
525
+ * Send the "volumeUp" command
526
+ * @category Control
571
527
  */
572
- removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
528
+ volumeUp(): Promise<void>;
573
529
  /**
574
- * @param n
575
- * @category Event
530
+ * Send the "wakeup" command
531
+ * @category Control
532
+ * @deprecated
576
533
  */
577
- setMaxListeners(n: number): this;
534
+ wakeup(): Promise<void>;
535
+ private _pressKeyWithRemote;
536
+ private _pressKeyWithScript;
537
+ private applyState;
578
538
  }
579
539
 
580
- declare enum NodePyATVExecutableType {
581
- atvremote = "atvremote",
582
- atvscript = "atvscript"
540
+ /**
541
+ * @internal
542
+ */
543
+ declare class FakeChildProcess extends EventEmitter {
544
+ args: ReadonlyArray<string>;
545
+ cmd: string;
546
+ stderr: EventEmitter;
547
+ stdin: FakeChildProcessStdIn;
548
+ stdout: EventEmitter;
549
+ timeout: NodeJS.Timeout | undefined;
550
+ constructor(command: string, args: ReadonlyArray<string>, options: SpawnOptions, callback: (cp: FakeChildProcessController) => void);
551
+ kill(): void;
583
552
  }
584
- declare enum NodePyATVProtocol {
585
- dmap = "dmap",
586
- mrp = "mrp",
587
- airplay = "airplay",
588
- mdns = "mdns"
553
+ /**
554
+ * @internal
555
+ */
556
+ declare class FakeChildProcessController {
557
+ _code: null | number;
558
+ _cp: FakeChildProcess;
559
+ constructor(cp: FakeChildProcess);
560
+ cmd(): string;
561
+ code(exitCode: number): this;
562
+ end(content?: Record<string, unknown> | string): this;
563
+ error(error: Error): this;
564
+ onStdIn(listener: (...args: any[]) => void): this;
565
+ stderr(content: string): this;
566
+ stdout(content: Record<string, unknown> | string): this;
589
567
  }
590
- declare enum NodePyATVMediaType {
591
- music = "music",
592
- tv = "tv",
593
- video = "video",
594
- unknown = "unknown"
568
+ /**
569
+ * @internal
570
+ */
571
+ declare class FakeChildProcessStdIn extends EventEmitter {
572
+ write(data: string): void;
595
573
  }
574
+
596
575
  declare enum NodePyATVDeviceState {
597
576
  idle = "idle",
598
577
  loading = "loading",
@@ -601,19 +580,9 @@ declare enum NodePyATVDeviceState {
601
580
  seeking = "seeking",
602
581
  stopped = "stopped"
603
582
  }
604
- declare enum NodePyATVRepeatState {
605
- all = "all",
606
- track = "track",
607
- off = "off"
608
- }
609
- declare enum NodePyATVShuffleState {
610
- albums = "albums",
611
- songs = "songs",
612
- off = "off"
613
- }
614
- declare enum NodePyATVPowerState {
615
- on = "on",
616
- off = "off"
583
+ declare enum NodePyATVExecutableType {
584
+ atvremote = "atvremote",
585
+ atvscript = "atvscript"
617
586
  }
618
587
  declare enum NodePyATVFocusState {
619
588
  focued = "focused",
@@ -638,12 +607,12 @@ declare enum NodePyATVKeys {
638
607
  stop = "stop",
639
608
  suspend = "suspend",
640
609
  topMenu = "topMenu",
610
+ turnOff = "turnOff",
611
+ turnOn = "turnOn",
641
612
  up = "up",
642
613
  volumeDown = "volumeDown",
643
614
  volumeUp = "volumeUp",
644
- wakeup = "wakeup",
645
- turnOff = "turnOff",
646
- turnOn = "turnOn"
615
+ wakeup = "wakeup"
647
616
  }
648
617
  declare enum NodePyATVListenerState {
649
618
  stopped = 0,
@@ -651,159 +620,185 @@ declare enum NodePyATVListenerState {
651
620
  started = 2,
652
621
  stopping = 3
653
622
  }
654
- type NodePyATVStateIndex = keyof NodePyATVState;
655
- type NodePyATVEventValueType = (string | number | NodePyATVMediaType | NodePyATVDeviceState | NodePyATVShuffleState | NodePyATVRepeatState);
656
- interface NodePyATVInstanceOptions {
657
- atvremotePath?: string;
658
- atvscriptPath?: string;
659
- debug?: true | ((msg: string) => void);
660
- noColors?: true;
661
- spawn?: (command: string, args: Array<string>, options: SpawnOptions) => (ChildProcess | FakeChildProcess);
623
+ declare enum NodePyATVMediaType {
624
+ music = "music",
625
+ tv = "tv",
626
+ unknown = "unknown",
627
+ video = "video"
662
628
  }
663
- interface NodePyATVRequestOptions extends NodePyATVInstanceOptions {
664
- allowMultipleResponses?: boolean;
629
+ declare enum NodePyATVPowerState {
630
+ off = "off",
631
+ on = "on"
665
632
  }
666
- interface NodePyATVVersionResponse {
667
- pyatv: string | null;
668
- module: string | null;
633
+ declare enum NodePyATVProtocol {
634
+ airplay = "airplay",
635
+ dmap = "dmap",
636
+ mdns = "mdns",
637
+ mrp = "mrp"
638
+ }
639
+ declare enum NodePyATVRepeatState {
640
+ all = "all",
641
+ off = "off",
642
+ track = "track"
643
+ }
644
+ declare enum NodePyATVShuffleState {
645
+ albums = "albums",
646
+ off = "off",
647
+ songs = "songs"
648
+ }
649
+ interface NodePyATVApp {
650
+ id: string;
651
+ launch: () => Promise<void>;
652
+ name: string;
653
+ }
654
+ interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
655
+ allIDs?: string[];
656
+ host?: string;
657
+ mac?: string;
658
+ model?: string;
659
+ modelName?: string;
660
+ name: string;
661
+ os?: string;
662
+ services?: NodePyATVService[];
663
+ version?: string;
664
+ }
665
+ type NodePyATVEventValueType = NodePyATVDeviceState | NodePyATVMediaType | NodePyATVRepeatState | NodePyATVShuffleState | number | string;
666
+ interface NodePyATVFindAndInstanceOptions extends NodePyATVFindOptions, NodePyATVInstanceOptions {
669
667
  }
670
668
  interface NodePyATVFindOptions {
669
+ airplayCredentials?: string;
670
+ companionCredentials?: string;
671
+ dmapCredentials?: string;
671
672
  host?: string;
672
673
  hosts?: string[];
673
674
  id?: string;
674
- protocol?: NodePyATVProtocol;
675
- dmapCredentials?: string;
676
675
  mrpCredentials?: string;
677
- airplayCredentials?: string;
678
- companionCredentials?: string;
676
+ protocol?: NodePyATVProtocol;
679
677
  raopCredentials?: string;
680
678
  }
681
- interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOptions, NodePyATVFindOptions {
682
- }
683
679
  interface NodePyATVFindResponseObject {
684
680
  devices: NodePyATVDevice[];
685
681
  errors: Record<string, unknown>[];
686
682
  }
687
- interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
688
- host: string;
689
- name: string;
690
- mac?: string;
691
- model?: string;
692
- modelName?: string;
693
- os?: string;
694
- version?: string;
695
- services?: NodePyATVService[];
696
- allIDs?: string[];
697
- }
698
683
  interface NodePyATVGetStateOptions {
699
684
  maxAge?: number;
700
685
  }
686
+ interface NodePyATVInstanceOptions {
687
+ atvremotePath?: string;
688
+ atvscriptPath?: string;
689
+ debug?: ((msg: string) => void) | true;
690
+ noColors?: true;
691
+ spawn?: (command: string, args: Array<string>, options: SpawnOptions) => ChildProcess | FakeChildProcess;
692
+ }
693
+ interface NodePyATVRequestOptions extends NodePyATVInstanceOptions {
694
+ allowMultipleResponses?: boolean;
695
+ }
701
696
  interface NodePyATVService {
702
- protocol: NodePyATVProtocol;
703
697
  port: number;
698
+ protocol: NodePyATVProtocol;
704
699
  }
705
700
  interface NodePyATVState {
701
+ album: null | string;
702
+ app: null | string;
703
+ appId: null | string;
704
+ artist: null | string;
705
+ contentIdentifier: null | string;
706
706
  dateTime: Date | null;
707
- hash: string | null;
708
- mediaType: NodePyATVMediaType | null;
709
707
  deviceState: NodePyATVDeviceState | null;
710
- title: string | null;
711
- artist: string | null;
712
- album: string | null;
713
- genre: string | null;
714
- totalTime: number | null;
715
- position: number | null;
716
- shuffle: NodePyATVShuffleState | null;
717
- repeat: NodePyATVRepeatState | null;
718
- app: string | null;
719
- appId: string | null;
720
- powerState: NodePyATVPowerState | null;
721
- volume: number | null;
708
+ episodeNumber: null | number;
722
709
  focusState: NodePyATVFocusState | null;
710
+ genre: null | string;
711
+ hash: null | string;
712
+ iTunesStoreIdentifier: null | number;
713
+ mediaType: NodePyATVMediaType | null;
723
714
  outputDevices: Array<{
724
- name: string;
725
715
  identifier: string;
716
+ name: string;
726
717
  }> | null;
727
- contentIdentifier: string | null;
728
- iTunesStoreIdentifier: number | null;
729
- episodeNumber: number | null;
730
- seasonNumber: number | null;
731
- seriesName: string | null;
718
+ position: null | number;
719
+ powerState: NodePyATVPowerState | null;
720
+ repeat: NodePyATVRepeatState | null;
721
+ seasonNumber: null | number;
722
+ seriesName: null | string;
723
+ shuffle: NodePyATVShuffleState | null;
724
+ title: null | string;
725
+ totalTime: null | number;
726
+ volume: null | number;
732
727
  }
733
- interface NodePyATVApp {
734
- id: string;
735
- name: string;
736
- launch: () => Promise<void>;
728
+ type NodePyATVStateIndex = keyof NodePyATVState;
729
+ interface NodePyATVVersionResponse {
730
+ module: null | string;
731
+ pyatv: null | string;
737
732
  }
738
733
 
739
734
  declare class NodePyATVDeviceEvent {
740
- protected readonly values: {
741
- key: NodePyATVStateIndex;
742
- old: NodePyATVEventValueType;
743
- new: NodePyATVEventValueType;
744
- device: NodePyATVDevice;
745
- };
746
735
  /**
747
- *
748
- * @param values
749
- * @internal
736
+ * References the device instance this
737
+ * event originates from
750
738
  */
751
- constructor(values: {
752
- key: NodePyATVStateIndex;
753
- old: NodePyATVEventValueType;
754
- new: NodePyATVEventValueType;
755
- device: NodePyATVDevice;
756
- });
739
+ get device(): NodePyATVDevice;
757
740
  /**
758
741
  * References the attribute name which was changed. So if the
759
742
  * title has been updated, this would be `title`.
760
743
  */
761
744
  get key(): NodePyATVStateIndex;
745
+ /**
746
+ * @alias value
747
+ */
748
+ get newValue(): NodePyATVEventValueType;
762
749
  /**
763
750
  * Holds the old value which was there
764
751
  * before the value was changed.
765
752
  */
766
753
  get oldValue(): NodePyATVEventValueType;
767
- /**
768
- * @alias value
769
- */
770
- get newValue(): NodePyATVEventValueType;
771
754
  /**
772
755
  * New, current value for `key`
773
756
  */
774
757
  get value(): NodePyATVEventValueType;
758
+ protected readonly values: {
759
+ device: NodePyATVDevice;
760
+ key: NodePyATVStateIndex;
761
+ new: NodePyATVEventValueType;
762
+ old: NodePyATVEventValueType;
763
+ };
775
764
  /**
776
- * References the device instance this
777
- * event originates from
765
+ *
766
+ * @param values
767
+ * @internal
778
768
  */
779
- get device(): NodePyATVDevice;
769
+ constructor(values: {
770
+ device: NodePyATVDevice;
771
+ key: NodePyATVStateIndex;
772
+ new: NodePyATVEventValueType;
773
+ old: NodePyATVEventValueType;
774
+ });
780
775
  }
781
776
 
782
777
  /**
783
778
  * @internal
784
779
  */
785
780
  declare class NodePyATVDeviceEvents extends EventEmitter {
786
- private readonly options;
787
- private readonly state;
788
781
  private readonly device;
782
+ private listenerState;
783
+ private readonly options;
789
784
  private pyatv;
785
+ private readonly state;
790
786
  private timeout;
791
- private listenerState;
792
787
  constructor(state: NodePyATVState, device: NodePyATVDevice, options: NodePyATVDeviceOptions);
793
- applyStateAndEmitEvents(newState: NodePyATVState): void;
794
- private parsePushUpdate;
795
- private applyPushUpdate;
796
- private checkListener;
797
- private startListening;
798
- protected stopListening(reqId: string): Promise<void>;
799
788
  addListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
789
+ applyStateAndEmitEvents(newState: NodePyATVState): void;
790
+ listenerCount(event?: string | symbol): number;
791
+ off(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
800
792
  on(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
801
793
  once(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
802
794
  prependListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
803
- off(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
804
795
  removeAllListeners(event?: string | symbol): this;
805
796
  removeListener(event: string | symbol, listener: (event: NodePyATVDeviceEvent) => void): this;
806
- listenerCount(event?: string | symbol): number;
797
+ protected stopListening(reqId: string): Promise<void>;
798
+ private applyPushUpdate;
799
+ private checkListener;
800
+ private parsePushUpdate;
801
+ private startListening;
807
802
  }
808
803
 
809
804
  /**
@@ -816,6 +811,19 @@ declare class NodePyATVDeviceEvents extends EventEmitter {
816
811
  */
817
812
  declare class NodePyATVInstance {
818
813
  private readonly options;
814
+ /**
815
+ * Use this to apply [[NodePyATVInstanceOptions]]
816
+ * (e.g. debug log method) to all further requests
817
+ *
818
+ * ```typescript
819
+ * import pyatv from '@sebbo2002/node-pyatv';
820
+ * const myPyatv = new pyatv({debug: true});
821
+ * const devices = myPyatv.find();
822
+ * console.log(devices);
823
+ * ```
824
+ * @param options
825
+ */
826
+ constructor(options?: NodePyATVInstanceOptions);
819
827
  /**
820
828
  * Checks if pyatv is installed and ready to be used.
821
829
  * Will throw an error if not.
@@ -824,12 +832,12 @@ declare class NodePyATVInstance {
824
832
  */
825
833
  static check(options?: NodePyATVInstanceOptions): Promise<void>;
826
834
  /**
827
- * Resolves with the version of pyatv and of the module itself.
828
- * If a value can't be found, null is returned instead.
835
+ * Create a [[NodePyATVDevice]] to query the state and control it.
836
+ * At least `host` and `name` are required.
829
837
  *
830
838
  * @param options
831
839
  */
832
- static version(options?: NodePyATVInstanceOptions): Promise<NodePyATVVersionResponse>;
840
+ static device(options: NodePyATVDeviceOptions): NodePyATVDevice;
833
841
  /**
834
842
  * Scan the network for Apple TVs by using pyatv's atvscript. See [[NodePyATVFindAndInstanceOptions]]
835
843
  * for the options allowed. Use the `host` / `hosts` attribute to filter by IP addresses. Resolves with
@@ -855,25 +863,12 @@ declare class NodePyATVInstance {
855
863
  static find(options?: NodePyATVFindAndInstanceOptions): Promise<NodePyATVDevice[]>;
856
864
  static find(options: NodePyATVFindAndInstanceOptions, returnDevicesAndErrors: true): Promise<NodePyATVFindResponseObject>;
857
865
  /**
858
- * Create a [[NodePyATVDevice]] to query the state and control it.
859
- * At least `host` and `name` are required.
860
- *
861
- * @param options
862
- */
863
- static device(options: NodePyATVDeviceOptions): NodePyATVDevice;
864
- /**
865
- * Use this to apply [[NodePyATVInstanceOptions]]
866
- * (e.g. debug log method) to all further requests
866
+ * Resolves with the version of pyatv and of the module itself.
867
+ * If a value can't be found, null is returned instead.
867
868
  *
868
- * ```typescript
869
- * import pyatv from '@sebbo2002/node-pyatv';
870
- * const myPyatv = new pyatv({debug: true});
871
- * const devices = myPyatv.find();
872
- * console.log(devices);
873
- * ```
874
869
  * @param options
875
870
  */
876
- constructor(options?: NodePyATVInstanceOptions);
871
+ static version(options?: NodePyATVInstanceOptions): Promise<NodePyATVVersionResponse>;
877
872
  /**
878
873
  * Checks if pyatv is installed and ready to be used.
879
874
  * Will throw an error if not.
@@ -882,12 +877,12 @@ declare class NodePyATVInstance {
882
877
  */
883
878
  check(options?: NodePyATVInstanceOptions): Promise<void>;
884
879
  /**
885
- * Resolves with the version of pyatv and of the module itself.
886
- * If a value can't be found, null is returned instead.
880
+ * Create a [[NodePyATVDevice]] to query the state and control it.
881
+ * At least `host` and `name` are required.
887
882
  *
888
883
  * @param options
889
884
  */
890
- version(options?: NodePyATVInstanceOptions): Promise<NodePyATVVersionResponse>;
885
+ device(options: NodePyATVDeviceOptions): NodePyATVDevice;
891
886
  /**
892
887
  * Scan the network for Apple TVs by using pyatv's atvscript. See [[NodePyATVFindAndInstanceOptions]]
893
888
  * for the options allowed. Use the `host` / `hosts` attribute to filter by IP addresses. Resolves with
@@ -904,12 +899,12 @@ declare class NodePyATVInstance {
904
899
  */
905
900
  find(options?: NodePyATVFindAndInstanceOptions): Promise<NodePyATVDevice[]>;
906
901
  /**
907
- * Create a [[NodePyATVDevice]] to query the state and control it.
908
- * At least `host` and `name` are required.
902
+ * Resolves with the version of pyatv and of the module itself.
903
+ * If a value can't be found, null is returned instead.
909
904
  *
910
905
  * @param options
911
906
  */
912
- device(options: NodePyATVDeviceOptions): NodePyATVDevice;
907
+ version(options?: NodePyATVInstanceOptions): Promise<NodePyATVVersionResponse>;
913
908
  }
914
909
 
915
910
  export { NodePyATVDevice, NodePyATVDeviceEvent, NodePyATVDeviceEvents, type NodePyATVDeviceOptions, NodePyATVDeviceState, type NodePyATVEventValueType, NodePyATVExecutableType, type NodePyATVFindAndInstanceOptions, type NodePyATVFindOptions, type NodePyATVFindResponseObject, type NodePyATVGetStateOptions, NodePyATVInstance, type NodePyATVInstanceOptions, NodePyATVKeys, NodePyATVListenerState, NodePyATVMediaType, NodePyATVPowerState, NodePyATVProtocol, NodePyATVRepeatState, type NodePyATVRequestOptions, type NodePyATVService, NodePyATVShuffleState, type NodePyATVState, type NodePyATVVersionResponse, NodePyATVInstance as default };