@sebbo2002/node-pyatv 6.0.0-develop.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/bin/check.cjs +10 -0
  2. package/dist/bin/check.cjs.map +1 -0
  3. package/dist/bin/check.d.ts +2 -1
  4. package/dist/bin/check.js +4 -45
  5. package/dist/bin/check.js.map +1 -1
  6. package/dist/chunk-TZSWUAOB.js +7 -0
  7. package/dist/chunk-TZSWUAOB.js.map +1 -0
  8. package/dist/lib/index.cjs +7 -0
  9. package/dist/lib/index.cjs.map +1 -0
  10. package/dist/lib/{device.d.ts → index.d.cts} +340 -4
  11. package/dist/lib/index.d.ts +806 -6
  12. package/dist/lib/index.js +1 -7
  13. package/dist/lib/index.js.map +1 -1
  14. package/package.json +18 -9
  15. package/.editorconfig +0 -12
  16. package/.eslintignore +0 -4
  17. package/.eslintrc +0 -60
  18. package/.mocharc.yml +0 -7
  19. package/.nycrc +0 -32
  20. package/CHANGELOG.md +0 -295
  21. package/check.sh +0 -5
  22. package/dist/examples/push.d.ts +0 -1
  23. package/dist/examples/push.js +0 -51
  24. package/dist/examples/push.js.map +0 -1
  25. package/dist/lib/device-event.d.ts +0 -44
  26. package/dist/lib/device-event.js +0 -47
  27. package/dist/lib/device-event.js.map +0 -1
  28. package/dist/lib/device-events.d.ts +0 -30
  29. package/dist/lib/device-events.js +0 -237
  30. package/dist/lib/device-events.js.map +0 -1
  31. package/dist/lib/device.js +0 -793
  32. package/dist/lib/device.js.map +0 -1
  33. package/dist/lib/fake-spawn.d.ts +0 -43
  34. package/dist/lib/fake-spawn.js +0 -85
  35. package/dist/lib/fake-spawn.js.map +0 -1
  36. package/dist/lib/instance.d.ts +0 -97
  37. package/dist/lib/instance.js +0 -208
  38. package/dist/lib/instance.js.map +0 -1
  39. package/dist/lib/tools.d.ts +0 -12
  40. package/dist/lib/tools.js +0 -319
  41. package/dist/lib/tools.js.map +0 -1
  42. package/dist/lib/types.d.ts +0 -204
  43. package/dist/lib/types.js +0 -108
  44. package/dist/lib/types.js.map +0 -1
  45. package/docs/coverage/base.css +0 -224
  46. package/docs/coverage/block-navigation.js +0 -87
  47. package/docs/coverage/cobertura-coverage.xml +0 -2889
  48. package/docs/coverage/device-event.ts.html +0 -256
  49. package/docs/coverage/device-events.ts.html +0 -970
  50. package/docs/coverage/device.ts.html +0 -2518
  51. package/docs/coverage/fake-spawn.ts.html +0 -448
  52. package/docs/coverage/favicon.png +0 -0
  53. package/docs/coverage/index.html +0 -221
  54. package/docs/coverage/index.ts.html +0 -172
  55. package/docs/coverage/instance.ts.html +0 -718
  56. package/docs/coverage/prettify.css +0 -1
  57. package/docs/coverage/prettify.js +0 -2
  58. package/docs/coverage/sort-arrow-sprite.png +0 -0
  59. package/docs/coverage/sorter.js +0 -196
  60. package/docs/coverage/tools.ts.html +0 -1222
  61. package/docs/coverage/types.ts.html +0 -775
  62. package/docs/reference/.nojekyll +0 -1
  63. package/docs/reference/assets/highlight.css +0 -99
  64. package/docs/reference/assets/main.js +0 -58
  65. package/docs/reference/assets/search.js +0 -1
  66. package/docs/reference/assets/style.css +0 -1280
  67. package/docs/reference/classes/NodePyATVDevice.html +0 -1266
  68. package/docs/reference/classes/NodePyATVDeviceEvent.html +0 -123
  69. package/docs/reference/classes/NodePyATVInstance.html +0 -240
  70. package/docs/reference/enums/NodePyATVDeviceState.html +0 -97
  71. package/docs/reference/enums/NodePyATVExecutableType.html +0 -69
  72. package/docs/reference/enums/NodePyATVKeys.html +0 -216
  73. package/docs/reference/enums/NodePyATVListenerState.html +0 -83
  74. package/docs/reference/enums/NodePyATVMediaType.html +0 -83
  75. package/docs/reference/enums/NodePyATVPowerState.html +0 -69
  76. package/docs/reference/enums/NodePyATVProtocol.html +0 -83
  77. package/docs/reference/enums/NodePyATVRepeatState.html +0 -76
  78. package/docs/reference/enums/NodePyATVShuffleState.html +0 -76
  79. package/docs/reference/index.html +0 -139
  80. package/docs/reference/interfaces/NodePyATVDeviceOptions.html +0 -232
  81. package/docs/reference/interfaces/NodePyATVFindAndInstanceOptions.html +0 -193
  82. package/docs/reference/interfaces/NodePyATVFindOptions.html +0 -124
  83. package/docs/reference/interfaces/NodePyATVGetStateOptions.html +0 -66
  84. package/docs/reference/interfaces/NodePyATVInstanceOptions.html +0 -113
  85. package/docs/reference/interfaces/NodePyATVService.html +0 -73
  86. package/docs/reference/interfaces/NodePyATVState.html +0 -164
  87. package/docs/reference/interfaces/NodePyATVVersionResponse.html +0 -73
  88. package/docs/reference/modules.html +0 -106
  89. package/docs/reference/types/NodePyATVEventValueType.html +0 -66
  90. package/docs/tests/assets/MaterialIcons-Regular.woff +0 -0
  91. package/docs/tests/assets/MaterialIcons-Regular.woff2 +0 -0
  92. package/docs/tests/assets/app.css +0 -14
  93. package/docs/tests/assets/app.js +0 -2
  94. package/docs/tests/assets/app.js.LICENSE.txt +0 -55
  95. package/docs/tests/assets/roboto-light-webfont.woff +0 -0
  96. package/docs/tests/assets/roboto-light-webfont.woff2 +0 -0
  97. package/docs/tests/assets/roboto-medium-webfont.woff +0 -0
  98. package/docs/tests/assets/roboto-medium-webfont.woff2 +0 -0
  99. package/docs/tests/assets/roboto-regular-webfont.woff +0 -0
  100. package/docs/tests/assets/roboto-regular-webfont.woff2 +0 -0
  101. package/docs/tests/index.html +0 -2
  102. package/docs/tests/mochawesome.json +0 -4823
  103. package/release.config.cjs +0 -51
  104. package/src/bin/check.ts +0 -41
  105. package/src/examples/push.ts +0 -46
  106. package/src/lib/device-event.ts +0 -57
  107. package/src/lib/device-events.ts +0 -295
  108. package/src/lib/device.ts +0 -811
  109. package/src/lib/fake-spawn.ts +0 -121
  110. package/src/lib/index.ts +0 -29
  111. package/src/lib/instance.ts +0 -211
  112. package/src/lib/tools.ts +0 -379
  113. package/src/lib/types.ts +0 -230
  114. package/test/device-event.ts +0 -88
  115. package/test/device-events.ts +0 -502
  116. package/test/device.ts +0 -826
  117. package/test/instance.ts +0 -428
  118. package/test/tools.ts +0 -301
  119. package/tsconfig.json +0 -19
  120. package/typedoc.json +0 -15
