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: string;
        name: string;
        protocol: 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>

    Deprecated

  • 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>

    Deprecated

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

    • event: string | symbol
    • listener: ((event) => void)

    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

    • event: string | symbol
    • listener: ((event) => void)

    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

    • event: string | symbol
    • listener: ((event) => void)

    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

    • event: string | symbol
    • listener: ((event) => void)

    Returns this

  • Parameters

    • event: string | symbol
    • listener: ((event) => void)

    Returns this

  • Parameters

    • event: string | symbol
    • listener: ((event) => void)

    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

    • Optional event: 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

    • event: string | symbol
    • listener: ((event) => void)

    Returns this

  • Parameters

    • n: number

    Returns this

Other

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

    Returns string[]

  • get debug(): true | ((msg) => 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 true | ((msg) => void)

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

    Parameters

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

    Returns void

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

    Returns string

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

    Returns string

    Example

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

    Returns string

    Example

    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(): string
  • Get the operating system of the device. Only set, if the device was found with [[find()]]. Requires pyatv ≧ 0.10.3.

    Returns string

    Example

    device.os"TvOS"
    
  • get services(): 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 NodePyATVService[]

    Example

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

    Returns string

    Example

    device.version"15.5.1"
    

State

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

    Returns void

  • 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>

Generated using TypeDoc