@sebbo2002/node-pyatv 5.0.0 → 5.1.0-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 (54) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/lib/device.d.ts +46 -1
  3. package/dist/lib/device.js +55 -0
  4. package/dist/lib/device.js.map +1 -1
  5. package/dist/lib/index.d.ts +2 -1
  6. package/dist/lib/index.js +2 -1
  7. package/dist/lib/index.js.map +1 -1
  8. package/dist/lib/instance.js +13 -5
  9. package/dist/lib/instance.js.map +1 -1
  10. package/dist/lib/types.d.ts +24 -0
  11. package/docs/coverage/cobertura-coverage.xml +913 -791
  12. package/docs/coverage/device-event.ts.html +1 -1
  13. package/docs/coverage/device-events.ts.html +8 -8
  14. package/docs/coverage/device.ts.html +204 -18
  15. package/docs/coverage/fake-spawn.ts.html +41 -41
  16. package/docs/coverage/index.html +30 -30
  17. package/docs/coverage/index.ts.html +25 -16
  18. package/docs/coverage/instance.ts.html +51 -33
  19. package/docs/coverage/tools.ts.html +250 -250
  20. package/docs/coverage/types.ts.html +82 -4
  21. package/docs/reference/assets/highlight.css +4 -4
  22. package/docs/reference/assets/search.js +1 -1
  23. package/docs/reference/classes/NodePyATVDevice.html +85 -9
  24. package/docs/reference/classes/NodePyATVDeviceEvent.html +4 -4
  25. package/docs/reference/classes/{default.html → NodePyATVInstance.html} +34 -34
  26. package/docs/reference/enums/NodePyATVDeviceState.html +10 -10
  27. package/docs/reference/enums/NodePyATVExecutableType.html +65 -0
  28. package/docs/reference/enums/NodePyATVKeys.html +27 -27
  29. package/docs/reference/enums/NodePyATVListenerState.html +8 -8
  30. package/docs/reference/enums/NodePyATVMediaType.html +8 -8
  31. package/docs/reference/enums/NodePyATVPowerState.html +6 -6
  32. package/docs/reference/enums/NodePyATVProtocol.html +8 -8
  33. package/docs/reference/enums/NodePyATVRepeatState.html +7 -7
  34. package/docs/reference/enums/NodePyATVShuffleState.html +7 -7
  35. package/docs/reference/index.html +8 -5
  36. package/docs/reference/interfaces/NodePyATVDeviceOptions.html +55 -20
  37. package/docs/reference/interfaces/NodePyATVFindAndInstanceOptions.html +18 -18
  38. package/docs/reference/interfaces/NodePyATVFindOptions.html +13 -13
  39. package/docs/reference/interfaces/NodePyATVGetStateOptions.html +5 -5
  40. package/docs/reference/interfaces/NodePyATVInstanceOptions.html +9 -9
  41. package/docs/reference/interfaces/NodePyATVService.html +69 -0
  42. package/docs/reference/interfaces/NodePyATVState.html +19 -19
  43. package/docs/reference/interfaces/NodePyATVVersionResponse.html +6 -6
  44. package/docs/reference/modules.html +23 -8
  45. package/docs/reference/types/NodePyATVEventValueType.html +9 -6
  46. package/docs/tests/index.html +1 -1
  47. package/docs/tests/mochawesome.json +930 -602
  48. package/package.json +1 -1
  49. package/src/lib/device.ts +62 -0
  50. package/src/lib/index.ts +15 -12
  51. package/src/lib/instance.ts +8 -2
  52. package/src/lib/types.ts +26 -0
  53. package/test/device.ts +124 -1
  54. package/test/instance.ts +84 -5
package/package.json CHANGED
@@ -58,5 +58,5 @@
58
58
  "test": "mocha"
59
59
  },
60
60
  "type": "module",
61
- "version": "5.0.0"
61
+ "version": "5.1.0-develop.1"
62
62
  }
