Class NodePyATVDevice

Represents an Apple TV. Use [[getState]] to query the current state (e.g. media type and title). You can also use the attribute methods (e.g. [[getTitle]] to get the state. If you want realtime updates, subscribe to it's events with an EventEmitter like API, so for example by using [[on]], [[once]] or [[addListener]]. It's also possible to send key commands by using [[pressKey]] or methods like [[pause]].

Implements

  • EventEmitter

Basic

  • Returns an object with name, host, id and protocol. Can be used to initiate a new device instance.

    Returns {
        host: string;
        id: undefined | string;
        name: string;
        protocol: undefined | NodePyATVProtocol;
    }

    • host: string
    • id: undefined | string
    • name: string
    • protocol: undefined | NodePyATVProtocol
  • Returns a string. Just for debugging, etc.

    Returns string

Control

  • Send the "homeHold" command

    Returns Promise<void>

  • Send the "playPause" command

    Returns Promise<void>

  • Send a key press to the Apple TV

    await device.pressKey(NodePyATVKeys.home);
    

    await device.pressKey('home');
    

    Parameters

    Returns Promise<void>

  • Send the "previous" command

    Returns Promise<void>

  • Send the "skipBackward" command

    Returns Promise<void>

  • Send the "skipForward" command

    Returns Promise<void>

  • Send the "suspend" command

    Returns Promise<void>

  • Send the "turn_off" command

    Returns Promise<void>

  • Send the "volumeDown" command

    Returns Promise<void>

  • Send the "volumeUp" command

    Returns Promise<void>

  • Send the "wakeup" command

    Returns Promise<void>

Event

  • Add an event listener. Will start the event subscription with the Apple TV as long as there are listeners for any event registered.

    Parameters

    Returns this

  • Get all event names which are currently known.

    Returns (string | symbol)[]

  • Get max number of listeners allowed

    Returns number

  • Get number of listeners for event

    Parameters

    • event: string | symbol

    Returns number

  • Get listeners for event. Will also return node-pyatv wrappers (e.g. once)

    Parameters

    • event: string | symbol

    Returns Function[]

  • Remove an event listener. Will stop the event subscription with the Apple TV if this was the last event listener.

    Parameters

    Returns this

  • Add an event listener. Will start the event subscription with the Apple TV as long as there are listeners for any event registered.

    Parameters

    Returns this

  • Add an event listener. Will start the event subscription with the Apple TV as long as there are listeners for any event registered. Removes the listener automatically after the first occurrence.

    Parameters

    Returns this

  • Parameters

    • event: string | symbol

    Returns Function[]

  • Removes all listeners, either for the given event or for every event. Will stop the event subscription with the Apple TV if this was the last event listener.

    Parameters

    • Optionalevent: string | symbol

    Returns this

  • Remove an event listener. Will stop the event subscription with the Apple TV if this was the last event listener.

    Parameters

    Returns this

  • Parameters

    • n: number

    Returns this

Other

  • get allIDs(): undefined | string[]
  • Get all IDs of the Apple TV. Requires pyatv >= 0.14.5.

    Returns undefined | string[]

  • get debug(): undefined | true | ((msg: string) => void)
  • Returns true, if debugging is enabled. Returns the custom logging method, if one was specified. Otherwise, if debug log is disabled, returns undefined.

    Returns undefined | true | ((msg: string) => void)

  • set debug(debug): void
  • Enable or disable debugging or set a custom debugging method to use.

    Parameters

    • debug: undefined | true | ((msg: string) => void)

    Returns void

  • get id(): undefined | string
  • Get the ID of the Apple TV.

    Returns undefined | string

  • get mac(): undefined | string
  • Get the MAC address of the Apple TV. Requires pyatv >= 0.14.5.

    Returns undefined | string

  • get model(): undefined | string
  • Get the model identifier of the device. Only set, if the device was found using [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns undefined | string

    device.model"Gen4K"
    
  • get modelName(): undefined | string
  • Get the model name of the device. Only set, if the device was found with [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns undefined | string

    device.modelName"Apple TV 4K"
    
  • get name(): string
  • Get the name of the Apple TV.

    import pyatv from '@sebbo2002/node-pyatv';
    const devices = await pyatv.find();
    devices.forEach(device =>
    console.log(device.name)
    );

    Returns string

  • get os(): undefined | string
  • Get the operating system of the device. Only set, if the device was found with [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns undefined | string

    device.os"TvOS"
    
  • get services(): undefined | NodePyATVService[]
  • Returns a list of services supported by the device. Ony set, if the device was found during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns undefined | NodePyATVService[]

    device.services → [
    {
    "protocol": "airplay",
    "port": 7000
    },
    {
    "protocol": "dmap",
    "port": 3689
    }
    ]
  • get version(): undefined | string
  • Get the device version. Only set, if the device was found during a scan using [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns undefined | string

    device.version"15.5.1"
    

State

  • Removes the state node-pyatv cached for this device.

    Returns void

  • Returns the current focus state of the device

    Parameters

    Returns Promise<null | NodePyATVFocusState>

  • Returns the iTunes Store identifier if available. Requires pyatv >= 0.16.0

    Parameters

    Returns Promise<null | number>

    getiTunesStoreIdentifier

  • Returns the current output devices of the device

    Parameters

    Returns Promise<null | {
        identifier: string;
        name: string;
    }[]>

  • Returns an [[NodePyATVState]] object representing the current state of the device. Has an internal cache, which has a default TTL of 5s. You can change this default value by passing the maxAge option.

    await device.getState({maxAge: 10000}); // cache TTL: 10s
    

    Parameters

    Returns Promise<NodePyATVState>