@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
@@ -1,502 +0,0 @@
1
- 'use strict';
2
-
3
- import assert from 'assert';
4
- import {createFakeSpawn} from '../src/lib/fake-spawn.js';
5
- import {NodePyATVDeviceEvent, NodePyATVPowerState, NodePyATVDevice} from '../src/lib/index.js';
6
-
7
- describe('NodePyATVDeviceEvents', function () {
8
- describe('applyStateAndEmitEvents()', function () {
9
- it('should emit update:key event', async function () {
10
- const device = new NodePyATVDevice({
11
- name: 'My Testdevice',
12
- host: '192.168.178.2',
13
- spawn: createFakeSpawn(cp => {
14
- cp.onStdIn(() => cp.end());
15
- cp.stdout({
16
- result: 'success',
17
- title: 'My Movie'
18
- });
19
- })
20
- });
21
-
22
- await new Promise(cb => {
23
- device.once('update:title', event => {
24
- assert.ok(event instanceof NodePyATVDeviceEvent);
25
- assert.strictEqual(event.key, 'title');
26
- assert.strictEqual(event.oldValue, null);
27
- assert.strictEqual(event.newValue, 'My Movie');
28
- assert.strictEqual(event.value, 'My Movie');
29
- assert.deepStrictEqual(event.device, device);
30
- cb(undefined);
31
- });
32
- });
33
- });
34
- it('should emit update event', async function () {
35
- const device = new NodePyATVDevice({
36
- name: 'My Testdevice',
37
- host: '192.168.178.2',
38
- spawn: createFakeSpawn(cp => {
39
- cp.onStdIn(() => cp.end());
40
- cp.stdout({
41
- result: 'success',
42
- title: 'My Movie'
43
- });
44
- })
45
- });
46
-
47
- await new Promise(cb => {
48
- device.once('update', event => {
49
- assert.ok(event instanceof NodePyATVDeviceEvent);
50
- assert.strictEqual(event.key, 'title');
51
- assert.strictEqual(event.oldValue, null);
52
- assert.strictEqual(event.newValue, 'My Movie');
53
- assert.strictEqual(event.value, 'My Movie');
54
- assert.deepStrictEqual(event.device, device);
55
- cb(undefined);
56
- });
57
- });
58
- });
59
- it('should emit update:key event before update', async function () {
60
- const device = new NodePyATVDevice({
61
- name: 'My Testdevice',
62
- host: '192.168.178.2',
63
- spawn: createFakeSpawn(cp => {
64
- cp.onStdIn(() => cp.end());
65
- cp.stdout({
66
- result: 'success',
67
- title: 'My Movie'
68
- });
69
- })
70
- });
71
-
72
- const sort: string[] = [];
73
- await Promise.race([
74
- new Promise(cb => {
75
- device.once('update', () => {
76
- sort.push('update');
77
- cb(undefined);
78
- });
79
- }),
80
- new Promise(cb => {
81
- device.once('update:title', () => {
82
- sort.push('update:title');
83
- cb(undefined);
84
- });
85
- })
86
- ]);
87
-
88
- assert.deepStrictEqual(sort, ['update:title', 'update']);
89
- });
90
- it('should emit error events on failures', async function () {
91
- const device = new NodePyATVDevice({
92
- name: 'My Testdevice',
93
- host: '192.168.178.2',
94
- spawn: createFakeSpawn(cp => {
95
- cp.onStdIn(() => cp.end());
96
- cp.stdout({
97
- result: 'failure',
98
- datetime: '2021-11-24T21:13:36.424576+03:00',
99
- exception: 'invalid credentials: 321',
100
- 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'
101
- });
102
- })
103
- });
104
-
105
- await new Promise(cb => {
106
- device.once('error', error => {
107
- assert.ok(error instanceof Error);
108
- assert.ok(error.toString().includes('invalid credentials: 321'));
109
- cb(undefined);
110
- });
111
- });
112
- });
113
- it('should not emit an update if new value is same as old one', async function () {
114
- let spawnCounter = 0;
115
- let eventCounter = 0;
116
- const device = new NodePyATVDevice({
117
- name: 'My Testdevice',
118
- host: '192.168.178.2',
119
- spawn: createFakeSpawn(cp => {
120
- if (spawnCounter === 0) {
121
- cp.onStdIn(() => cp.end());
122
- }
123
-
124
- cp.stdout({
125
- result: 'success',
126
- title: 'My Movie'
127
- });
128
-
129
- spawnCounter++;
130
- if (spawnCounter >= 2) {
131
- cp.end();
132
- }
133
- })
134
- });
135
-
136
- const listener = () => {
137
- eventCounter++;
138
- };
139
-
140
- device.on('update', listener);
141
- await new Promise(cb => setTimeout(cb, 0));
142
- await device.getState();
143
-
144
- device.off('update', listener);
145
-
146
- assert.strictEqual(spawnCounter, 2);
147
- assert.strictEqual(eventCounter, 1);
148
- });
149
- it('should emit error event if event listener throws an exception', async function () {
150
- const device = new NodePyATVDevice({
151
- name: 'My Testdevice',
152
- host: '192.168.178.2',
153
- spawn: createFakeSpawn(cp => {
154
- cp.onStdIn(() => cp.end());
155
- cp.stdout({
156
- result: 'success',
157
- title: 'My Movie'
158
- });
159
- })
160
- });
161
-
162
- let callCounter = 0;
163
- const error = new Error('This is an error. Be nice.');
164
- device.once('error', err => {
165
- assert.strictEqual(err, error);
166
- callCounter++;
167
- });
168
-
169
- const listener = () => {
170
- throw error;
171
- };
172
- device.on('update', listener);
173
-
174
- await new Promise(cb => setTimeout(cb, 0));
175
- device.off('update', listener);
176
-
177
- assert.strictEqual(callCounter, 1);
178
- });
179
- it('should also work with powerState', async function () {
180
- const device = new NodePyATVDevice({
181
- name: 'My Testdevice',
182
- host: '192.168.178.2',
183
- spawn: createFakeSpawn(cp => {
184
- cp.onStdIn(() => cp.end());
185
- cp.stdout({
186
- result: 'success',
187
- datetime: new Date().toJSON(),
188
- power_state: 'off'
189
- });
190
- })
191
- });
192
-
193
- await new Promise(cb => {
194
- device.once('update:powerState', event => {
195
- assert.ok(event instanceof NodePyATVDeviceEvent);
196
- assert.strictEqual(event.key, 'powerState');
197
- assert.strictEqual(event.oldValue, null);
198
- assert.strictEqual(event.newValue, 'off');
199
- assert.strictEqual(event.newValue, NodePyATVPowerState.off);
200
- assert.strictEqual(event.value, 'off');
201
- assert.strictEqual(event.value, NodePyATVPowerState.off);
202
- assert.deepStrictEqual(event.device, device);
203
- cb(undefined);
204
- });
205
- });
206
- });
207
- });
208
-
209
- describe('start|stopListening()', function () {
210
- it('should emit error if spawn fails', async function () {
211
- const error = new Error();
212
- const device = new NodePyATVDevice({
213
- name: 'My Testdevice',
214
- host: '192.168.178.2',
215
- spawn: createFakeSpawn(cp => {
216
- cp.error(error).end();
217
- })
218
- });
219
- const listener = () => {
220
- // empty listener
221
- };
222
-
223
- device.on('update', listener);
224
-
225
- await new Promise(cb => {
226
- device.once('error', err => {
227
- assert.strictEqual(err, error);
228
- cb(undefined);
229
- });
230
- });
231
-
232
- device.off('update', listener);
233
- });
234
- it('should emit error on stderr data', async function () {
235
- const device = new NodePyATVDevice({
236
- name: 'My Testdevice',
237
- host: '192.168.178.2',
238
- spawn: createFakeSpawn(cp => {
239
- cp.stderr('Hello World!').end();
240
- })
241
- });
242
- const listener = () => {
243
- // empty listener
244
- };
245
-
246
- device.on('update', listener);
247
-
248
- await new Promise(cb => {
249
- device.once('error', err => {
250
- assert.ok(err instanceof Error);
251
- assert.ok(err.toString().includes('Got stderr output from pyatv: Hello World!'));
252
- cb(undefined);
253
- });
254
- });
255
-
256
- device.off('update', listener);
257
- });
258
- it('should emit error if stdout is not valid json', async function () {
259
- const device = new NodePyATVDevice({
260
- name: 'My Testdevice',
261
- host: '192.168.178.2',
262
- spawn: createFakeSpawn(cp => {
263
- cp.stdout('#').end();
264
- })
265
- });
266
- const listener = () => {
267
- // empty listener
268
- };
269
-
270
- device.on('update', listener);
271
-
272
- await new Promise(cb => {
273
- device.once('error', err => {
274
- assert.ok(err instanceof Error);
275
- assert.ok(err.toString().includes(
276
- 'Unable to parse stdout json: SyntaxError: ' +
277
- 'Unexpected token # in JSON at position 0'
278
- ));
279
- cb(undefined);
280
- });
281
- });
282
-
283
- device.off('update', listener);
284
- });
285
- it('should restart the process if it gets killed');
286
- });
287
-
288
- describe('addListener() / removeAllListeners()', function () {
289
- it('should work without any exceptions', async function () {
290
- const device = new NodePyATVDevice({
291
- name: 'My Testdevice',
292
- host: '192.168.178.2',
293
- spawn: createFakeSpawn(cp => {
294
- cp.onStdIn(() => cp.end());
295
- cp.stdout({
296
- result: 'success',
297
- title: 'My Movie'
298
- });
299
- })
300
- });
301
-
302
- const listener = () => {
303
- // empty listener
304
- };
305
- device.addListener('update', listener);
306
- device.removeAllListeners('update');
307
- });
308
- });
309
-
310
- describe('emit()', function () {
311
- it('should work', function (done) {
312
- const device = new NodePyATVDevice({
313
- name: 'My Testdevice',
314
- host: '192.168.178.2',
315
- spawn: createFakeSpawn(cp => {
316
- cp.onStdIn(() => cp.end());
317
- })
318
- });
319
- const event = new NodePyATVDeviceEvent({
320
- key: 'dateTime',
321
- old: 'foo',
322
- new: 'bar',
323
- device
324
- });
325
-
326
- let executions = 0;
327
- device.once('test', (e) => {
328
- executions++;
329
- assert.strictEqual(e, event);
330
- assert.strictEqual(executions, 1);
331
- done();
332
- });
333
-
334
- device.emit('test', event);
335
- });
336
- });
337
-
338
- describe('eventNames()', function () {
339
- it('should work', function () {
340
- const device = new NodePyATVDevice({
341
- name: 'My Testdevice',
342
- host: '192.168.178.2',
343
- spawn: createFakeSpawn(cp => {
344
- cp.onStdIn(() => cp.end());
345
- })
346
- });
347
-
348
- const listener = () => {
349
- // ignore
350
- };
351
-
352
- device.on('test', listener);
353
- assert.deepStrictEqual(device.eventNames(), ['test']);
354
- device.off('test', listener);
355
- });
356
- });
357
-
358
- describe('getMaxListeners()', function () {
359
- it('should work', function () {
360
- const device = new NodePyATVDevice({
361
- name: 'My Testdevice',
362
- host: '192.168.178.2',
363
- spawn: createFakeSpawn(cp => {
364
- cp.onStdIn(() => cp.end());
365
- })
366
- });
367
-
368
- const result = device.getMaxListeners();
369
- assert.ok(typeof result, 'number');
370
- assert.ok(result >= 10);
371
- });
372
- });
373
-
374
- describe('listenerCount()', function () {
375
- it('should work', function () {
376
- const device = new NodePyATVDevice({
377
- name: 'My Testdevice',
378
- host: '192.168.178.2',
379
- spawn: createFakeSpawn(cp => {
380
- cp.onStdIn(() => cp.end());
381
- })
382
- });
383
-
384
- const listener = () => {
385
- // ignore
386
- };
387
-
388
- assert.deepStrictEqual(device.listenerCount('test'), 0);
389
- device.on('test', listener);
390
- assert.deepStrictEqual(device.listenerCount('test'), 1);
391
- device.off('test', listener);
392
- });
393
- });
394
-
395
- describe('listeners()', function () {
396
- it('should work', function () {
397
- const device = new NodePyATVDevice({
398
- name: 'My Testdevice',
399
- host: '192.168.178.2',
400
- spawn: createFakeSpawn(cp => {
401
- cp.onStdIn(() => cp.end());
402
- })
403
- });
404
-
405
- const listener = () => {
406
- // ignore
407
- };
408
-
409
- assert.deepStrictEqual(device.listeners('test').length, 0);
410
- device.on('test', listener);
411
- assert.deepStrictEqual(device.listeners('test').length, 1);
412
- assert.deepStrictEqual(device.listeners('test')[0], listener);
413
- device.off('test', listener);
414
- });
415
- });
416
-
417
- describe('prependListener()', function () {
418
- it('should work', function (done) {
419
- const device = new NodePyATVDevice({
420
- name: 'My Testdevice',
421
- host: '192.168.178.2',
422
- spawn: createFakeSpawn(cp => {
423
- cp.onStdIn(() => cp.end());
424
- cp.stdout({
425
- result: 'success',
426
- title: 'My Movie'
427
- });
428
- })
429
- });
430
-
431
- const listener = () => {
432
- device.removeAllListeners('update');
433
- done();
434
- };
435
- device.prependListener('update', listener);
436
- });
437
- });
438
-
439
- describe('prependOnceListener()', function () {
440
- it('should work', function (done) {
441
- const device = new NodePyATVDevice({
442
- name: 'My Testdevice',
443
- host: '192.168.178.2',
444
- spawn: createFakeSpawn(cp => {
445
- cp.onStdIn(() => cp.end());
446
- cp.stdout({
447
- result: 'success',
448
- title: 'My Movie'
449
- });
450
- })
451
- });
452
-
453
- device.prependOnceListener('update', () => done());
454
- });
455
- });
456
-
457
- describe('rawListeners()', function () {
458
- it('should work', function () {
459
- const device = new NodePyATVDevice({
460
- name: 'My Testdevice',
461
- host: '192.168.178.2',
462
- spawn: createFakeSpawn(cp => {
463
- cp.onStdIn(() => cp.end());
464
- })
465
- });
466
-
467
- const listener = () => {
468
- // ignore
469
- };
470
-
471
- assert.deepStrictEqual(device.rawListeners('test').length, 0);
472
- device.on('test', listener);
473
- assert.deepStrictEqual(device.rawListeners('test').length, 1);
474
- assert.deepStrictEqual(device.rawListeners('test')[0], listener);
475
- device.off('test', listener);
476
- });
477
- });
478
-
479
- describe('removeListener()', function () {
480
- it('should work without any exceptions', async function () {
481
- const device = new NodePyATVDevice({
482
- name: 'My Testdevice',
483
- host: '192.168.178.2',
484
- spawn: createFakeSpawn(cp => {
485
- cp.onStdIn(() => cp.end());
486
- cp.stdout({
487
- result: 'success',
488
- title: 'My Movie'
489
- });
490
- })
491
- });
492
-
493
- const listener = () => {
494
- // empty listener
495
- };
496
- device.addListener('update', listener);
497
- assert.deepStrictEqual(device.listenerCount('update'), 1);
498
- device.removeListener('update', listener);
499
- assert.deepStrictEqual(device.listenerCount('update'), 0);
500
- });
501
- });
502
- });