package/src/lib/device.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  NodePyATVMediaType,
11
11
  NodePyATVProtocol,
12
12
  NodePyATVRepeatState,
13
+ NodePyATVService,
13
14
  NodePyATVShuffleState,
14
15
  NodePyATVState
15
16
  } from './types.js';
@@ -74,6 +75,67 @@ export default class NodePyATVDevice implements EventEmitter{
74
75
  return this.options.protocol;
75
76
  }
76
77
 
78
+ /**
79
+ * Get the model identifier of the device. Only set, if the
80
+ * device was found using [[find()]]. Requires pyatv ≧ 0.10.3.
81
+ *
82
+ * @example device.model → "Gen4K"
83
+ */
84
+ get model(): string | undefined {
85
+ return this.options.model;
86
+ }
87
+
88
+ /**
89
+ * Get the model name of the device. Only set, if the device
90
+ * was found with [[find()]]. Requires pyatv ≧ 0.10.3.
91
+ *
92
+ * @example device.modelName → "Apple TV 4K"
93
+ */
94
+ get modelName(): string | undefined {
95
+ return this.options.modelName;
96
+ }
97
+
98
+ /**
99
+ * Get the operating system of the device. Only set, if the
100
+ * device was found with [[find()]]. Requires pyatv ≧ 0.10.3.
101
+ *
102
+ * @example device.os → "TvOS"
103
+ */
104
+ get os(): string | undefined {
105
+ return this.options.os;
106
+ }
107
+
108
+ /**
109
+ * Get the device version. Only set, if the device was found
110
+ * during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.
111
+ *
112
+ * @example device.version → "15.5.1"
113
+ */
114
+ get version(): string | undefined {
115
+ return this.options.version;
116
+ }
117
+
118
+ /**
119
+ * Returns a list of services supported by the device. Ony set, if
120
+ * the device was found during a scan using [[find()]]. Requires
121
+ * pyatv ≧ 0.10.3.
122
+ *
123
+ * @example device.services → [
124
+ * {
125
+ * "protocol": "airplay",
126
+ * "port": 7000
127
+ * },
128
+ * {
129
+ * "protocol": "dmap",
130
+ * "port": 3689
131
+ * }
132
+ * ]
133
+ */
134
+ get services(): NodePyATVService[] | undefined {
135
+ return this.options.services;
136
+ }
137
+
138
+
77
139
  /**
78
140
  * Returns true, if debugging is enabled. Returns the custom
79
141
  * logging method, if one was specified. Otherwise, if debug
package/src/lib/index.ts CHANGED
@@ -1,26 +1,29 @@
1
1
  'use strict';
2
2
 
3
3
  export {
4
- NodePyATVProtocol,
5
- NodePyATVMediaType,
4
+ NodePyATVDeviceOptions,
6
5
  NodePyATVDeviceState,
7
- NodePyATVRepeatState,
8
- NodePyATVShuffleState,
9
- NodePyATVKeys,
10
- NodePyATVInstanceOptions,
11
- NodePyATVVersionResponse,
12
- NodePyATVFindOptions,
6
+ NodePyATVEventValueType,
7
+ NodePyATVExecutableType,
13
8
  NodePyATVFindAndInstanceOptions,
14
- NodePyATVDeviceOptions,
9
+ NodePyATVFindOptions,
15
10
  NodePyATVGetStateOptions,
16
- NodePyATVState,
17
- NodePyATVPowerState,
11
+ NodePyATVInstanceOptions,
12
+ NodePyATVKeys,
18
13
  NodePyATVListenerState,
19
- NodePyATVEventValueType,
14
+ NodePyATVMediaType,
15
+ NodePyATVPowerState,
16
+ NodePyATVProtocol,
17
+ NodePyATVRepeatState,
18
+ NodePyATVService,
19
+ NodePyATVShuffleState,
20
+ NodePyATVState,
21
+ NodePyATVVersionResponse
20
22
  } from './types.js';
21
23
 
22
24
  export {default as NodePyATVDeviceEvent} from './device-event.js';
23
25
  export {default as NodePyATVDeviceEvents} from './device-events.js';
24
26
  export {default as NodePyATVDevice} from './device.js';
27
+ export {default as NodePyATVInstance} from './instance.js';
25
28
 
26
29
  export {default} from './instance.js';
@@ -10,6 +10,7 @@ import {
10
10
  NodePyATVExecutableType,
11
11
  NodePyATVFindAndInstanceOptions,
12
12
  NodePyATVInstanceOptions,
13
+ NodePyATVInternalScanDevice,
13
14
  NodePyATVVersionResponse
14
15
  } from './types.js';
15
16
 
@@ -117,11 +118,16 @@ export default class NodePyATVInstance {
117
118
  throw new Error(`Unable to parse pyatv response: ${JSON.stringify(result, null, ' ')}`);
118
119
  }
119
120
 
120
- const objects = result.devices.map((device: { address: string, identifier: string, name: string }) =>
121
+ const objects = result.devices.map((device: NodePyATVInternalScanDevice) =>
121
122
  this.device(Object.assign({}, options, {
122
123
  host: device.address,
123
124
  id: device.identifier,
124
- name: device.name
125
+ name: device.name,
126
+ model: device.device_info?.model,
127
+ modelName: device.device_info?.model_str,
128
+ os: device.device_info?.operating_system,
129
+ version: device.device_info?.version,
130
+ services: device.services
125
131
  }))
126
132
  );
127
133
 
package/src/lib/types.ts CHANGED
@@ -147,12 +147,38 @@ export interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOption
147
147
  export interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
148
148
  host: string;
149
149
  name: string;
150
+ model?: string;
151
+ modelName?: string;
152
+ os?: string;
153
+ version?: string;
154
+ services?: NodePyATVService[];
150
155
  }
151
156
 
152
157
  export interface NodePyATVGetStateOptions {
153
158
  maxAge?: number;
154
159
  }
155
160
 
161
+ export interface NodePyATVService {
162
+ protocol: NodePyATVProtocol;
163
+ port: number;
164
+ }
165
+
166
+ /**
167
+ * @internal
168
+ */
169
+ export interface NodePyATVInternalScanDevice {
170
+ name: string;
171
+ address: string;
172
+ identifier: string;
173
+ device_info?: {
174
+ model: string;
175
+ model_str: string;
176
+ operating_system: string;
177
+ version: string;
178
+ };
179
+ services?: NodePyATVService[];
180
+ }
181
+
156
182
  /**
157
183
  * @internal
158
184
  */
