@sebbo2002/node-pyatv 4.1.1-develop.1 → 4.2.1-develop.1

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 (68) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/lib/device-event.d.ts +1 -1
  3. package/dist/lib/device-events.d.ts +1 -2
  4. package/dist/lib/device-events.js +9 -7
  5. package/dist/lib/device-events.js.map +1 -1
  6. package/dist/lib/device.d.ts +1 -1
  7. package/dist/lib/device.js +12 -11
  8. package/dist/lib/device.js.map +1 -1
  9. package/dist/lib/index.d.ts +3 -1
  10. package/dist/lib/index.js +7 -1
  11. package/dist/lib/index.js.map +1 -1
  12. package/dist/lib/instance.d.ts +1 -1
  13. package/dist/lib/instance.js +2 -2
  14. package/dist/lib/instance.js.map +1 -1
  15. package/dist/lib/tools.js +7 -0
  16. package/dist/lib/tools.js.map +1 -1
  17. package/dist/lib/types.d.ts +1 -0
  18. package/docs/coverage/cobertura-coverage.xml +665 -633
  19. package/docs/coverage/device-event.ts.html +2 -2
  20. package/docs/coverage/device-events.ts.html +99 -87
  21. package/docs/coverage/device.ts.html +38 -26
  22. package/docs/coverage/fake-spawn.ts.html +25 -25
  23. package/docs/coverage/index.html +29 -29
  24. package/docs/coverage/index.ts.html +22 -7
  25. package/docs/coverage/instance.ts.html +2 -2
  26. package/docs/coverage/tools.ts.html +133 -109
  27. package/docs/coverage/types.ts.html +5 -2
  28. package/docs/reference/assets/main.js +1 -1
  29. package/docs/reference/assets/search.js +1 -1
  30. package/docs/reference/assets/style.css +4 -0
  31. package/docs/reference/classes/NodePyATVDevice.html +147 -0
  32. package/docs/reference/classes/NodePyATVDeviceEvent.html +6 -6
  33. package/docs/reference/classes/default.html +15 -15
  34. package/docs/reference/enums/NodePyATVDeviceState.html +1 -1
  35. package/docs/reference/enums/NodePyATVKeys.html +1 -1
  36. package/docs/reference/enums/NodePyATVListenerState.html +1 -0
  37. package/docs/reference/enums/NodePyATVMediaType.html +1 -1
  38. package/docs/reference/enums/NodePyATVPowerState.html +1 -0
  39. package/docs/reference/enums/NodePyATVProtocol.html +1 -1
  40. package/docs/reference/enums/NodePyATVRepeatState.html +1 -1
  41. package/docs/reference/enums/NodePyATVShuffleState.html +1 -1
  42. package/docs/reference/index.html +2 -2
  43. package/docs/reference/interfaces/NodePyATVDeviceOptions.html +1 -1
  44. package/docs/reference/interfaces/NodePyATVFindAndInstanceOptions.html +1 -1
  45. package/docs/reference/interfaces/NodePyATVFindOptions.html +1 -1
  46. package/docs/reference/interfaces/NodePyATVGetStateOptions.html +1 -1
  47. package/docs/reference/interfaces/NodePyATVInstanceOptions.html +1 -1
  48. package/docs/reference/interfaces/NodePyATVState.html +1 -1
  49. package/docs/reference/interfaces/NodePyATVVersionResponse.html +1 -1
  50. package/docs/reference/modules.html +1 -1
  51. package/docs/tests/assets/app.css +1 -1
  52. package/docs/tests/assets/app.js +2 -2
  53. package/docs/tests/assets/app.js.LICENSE.txt +1 -1
  54. package/docs/tests/index.html +1 -1
  55. package/docs/tests/mochawesome.json +700 -605
  56. package/package.json +17 -17
  57. package/src/lib/device-event.ts +1 -1
  58. package/src/lib/device-events.ts +8 -4
  59. package/src/lib/device.ts +12 -8
  60. package/src/lib/index.ts +6 -1
  61. package/src/lib/instance.ts +1 -1
  62. package/src/lib/tools.ts +8 -0
  63. package/src/lib/types.ts +1 -0
  64. package/test/device-events.ts +24 -3
  65. package/test/device.ts +18 -0
  66. package/test/instance.ts +9 -1
  67. package/test/tools.ts +15 -4
  68. package/typedoc.json +1 -1
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "author": "Sebastian Pekarek <sheeboothohmoolaiquu@e.sebbo.net>",
2
+ "author": "Sebastian Pekarek <mail@sebbo.net>",
3
3
  "bugs": {
4
4
  "email": "sheeboothohmoolaiquu@e.sebbo.net",
5
5
  "url": "http://github.com/sebbo2002/node-pyatv/issues"
@@ -10,27 +10,27 @@
10
10
  "description": "A lightweight wrapper around pyatv…",
11
11
  "devDependencies": {
12
12
  "@amanda-mitchell/semantic-release-npm-multiple": "^2.15.0",
13
- "@qiwi/semantic-release-gh-pages-plugin": "^5.1.1",
14
- "@semantic-release/changelog": "^6.0.0",
15
- "@semantic-release/exec": "^6.0.1",
16
- "@semantic-release/git": "^10.0.0",
13
+ "@qiwi/semantic-release-gh-pages-plugin": "^5.2.0",
14
+ "@semantic-release/changelog": "^6.0.1",
15
+ "@semantic-release/exec": "^6.0.2",
16
+ "@semantic-release/git": "^10.0.1",
17
17
  "@types/mocha": "^9.0.0",
18
- "@types/node": "^16.11.3",
18
+ "@types/node": "^16.11.10",
19
19
  "@types/semver": "^7.3.9",
20
- "@typescript-eslint/eslint-plugin": "^5.1.0",
21
- "@typescript-eslint/parser": "^5.1.0",
22
- "eslint": "^8.0.1",
23
- "eslint-plugin-jsonc": "^1.7.0",
20
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
21
+ "@typescript-eslint/parser": "^5.4.0",
22
+ "eslint": "^8.3.0",
23
+ "eslint-plugin-jsonc": "^2.0.0",
24
24
  "license-checker": "^25.0.1",
25
25
  "mocha": "^9.1.3",
26
- "mochawesome": "^6.3.1",
26
+ "mochawesome": "^7.0.1",
27
27
  "nyc": "^15.1.0",
28
- "semantic-release": "^18.0.0",
28
+ "semantic-release": "^18.0.1",
29
29
  "semantic-release-license": "^1.0.3",
30
- "source-map-support": "^0.5.20",
31
- "ts-node": "^10.3.1",
32
- "typedoc": "^0.22.6",
33
- "typescript": "^4.4.4"
30
+ "source-map-support": "^0.5.21",
31
+ "ts-node": "^10.4.0",
32
+ "typedoc": "^0.22.10",
33
+ "typescript": "^4.5.2"
34
34
  },
35
35
  "engines": {
36
36
  "node": ">=12.0.0"
@@ -55,5 +55,5 @@
55
55
  "postinstall": "./check.sh",
56
56
  "test": "mocha"
57
57
  },
58
- "version": "4.1.1-develop.1"
58
+ "version": "4.2.1-develop.1"
59
59
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import NodePyATVDevice from './device';
3
+ import {NodePyATVDevice} from '../lib';
4
4
  import {NodePyATVEventValueType, NodePyATVStateIndex} from './types';
5
5
 
6
6
  export default class NodePyATVDeviceEvent {
@@ -11,8 +11,7 @@ import {
11
11
  import {ChildProcess} from 'child_process';
12
12
 
13
13
  import {EventEmitter} from 'events';
14
- import NodePyATVDevice from './device';
15
- import NodePyATVDeviceEvent from './device-event';
14
+ import {NodePyATVDevice, NodePyATVDeviceEvent} from '../lib';
16
15
  import {addRequestId, debug, execute, getParamters, parseState, removeRequestId} from './tools';
17
16
  import {FakeChildProcess} from './fake-spawn';
18
17
 
@@ -91,8 +90,13 @@ export default class NodePyATVDeviceEvents extends EventEmitter {
91
90
  }
92
91
 
93
92
  private applyPushUpdate(update: NodePyATVInternalState, reqId: string): void {
94
- const newState = parseState(update, reqId, this.options);
95
- this.applyStateAndEmitEvents(newState);
93
+ try {
94
+ const newState = parseState(update, reqId, this.options);
95
+ this.applyStateAndEmitEvents(newState);
96
+ }
97
+ catch(error) {
98
+ this.emit('error', error);
99
+ }
96
100
  }
97
101
 
98
102
  private checkListener(): void {
package/src/lib/device.ts CHANGED
@@ -14,8 +14,7 @@ import {
14
14
  } from './types';
15
15
 
16
16
  import {addRequestId, getParamters, parseState, removeRequestId, request} from './tools';
17
- import NodePyATVDeviceEvents from './device-events';
18
- import NodePyATVDeviceEvent from './device-event';
17
+ import {NodePyATVDeviceEvents, NodePyATVDeviceEvent} from '../lib';
19
18
  import { EventEmitter } from 'events';
20
19
 
21
20
  /**
@@ -148,14 +147,19 @@ export default class NodePyATVDevice implements EventEmitter{
148
147
  }
149
148
 
150
149
  const id = addRequestId();
151
- const parameters = getParamters(this.options);
152
150
 
153
- const result = await request(id, NodePyATVExecutableType.atvscript, [...parameters, 'playing'], this.options);
154
- const newState = parseState(result, id, this.options);
155
- this.applyState(newState);
151
+ try {
152
+ const parameters = getParamters(this.options);
156
153
 
157
- removeRequestId(id);
158
- return newState;
154
+ const result = await request(id, NodePyATVExecutableType.atvscript, [...parameters, 'playing'], this.options);
155
+ const newState = parseState(result, id, this.options);
156
+
157
+ this.applyState(newState);
158
+ return newState;
159
+ }
160
+ finally {
161
+ removeRequestId(id);
162
+ }
159
163
  }
160
164
 
161
165
  /**
package/src/lib/index.ts CHANGED
@@ -13,9 +13,14 @@ export {
13
13
  NodePyATVFindAndInstanceOptions,
14
14
  NodePyATVDeviceOptions,
15
15
  NodePyATVGetStateOptions,
16
- NodePyATVState
16
+ NodePyATVState,
17
+ NodePyATVPowerState,
18
+ NodePyATVListenerState,
19
+ NodePyATVEventValueType,
17
20
  } from './types';
18
21
 
19
22
  export {default as NodePyATVDeviceEvent} from './device-event';
23
+ export {default as NodePyATVDeviceEvents} from './device-events';
24
+ export {default as NodePyATVDevice} from './device';
20
25
 
21
26
  export {default} from './instance';
@@ -11,7 +11,7 @@ import {
11
11
  } from './types';
12
12
 
13
13
  import {addRequestId, debug, getParamters, removeRequestId, request} from './tools';
14
- import NodePyATVDevice from './device';
14
+ import {NodePyATVDevice} from '../lib';
15
15
 
16
16
  /**
17
17
  * Default class exported by `@sebbo2002/node-pyatv`. Use [[find]] to scan for devices in your local network. Use
package/src/lib/tools.ts CHANGED
@@ -252,6 +252,14 @@ export function parseState(input: NodePyATVInternalState, id: string, options: N
252
252
  if (!input || typeof input !== 'object') {
253
253
  return result;
254
254
  }
255
+ if(input.exception) {
256
+ let errorStr = 'Got pyatv Error: ' + input.exception;
257
+ if(input.stacktrace) {
258
+ errorStr += '\n\npyatv Stacktrace:\n' + input.stacktrace;
259
+ }
260
+
261
+ throw new Error(errorStr);
262
+ }
255
263
 
256
264
  // datetime
257
265
  if (typeof input.datetime === 'string') {
package/src/lib/types.ts CHANGED
@@ -171,6 +171,7 @@ export interface NodePyATVInternalState {
171
171
  power_state?: string | unknown,
172
172
  push_updates?: string | unknown,
173
173
  exception?: string | unknown,
174
+ stacktrace?: string | unknown,
174
175
  connection?: string | unknown
175
176
  }
176
177
 
@@ -1,10 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  import assert from 'assert';
4
- import NodePyATVDevice from '../src/lib/device';
5
4
  import {createFakeSpawn} from '../src/lib/fake-spawn';
6
- import NodePyATVDeviceEvent from '../src/lib/device-event';
7
- import {NodePyATVPowerState} from '../src/lib/types';
5
+ import {NodePyATVDeviceEvent, NodePyATVPowerState, NodePyATVDevice} from '../src/lib';
8
6
 
9
7
  describe('NodePyATVDeviceEvents', function () {
10
8
  describe('applyStateAndEmitEvents()', function () {
@@ -89,6 +87,29 @@ describe('NodePyATVDeviceEvents', function () {
89
87
 
90
88
  assert.deepStrictEqual(sort, ['update:title', 'update']);
91
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
+ });
92
113
  it('should not emit an update if new value is same as old one', async function () {
93
114
  let spawnCounter = 0;
94
115
  let eventCounter = 0;
package/test/device.ts CHANGED
@@ -237,6 +237,24 @@ describe('NodePyATVDevice', function () {
237
237
  powerState: null
238
238
  });
239
239
  });
240
+ it('should reject with error if pyatv fails', async function () {
241
+ const device = new NodePyATVDevice({
242
+ name: 'My Testdevice',
243
+ host: '192.168.178.2',
244
+ spawn: createFakeSpawn(cp => {
245
+ cp.end({
246
+ result: 'failure',
247
+ datetime: '2021-11-24T21:13:36.424576+03:00',
248
+ exception: 'invalid credentials: 321',
249
+ 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'
250
+ });
251
+ })
252
+ });
253
+
254
+ assert.rejects(async () => {
255
+ await device.getState();
256
+ }, /Got pyatv Error: invalid credentials: 321/);
257
+ });
240
258
  it('should cache requests for a bit', async function () {
241
259
  let executions = 0;
242
260
  const device = new NodePyATVDevice({
package/test/instance.ts CHANGED
@@ -9,7 +9,9 @@ import NodePyATVInstance, {
9
9
  NodePyATVDeviceState,
10
10
  NodePyATVRepeatState,
11
11
  NodePyATVShuffleState,
12
- NodePyATVKeys
12
+ NodePyATVKeys,
13
+ NodePyATVListenerState,
14
+ NodePyATVPowerState
13
15
  } from '../src/lib/index';
14
16
 
15
17
  describe('NodePyATVInstance', function () {
@@ -330,5 +332,11 @@ describe('NodePyATVInstance', function () {
330
332
  it('Type NodePyATVKeys should be exported', function() {
331
333
  assert.ok(NodePyATVKeys);
332
334
  });
335
+ it('Type NodePyATVInstanceOptions should be exported', function() {
336
+ assert.ok(NodePyATVListenerState);
337
+ });
338
+ it('Type NodePyATVPowerState should be exported', function() {
339
+ assert.ok(NodePyATVPowerState);
340
+ });
333
341
  });
334
342
  });
package/test/tools.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import assert from 'assert';
4
- import {addRequestId, debug, getExecutable, getParamters, parseState, removeRequestId} from '../src/lib/tools';
4
+ import { addRequestId, debug, getExecutable, getParamters, parseState, removeRequestId } from '../src/lib/tools';
5
5
  import {
6
6
  NodePyATVDeviceState,
7
7
  NodePyATVExecutableType,
@@ -28,7 +28,7 @@ describe('Tools', function () {
28
28
  debug('TEST', 'Hello World.', {});
29
29
  });
30
30
  it('should work with default logger', function () {
31
- debug('TEST', 'Hello World.', {debug: true});
31
+ debug('TEST', 'Hello World.', { debug: true });
32
32
  });
33
33
  it('should work with custom logger', function () {
34
34
  debug('TEST', 'Hello World.', {
@@ -39,7 +39,7 @@ describe('Tools', function () {
39
39
  });
40
40
  });
41
41
  it('should work with colors disabled', function () {
42
- debug('TEST', 'Hello World.', {noColors: true});
42
+ debug('TEST', 'Hello World.', { noColors: true });
43
43
  });
44
44
  it('should work with custom logger and colors disabled', function () {
45
45
  debug('TEST', 'Hello World.', {
@@ -201,8 +201,19 @@ describe('Tools', function () {
201
201
  powerState: null
202
202
  });
203
203
  });
204
+ it('should throw an error for pyatv exceptions', function () {
205
+ const input = {
206
+ result: 'failure',
207
+ datetime: '2021-11-24T21:13:36.424576+03:00',
208
+ exception: 'invalid credentials: 321',
209
+ 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'
210
+ };
211
+ assert.throws(() => {
212
+ parseState(input, '', {});
213
+ }, /Got pyatv Error: invalid credentials: 321/);
214
+ });
204
215
  it('should ignore date if it\'s an invalid date', function () {
205
- const input = {datetime: 'today'};
216
+ const input = { datetime: 'today' };
206
217
  const result = parseState(input, '', {});
207
218
  assert.deepStrictEqual(result, {
208
219
  dateTime: null,
package/typedoc.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "excludePrivate": true,
8
8
  "excludeProtected": true,
9
9
  "includeVersion": true,
10
- "name": "",
10
+ "name": "node-pyatv",
11
11
  "out": "./docs/reference",
12
12
  "plugin": [],
13
13
  "readme": "README.md",