package/test/device.ts DELETED
@@ -1,826 +0,0 @@
1
- 'use strict';
2
-
3
- import assert from 'assert';
4
- import NodePyATVDevice from '../src/lib/device.js';
5
- import {
6
- NodePyATVDeviceState,
7
- NodePyATVKeys,
8
- NodePyATVMediaType,
9
- NodePyATVProtocol,
10
- NodePyATVRepeatState,
11
- NodePyATVShuffleState
12
- } from '../src/lib/types.js';
13
- import NodePyATVInstance from '../src/lib/instance.js';
14
- import { createFakeSpawn } from '../src/lib/fake-spawn.js';
15
-
16
- describe('NodePyATVDevice', function () {
17
- describe('get name()', function () {
18
- it('should return the name', function () {
19
- const device = new NodePyATVDevice({
20
- name: 'My Testdevice',
21
- host: '192.168.178.2'
22
- });
23
-
24
- assert.strictEqual(device.name, 'My Testdevice');
25
- });
26
- });
27
-
28
- describe('get host()', function () {
29
- it('should return the host', function () {
30
- const device = new NodePyATVDevice({
31
- name: 'My Testdevice',
32
- host: '192.168.178.2'
33
- });
34
-
35
- assert.strictEqual(device.host, '192.168.178.2');
36
- });
37
- });
38
-
39
- describe('get id()', function () {
40
- it('should return the id', function () {
41
- const device = new NodePyATVDevice({
42
- name: 'My Testdevice',
43
- host: '192.168.178.2',
44
- id: '*****'
45
- });
46
-
47
- assert.strictEqual(device.id, '*****');
48
- });
49
- });
50
-
51
- describe('get protocol()', function () {
52
- it('should return the protocol', function () {
53
- const device = new NodePyATVDevice({
54
- name: 'My Testdevice',
55
- host: '192.168.178.2',
56
- protocol: NodePyATVProtocol.airplay
57
- });
58
-
59
- assert.strictEqual(device.protocol, NodePyATVProtocol.airplay);
60
- });
61
- });
62
-
63
- describe('get model()', function () {
64
- it('should return the model if set by scan', function () {
65
- const device = new NodePyATVDevice({
66
- name: 'Vardagsrum',
67
- host: '10.0.10.81',
68
- id: 'xxx',
69
- model: 'Gen4K'
70
- });
71
-
72
- assert.strictEqual(device.model, 'Gen4K');
73
- });
74
- it('should return undefined otherwise', function () {
75
- const device = new NodePyATVDevice({
76
- name: 'Vardagsrum',
77
- host: '10.0.10.81'
78
- });
79
-
80
- assert.strictEqual(device.model, undefined);
81
- });
82
- });
83
-
84
- describe('get modelName()', function () {
85
- it('should return the model name if set by scan', function () {
86
- const device = new NodePyATVDevice({
87
- name: 'Vardagsrum',
88
- host: '10.0.10.81',
89
- id: 'xxx',
90
- modelName: 'Apple TV 4K'
91
- });
92
-
93
- assert.strictEqual(device.modelName, 'Apple TV 4K');
94
- });
95
- it('should return undefined otherwise', function () {
96
- const device = new NodePyATVDevice({
97
- name: 'Vardagsrum',
98
- host: '10.0.10.81'
99
- });
100
-
101
- assert.strictEqual(device.modelName, undefined);
102
- });
103
- });
104
-
105
- describe('get os()', function () {
106
- it('should return the operating system if set by scan', function () {
107
- const device = new NodePyATVDevice({
108
- name: 'Vardagsrum',
109
- host: '10.0.10.81',
110
- id: 'xxx',
111
- os: 'TvOS'
112
- });
113
-
114
- assert.strictEqual(device.os, 'TvOS');
115
- });
116
- it('should return undefined otherwise', function () {
117
- const device = new NodePyATVDevice({
118
- name: 'Vardagsrum',
119
- host: '10.0.10.81'
120
- });
121
-
122
- assert.strictEqual(device.os, undefined);
123
- });
124
- });
125
-
126
- describe('get version()', function () {
127
- it('should return the version if set by scan', function () {
128
- const device = new NodePyATVDevice({
129
- name: 'Vardagsrum',
130
- host: '10.0.10.81',
131
- id: 'xxx',
132
- version: '15.5.1'
133
- });
134
-
135
- assert.strictEqual(device.version, '15.5.1');
136
- });
137
- it('should return undefined otherwise', function () {
138
- const device = new NodePyATVDevice({
139
- name: 'Vardagsrum',
140
- host: '10.0.10.81'
141
- });
142
-
143
- assert.strictEqual(device.version, undefined);
144
- });
145
- });
146
-
147
- describe('get services()', function () {
148
- it('should return the services if set by scan', function () {
149
- const device = new NodePyATVDevice({
150
- name: 'Vardagsrum',
151
- host: '10.0.10.81',
152
- id: 'xxx',
153
- services: [
154
- {
155
- protocol: NodePyATVProtocol.mrp,
156
- port: 49152
157
- },
158
- {
159
- protocol: NodePyATVProtocol.airplay,
160
- port: 7000
161
- }
162
- ]
163
- });
164
-
165
- assert.deepStrictEqual(device.services, [
166
- {
167
- protocol: 'mrp',
168
- port: 49152
169
- },
170
- {
171
- protocol: 'airplay',
172
- port: 7000
173
- }
174
- ]);
175
- });
176
- it('should return undefined otherwise', function () {
177
- const device = new NodePyATVDevice({
178
- name: 'Vardagsrum',
179
- host: '10.0.10.81'
180
- });
181
-
182
- assert.strictEqual(device.services, undefined);
183
- });
184
- });
185
-
186
- describe('get debug()', function () {
187
- it('should return true if set to true', function () {
188
- const device = new NodePyATVDevice({
189
- name: 'My Testdevice',
190
- host: '192.168.178.2',
191
- debug: true
192
- });
193
-
194
- assert.strictEqual(device.debug, true);
195
- });
196
- it('should return fn if set to custom function', function () {
197
- // eslint-disable-next-line @typescript-eslint/no-empty-function
198
- const fn = () => {
199
- };
200
-
201
- const device = new NodePyATVDevice({
202
- name: 'My Testdevice',
203
- host: '192.168.178.2',
204
- debug: fn
205
- });
206
-
207
- assert.strictEqual(device.debug, fn);
208
- });
209
- it('should return false if unset', function () {
210
- const device = new NodePyATVDevice({
211
- name: 'My Testdevice',
212
- host: '192.168.178.2'
213
- });
214
-
215
- assert.strictEqual(device.debug, undefined);
216
- });
217
- });
218
-
219
- describe('set debug()', function () {
220
- it('should work for debug = true', function () {
221
- const device = new NodePyATVDevice({
222
- name: 'My Testdevice',
223
- host: '192.168.178.2'
224
- });
225
-
226
- assert.strictEqual(device.debug, undefined);
227
- device.debug = true;
228
- assert.strictEqual(device.debug, true);
229
- });
230
- it('should work for debug = undefined', function () {
231
- const device = new NodePyATVDevice({
232
- name: 'My Testdevice',
233
- host: '192.168.178.2',
234
- debug: true
235
- });
236
-
237
- assert.strictEqual(device.debug, true);
238
- device.debug = undefined;
239
- assert.strictEqual(device.debug, undefined);
240
- });
241
- it('should work for debug = undefined', function () {
242
- const device = new NodePyATVDevice({
243
- name: 'My Testdevice',
244
- host: '192.168.178.2',
245
- debug: true
246
- });
247
-
248
- assert.strictEqual(device.debug, true);
249
- device.debug = undefined;
250
- assert.strictEqual(device.debug, undefined);
251
- });
252
- it('should work for debug = fn', function () {
253
- const device = new NodePyATVDevice({
254
- name: 'My Testdevice',
255
- host: '192.168.178.2'
256
- });
257
-
258
- // eslint-disable-next-line @typescript-eslint/no-empty-function
259
- const fn = () => {
260
- };
261
-
262
- assert.strictEqual(device.debug, undefined);
263
- device.debug = fn;
264
- assert.strictEqual(device.debug, fn);
265
- });
266
- });
267
-
268
- describe('toJSON()', function () {
269
- it('should return a object representation', function () {
270
- const device = new NodePyATVDevice({
271
- name: 'My Testdevice',
272
- host: '192.168.178.2',
273
- id: '*****',
274
- protocol: NodePyATVProtocol.airplay
275
- });
276
-
277
- assert.deepEqual(device.toJSON(), {
278
- name: 'My Testdevice',
279
- host: '192.168.178.2',
280
- id: '*****',
281
- protocol: NodePyATVProtocol.airplay
282
- });
283
- });
284
- it('should be possible to create a new device from this', function () {
285
- const config = {
286
- name: 'My Testdevice',
287
- host: '192.168.178.2',
288
- id: '*****',
289
- protocol: NodePyATVProtocol.airplay
290
- };
291
-
292
- const deviceA = new NodePyATVDevice(config);
293
- const deviceB = new NodePyATVDevice(deviceA.toJSON());
294
- assert.deepEqual(deviceB.toJSON(), config);
295
- });
296
- });
297
-
298
- describe('toString()', function () {
299
- it('should work', function () {
300
- const device = new NodePyATVDevice({
301
- name: 'My Testdevice',
302
- host: '192.168.178.2'
303
- });
304
-
305
- assert.strictEqual(device.toString(), 'NodePyATVDevice(My Testdevice, 192.168.178.2)');
306
- });
307
- });
308
-
309
- describe('getState()', function () {
310
- it('should work [I]', process.env.ENABLE_INTEGRATION ? async function () {
311
- this.timeout(12000);
312
-
313
- const devices = await NodePyATVInstance.find();
314
- assert.ok(devices.length > 0, 'Device(s) found');
315
-
316
- const device = devices[0];
317
- await device.getState();
318
- } : undefined);
319
- it('should work', async function () {
320
- const device = new NodePyATVDevice({
321
- name: 'My Testdevice',
322
- host: '192.168.178.2',
323
- spawn: createFakeSpawn(cp => {
324
- cp.end({
325
- result: 'success',
326
- datetime: '2020-11-07T22:38:43.608030+01:00',
327
- hash: '100e0ab6-6ff5-4199-9c04-a7107ff78712',
328
- media_type: 'video',
329
- device_state: 'playing',
330
- title: 'Solo: A Star Wars Story',
331
- artist: null,
332
- album: null,
333
- genre: null,
334
- total_time: 8097,
335
- position: 27,
336
- shuffle: 'off',
337
- repeat: 'off',
338
- app: 'Disney+',
339
- app_id: 'com.disney.disneyplus'
340
- });
341
- })
342
- });
343
-
344
- const result = await device.getState();
345
- assert.deepStrictEqual(result, {
346
- dateTime: new Date('2020-11-07T22:38:43.608030+01:00'),
347
- hash: '100e0ab6-6ff5-4199-9c04-a7107ff78712',
348
- mediaType: NodePyATVMediaType.video,
349
- deviceState: NodePyATVDeviceState.playing,
350
- title: 'Solo: A Star Wars Story',
351
- artist: null,
352
- album: null,
353
- genre: null,
354
- totalTime: 8097,
355
- position: 27,
356
- shuffle: NodePyATVShuffleState.off,
357
- repeat: NodePyATVRepeatState.off,
358
- app: 'Disney+',
359
- appId: 'com.disney.disneyplus',
360
- powerState: null
361
- });
362
- });
363
- it('should reject with error if pyatv fails', async function () {
364
- const device = new NodePyATVDevice({
365
- name: 'My Testdevice',
366
- host: '192.168.178.2',
367
- spawn: createFakeSpawn(cp => {
368
- cp.end({
369
- result: 'failure',
370
- datetime: '2021-11-24T21:13:36.424576+03:00',
371
- exception: 'invalid credentials: 321',
372
- stacktrace: 'Traceback (most recent call last):\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/scripts/atvscript.py\", line 302, in appstart\n print(args.output(await _handle_command(args, abort_sem, loop)), flush=True)\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/scripts/atvscript.py\", line 196, in _handle_command\n atv = await connect(config, loop, protocol=Protocol.MRP)\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/__init__.py\", line 96, in connect\n for setup_data in proto_methods.setup(\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/protocols/airplay/__init__.py\", line 192, in setup\n stream = AirPlayStream(config, service)\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/protocols/airplay/__init__.py\", line 79, in __init__\n self._credentials: HapCredentials = parse_credentials(self.service.credentials)\n File \"/Users/free/Library/Python/3.8/lib/python/site-packages/pyatv/auth/hap_pairing.py\", line 139, in parse_credentials\n raise exceptions.InvalidCredentialsError(\"invalid credentials: \" + detail_string)\npyatv.exceptions.InvalidCredentialsError: invalid credentials: 321\n'
373
- });
374
- })
375
- });
376
-
377
- assert.rejects(async () => {
378
- await device.getState();
379
- }, /Got pyatv Error: invalid credentials: 321/);
380
- });
381
- it('should cache requests for a bit', async function () {
382
- let executions = 0;
383
- const device = new NodePyATVDevice({
384
- name: 'My Testdevice',
385
- host: '192.168.178.2',
386
- spawn: createFakeSpawn(cp => {
387
- executions++;
388
- cp.end({
389
- result: 'success',
390
- datetime: new Date().toJSON(),
391
- hash: '100e0ab6-6ff5-4199-9c04-a7107ff78712',
392
- media_type: 'video',
393
- device_state: 'playing',
394
- title: 'Solo: A Star Wars Story',
395
- artist: null,
396
- album: null,
397
- genre: null,
398
- total_time: 8097,
399
- position: 27,
400
- shuffle: 'off',
401
- repeat: 'off',
402
- app: 'Disney+',
403
- app_id: 'com.disney.disneyplus'
404
- });
405
- })
406
- });
407
-
408
- const firstResult = await device.getState();
409
- const secondResult = await device.getState();
410
-
411
- assert.strictEqual(firstResult.dateTime, secondResult.dateTime);
412
- assert.strictEqual(executions, 1);
413
- });
414
- it('should update the position if cache was used', async function () {
415
- const device = new NodePyATVDevice({
416
- name: 'My Testdevice',
417
- host: '192.168.178.2',
418
- spawn: createFakeSpawn(cp => {
419
- cp.end({
420
- result: 'success',
421
- datetime: new Date(new Date().getTime() - 1000).toJSON(),
422
- hash: '100e0ab6-6ff5-4199-9c04-a7107ff78712',
423
- media_type: 'video',
424
- device_state: 'playing',
425
- title: 'Solo: A Star Wars Story',
426
- artist: null,
427
- album: null,
428
- genre: null,
429
- total_time: 8097,
430
- position: 27,
431
- shuffle: 'off',
432
- repeat: 'off',
433
- app: 'Disney+',
434
- app_id: 'com.disney.disneyplus'
435
- });
436
- })
437
- });
438
-
439
- const firstResult = await device.getState();
440
- assert.strictEqual(firstResult.position, 27);
441
-
442
- const secondResult = await device.getState();
443
- assert.ok(secondResult.position);
444
- assert.ok(secondResult.position > 27, `Position should be > 27, was ${secondResult.position}`);
445
- assert.ok(secondResult.position < 30, `Position should be > 27, was ${secondResult.position}`);
446
- });
447
- });
448
-
449
- describe('clearState()', function () {
450
- it('should work', async function () {
451
- let executions = 0;
452
- const device = new NodePyATVDevice({
453
- name: 'My Testdevice',
454
- host: '192.168.178.2',
455
- spawn: createFakeSpawn(cp => {
456
- executions++;
457
- cp.end({
458
- result: 'success',
459
- datetime: '2020-11-07T22:38:43.608030+01:00',
460
- title: 'Solo: A Star Wars Story'
461
- });
462
- })
463
- });
464
-
465
- assert.deepStrictEqual(await device.getTitle(), 'Solo: A Star Wars Story');
466
-
467
- device.clearState();
468
- assert.deepStrictEqual(await device.getTitle(), 'Solo: A Star Wars Story');
469
- assert.strictEqual(executions, 2);
470
- });
471
- });
472
-
473
- describe('getDateTime()', function () {
474
- it('should work', async function () {
475
- const device = new NodePyATVDevice({
476
- name: 'My Testdevice',
477
- host: '192.168.178.2',
478
- spawn: createFakeSpawn(cp => {
479
- cp.end({
480
- result: 'success',
481
- datetime: new Date().toJSON()
482
- });
483
- })
484
- });
485
-
486
- const result = await device.getDateTime();
487
- assert.ok(result instanceof Date);
488
- });
489
- });
490
-
491
- describe('getHash()', function () {
492
- it('should work', async function () {
493
- const device = new NodePyATVDevice({
494
- name: 'My Testdevice',
495
- host: '192.168.178.2',
496
- spawn: createFakeSpawn(cp => {
497
- cp.end({
498
- result: 'success',
499
- hash: '12345'
500
- });
501
- })
502
- });
503
-
504
- const result = await device.getHash();
505
- assert.strictEqual(result, '12345');
506
- });
507
- });
508
-
509
- describe('getMediaType()', function () {
510
- it('should work', async function () {
511
- const device = new NodePyATVDevice({
512
- name: 'My Testdevice',
513
- host: '192.168.178.2',
514
- spawn: createFakeSpawn(cp => {
515
- cp.end({
516
- result: 'success',
517
- media_type: 'video'
518
- });
519
- })
520
- });
521
-
522
- const result = await device.getMediaType();
523
- assert.deepStrictEqual(result, NodePyATVMediaType.video);
524
- assert.deepStrictEqual(result, 'video');
525
- });
526
- });
527
-
528
- describe('getDeviceState()', function () {
529
- it('should work', async function () {
530
- const device = new NodePyATVDevice({
531
- name: 'My Testdevice',
532
- host: '192.168.178.2',
533
- spawn: createFakeSpawn(cp => {
534
- cp.end({
535
- result: 'success',
536
- device_state: 'seeking'
537
- });
538
- })
539
- });
540
-
541
- const result = await device.getDeviceState();
542
- assert.deepStrictEqual(result, NodePyATVDeviceState.seeking);
543
- assert.deepStrictEqual(result, 'seeking');
544
- });
545
- });
546
-
547
- describe('getTitle()', function () {
548
- it('should work', async function () {
549
- const device = new NodePyATVDevice({
550
- name: 'My Testdevice',
551
- host: '192.168.178.2',
552
- spawn: createFakeSpawn(cp => {
553
- cp.end({
554
- result: 'success',
555
- title: 'My Movie'
556
- });
557
- })
558
- });
559
-
560
- const result = await device.getTitle();
561
- assert.strictEqual(result, 'My Movie');
562
- });
563
- });
564
-
565
- describe('getArtist()', function () {
566
- it('should work', async function () {
567
- const device = new NodePyATVDevice({
568
- name: 'My Testdevice',
569
- host: '192.168.178.2',
570
- spawn: createFakeSpawn(cp => {
571
- cp.end({
572
- result: 'success',
573
- artist: 'My Artist'
574
- });
575
- })
576
- });
577
-
578
- const result = await device.getArtist();
579
- assert.strictEqual(result, 'My Artist');
580
- });
581
- });
582
-
583
- describe('getAlbum()', function () {
584
- it('should work', async function () {
585
- const device = new NodePyATVDevice({
586
- name: 'My Testdevice',
587
- host: '192.168.178.2',
588
- spawn: createFakeSpawn(cp => {
589
- cp.end({
590
- result: 'success',
591
- album: 'My ALbum'
592
- });
593
- })
594
- });
595
-
596
- const result = await device.getAlbum();
597
- assert.strictEqual(result, 'My ALbum');
598
- });
599
- });
600
-
601
- describe('getGenre()', function () {
602
- it('should work', async function () {
603
- const device = new NodePyATVDevice({
604
- name: 'My Testdevice',
605
- host: '192.168.178.2',
606
- spawn: createFakeSpawn(cp => {
607
- cp.end({
608
- result: 'success',
609
- genre: 'My Genre'
610
- });
611
- })
612
- });
613
-
614
- const result = await device.getGenre();
615
- assert.strictEqual(result, 'My Genre');
616
- });
617
- });
618
-
619
- describe('getTotalTime()', function () {
620
- it('should work', async function () {
621
- const device = new NodePyATVDevice({
622
- name: 'My Testdevice',
623
- host: '192.168.178.2',
624
- spawn: createFakeSpawn(cp => {
625
- cp.end({
626
- result: 'success',
627
- total_time: 45
628
- });
629
- })
630
- });
631
-
632
- const result = await device.getTotalTime();
633
- assert.strictEqual(result, 45);
634
- });
635
- });
636
-
637
- describe('getPosition()', function () {
638
- it('should work', async function () {
639
- const device = new NodePyATVDevice({
640
- name: 'My Testdevice',
641
- host: '192.168.178.2',
642
- spawn: createFakeSpawn(cp => {
643
- cp.end({
644
- result: 'success',
645
- position: 30
646
- });
647
- })
648
- });
649
-
650
- const result = await device.getPosition();
651
- assert.strictEqual(result, 30);
652
- });
653
- });
654
-
655
- describe('getShuffle()', function () {
656
- it('should work', async function () {
657
- const device = new NodePyATVDevice({
658
- name: 'My Testdevice',
659
- host: '192.168.178.2',
660
- spawn: createFakeSpawn(cp => {
661
- cp.end({
662
- result: 'success',
663
- shuffle: 'songs'
664
- });
665
- })
666
- });
667
-
668
- const result = await device.getShuffle();
669
- assert.deepStrictEqual(result, NodePyATVShuffleState.songs);
670
- assert.deepStrictEqual(result, 'songs');
671
- });
672
- });
673
-
674
- describe('getRepeat()', function () {
675
- it('should work', async function () {
676
- const device = new NodePyATVDevice({
677
- name: 'My Testdevice',
678
- host: '192.168.178.2',
679
- spawn: createFakeSpawn(cp => {
680
- cp.end({
681
- result: 'success',
682
- repeat: 'all'
683
- });
684
- })
685
- });
686
-
687
- const result = await device.getRepeat();
688
- assert.deepStrictEqual(result, NodePyATVRepeatState.all);
689
- assert.deepStrictEqual(result, 'all');
690
- });
691
- });
692
-
693
- describe('getApp()', function () {
694
- it('should work', async function () {
695
- const device = new NodePyATVDevice({
696
- name: 'My Testdevice',
697
- host: '192.168.178.2',
698
- spawn: createFakeSpawn(cp => {
699
- cp.end({
700
- result: 'success',
701
- app: 'My App'
702
- });
703
- })
704
- });
705
-
706
- const result = await device.getApp();
707
- assert.strictEqual(result, 'My App');
708
- });
709
- });
710
-
711
- describe('getAppId()', function () {
712
- it('should work', async function () {
713
- const device = new NodePyATVDevice({
714
- name: 'My Testdevice',
715
- host: '192.168.178.2',
716
- spawn: createFakeSpawn(cp => {
717
- cp.end({
718
- result: 'success',
719
- app_id: 'app.example.com'
720
- });
721
- })
722
- });
723
-
724
- const result = await device.getAppId();
725
- assert.strictEqual(result, 'app.example.com');
726
- });
727
- });
728
-
729
- describe('listApps()', function () {
730
- it('should work', async function () {
731
- const device = new NodePyATVDevice({
732
- name: 'My Testdevice',
733
- host: '192.168.178.2',
734
- spawn: createFakeSpawn(cp => {
735
- cp.end(
736
- 'App: Fitness (com.apple.Fitness), App: Podcasts (com.apple.podcasts), ' +
737
- 'App: Filme (com.apple.TVMovies), App: Prime Video (com.amazon.aiv.AIVApp), ' +
738
- 'App: TV (com.apple.TVWatchList), App: Fotos (com.apple.TVPhotos), App: App Store ' +
739
- '(com.apple.TVAppStore), App: Arcade (com.apple.Arcade), App: TV-Sendungen (com.apple.TVShows), ' +
740
- 'App: Suchen (com.apple.TVSearch), App: Live TV (de.couchfunk.WM2014), App: RTL+ ' +
741
- '(com.rtlinteractive.tvnow), App: Computer (com.apple.TVHomeSharing), App: ARTE ' +
742
- '(tv.arte.plus7), App: YouTube (com.google.ios.youtube), App: ARD Mediathek ' +
743
- '(de.swr.avp.ard.tablet), App: Disney+ (com.disney.disneyplus), App: Plex (com.plexapp.plex), ' +
744
- 'App: Joyn (de.prosiebensat1digital.seventv), App: Einstellungen (com.apple.TVSettings), ' +
745
- 'App: ZDFmediathek (de.zdf.mediathek.universal), App: Crossy Road (com.hipsterwhale.crossy), ' +
746
- 'App: Netflix (com.netflix.Netflix), App: Infuse (com.firecore.infuse), ' +
747
- 'App: Musik (com.apple.TVMusic)');
748
- })
749
- });
750
-
751
- const result = await device.listApps();
752
- assert.strictEqual(result.length, 25);
753
- assert.strictEqual(result[0].id, 'com.apple.Fitness');
754
- assert.strictEqual(result[0].name, 'Fitness');
755
- });
756
- });
757
-
758
- describe('pressKey()', function () {
759
- it('should work with valid key', async function () {
760
- const device = new NodePyATVDevice({
761
- name: 'My Testdevice',
762
- host: '192.168.178.2',
763
- spawn: createFakeSpawn(cp => {
764
- cp.end('{"result":"success"}');
765
- })
766
- });
767
-
768
- await device.pressKey(NodePyATVKeys.home);
769
- });
770
- it('should throw error with invalid key', async function () {
771
- const device = new NodePyATVDevice({
772
- name: 'My Testdevice',
773
- host: '192.168.178.2'
774
- });
775
-
776
- await assert.rejects(async () => {
777
- // @ts-ignore
778
- await device.pressKey('foo');
779
- }, /Unsupported key value foo/);
780
- });
781
- it('should throw error if pyatv result is not success', async function () {
782
- const device = new NodePyATVDevice({
783
- name: 'My Testdevice',
784
- host: '192.168.178.2',
785
- spawn: createFakeSpawn(cp => {
786
- cp.end('{"result":"failure"}');
787
- })
788
- });
789
-
790
- await assert.rejects(async () => {
791
- await device.pressKey(NodePyATVKeys.home);
792
- }, /Unable to parse pyatv response/);
793
- });
794
- });
795
-
796
- Object.keys(NodePyATVKeys).forEach(key => {
797
- describe(key + '()', function () {
798
- it('should work', async function () {
799
- const device = new NodePyATVDevice({
800
- name: 'My Testdevice',
801
- host: '192.168.178.2',
802
- spawn: createFakeSpawn(cp => {
803
- cp.end('{"result":"success"}');
804
- })
805
- });
806
-
807
- // @ts-ignore
808
- await device[key]();
809
- });
810
- });
811
- });
812
-
813
- describe('launchApp()', function () {
814
- it('should work', async function () {
815
- const device = new NodePyATVDevice({
816
- name: 'My Testdevice',
817
- host: '192.168.178.2',
818
- spawn: createFakeSpawn(cp => {
819
- cp.end('');
820
- })
821
- });
822
-
823
- await device.launchApp('com.apple.TVShows');
824
- });
825
- });
826
- });