package/test/device.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  NodePyATVShuffleState
12
12
  } from '../src/lib/types.js';
13
13
  import NodePyATVInstance from '../src/lib/instance.js';
14
- import {createFakeSpawn} from '../src/lib/fake-spawn.js';
14
+ import { createFakeSpawn } from '../src/lib/fake-spawn.js';
15
15
 
16
16
  describe('NodePyATVDevice', function () {
17
17
  describe('get name()', function () {
@@ -60,6 +60,129 @@ describe('NodePyATVDevice', function () {
60
60
  });
61
61
  });
62
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
+
63
186
  describe('get debug()', function () {
64
187
  it('should return true if set to true', function () {
65
188
  const device = new NodePyATVDevice({
package/test/instance.ts CHANGED
@@ -7,15 +7,15 @@ import { fileURLToPath } from 'url';
7
7
 
8
8
  import { createFakeSpawn } from '../src/lib/fake-spawn.js';
9
9
  import NodePyATVInstance, {
10
- NodePyATVProtocol,
11
- NodePyATVMediaType,
12
10
  NodePyATVDeviceEvent,
13
11
  NodePyATVDeviceState,
14
- NodePyATVRepeatState,
15
- NodePyATVShuffleState,
16
12
  NodePyATVKeys,
17
13
  NodePyATVListenerState,
18
- NodePyATVPowerState
14
+ NodePyATVMediaType,
15
+ NodePyATVPowerState,
16
+ NodePyATVProtocol,
17
+ NodePyATVRepeatState,
18
+ NodePyATVShuffleState
19
19
  } from '../src/lib/index.js';
20
20
 
21
21
  const __filename = fileURLToPath(import.meta.url);
@@ -257,6 +257,85 @@ describe('NodePyATVInstance', function () {
257
257
  });
258
258
  }, /Unable to parse pyatv response: /);
259
259
  });
260
+ it('should work if devices are without device_info / services', async function () {
261
+ const devices = await NodePyATVInstance.find({
262
+ spawn: createFakeSpawn(cp => {
263
+ cp.stdout({
264
+ result: 'success',
265
+ datetime: '2020-11-06T20:47:30.840022+01:00',
266
+ devices: [
267
+ {
268
+ name: 'Vardagsrum',
269
+ address: '10.0.10.81',
270
+ identifier: 'xxx'
271
+ }
272
+ ]
273
+ }).code(1).end();
274
+ })
275
+ });
276
+
277
+ assert.strictEqual(devices.length, 1);
278
+ assert.strictEqual(devices[0].name, 'Vardagsrum');
279
+ assert.strictEqual(devices[0].host, '10.0.10.81');
280
+ assert.strictEqual(devices[0].id, 'xxx');
281
+ assert.strictEqual(devices[0].model, undefined);
282
+ assert.strictEqual(devices[0].modelName, undefined);
283
+ assert.strictEqual(devices[0].os, undefined);
284
+ assert.strictEqual(devices[0].version, undefined);
285
+ assert.deepStrictEqual(devices[0].services, undefined);
286
+ });
287
+ it('should work if devices are with device_info / services', async function () {
288
+ const devices = await NodePyATVInstance.find({
289
+ spawn: createFakeSpawn(cp => {
290
+ cp.stdout({
291
+ result: 'success',
292
+ datetime: '2020-11-06T20:47:30.840022+01:00',
293
+ devices: [
294
+ {
295
+ name: 'Vardagsrum',
296
+ address: '10.0.10.81',
297
+ identifier: 'xxx',
298
+ device_info: {
299
+ 'model': 'Gen4K',
300
+ 'model_str': 'Apple TV 4K',
301
+ 'operating_system': 'TvOS',
302
+ 'version': '15.5.1'
303
+ },
304
+ services: [
305
+ {
306
+ protocol: 'mrp',
307
+ port: 49152
308
+ },
309
+ {
310
+ protocol: 'airplay',
311
+ port: 7000
312
+ }
313
+ ]
314
+ }
315
+ ]
316
+ }).code(1).end();
317
+ })
318
+ });
319
+
320
+ assert.strictEqual(devices.length, 1);
321
+ assert.strictEqual(devices[0].name, 'Vardagsrum');
322
+ assert.strictEqual(devices[0].host, '10.0.10.81');
323
+ assert.strictEqual(devices[0].id, 'xxx');
324
+ assert.strictEqual(devices[0].model, 'Gen4K');
325
+ assert.strictEqual(devices[0].modelName, 'Apple TV 4K');
326
+ assert.strictEqual(devices[0].os, 'TvOS');
327
+ assert.strictEqual(devices[0].version, '15.5.1');
328
+ assert.deepStrictEqual(devices[0].services, [
329
+ {
330
+ protocol: NodePyATVProtocol.mrp,
331
+ port: 49152
332
+ },
333
+ {
334
+ protocol: NodePyATVProtocol.airplay,
335
+ port: 7000
336
+ }
337
+ ]);
338
+ });
260
339
  });
261
340
 
262
341
  describe('static device()', function () {