Skip to content

Commit

Permalink
feat(core): add mac attribute to device
Browse files Browse the repository at this point in the history
adding the new mac attribute introduced in postlund/pyatv#2282 to the device.
  • Loading branch information
maxileith authored and sebbo2002 committed Dec 26, 2023
1 parent 02a9c05 commit 5b0f58c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export default class NodePyATVDevice implements EventEmitter{
return this.options.protocol;
}

/**
* Get the MAC address of the Apple TV.
*/
get mac(): string | undefined {
return this.options.mac;
}

/**
* Get the model identifier of the device. Only set, if the
* device was found using [[find()]]. Requires pyatv ≧ 0.10.3.
Expand Down
1 change: 1 addition & 0 deletions src/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class NodePyATVInstance {
id: device.identifier,
allIDs: device.all_identifiers,
name: device.name,
mac: device.device_info?.mac,
model: device.device_info?.model,
modelName: device.device_info?.model_str,
os: device.device_info?.operating_system,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface NodePyATVFindAndInstanceOptions extends NodePyATVInstanceOption
export interface NodePyATVDeviceOptions extends NodePyATVFindAndInstanceOptions {
host: string;
name: string;
mac?: string;
model?: string;
modelName?: string;
os?: string;
Expand All @@ -178,6 +179,7 @@ export interface NodePyATVInternalScanDevice {
identifier: string;
all_identifiers: string[];
device_info?: {
mac: string | null;
model: string;
model_str: string;
operating_system: string;
Expand Down
12 changes: 12 additions & 0 deletions test/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ describe('NodePyATVDevice', function () {
});
});

describe('get mac()', function () {
it('should return the mac', function () {
const device = new NodePyATVDevice({
name: 'My Testdevice',
host: '192.168.178.2',
mac: 'AA:BB:CC:DD:EE:FF'
});

assert.strictEqual(device.mac, 'AA:BB:CC:DD:EE:FF');
});
});

describe('get model()', function () {
it('should return the model if set by scan', function () {
const device = new NodePyATVDevice({
Expand Down

0 comments on commit 5b0f58c

Please sign in to comment.