Start | Scan, Pair and Connect | Device Information | Control | Power Management | Features | Metadata | Listeners | AirPlay | Examples

Power Management

Power management of a device is done with the power interface, interface.Power. It allows you to turn on, turn off and get current power state. This interface is currently only supported by devices running tvOS.

Using the Power Management API

After connecting to a device, you get the power management via interface.AppleTV.power:

atv = await pyatv.connect(config, ...)
pwrc = atv.power

You can then control via the available functions:

await pwrc.turn_on()
await pwrc.turn_off()

To get current power state use following property:

@property
def power_state(self) -> const.PowerState:

Waiting for State Change

It is possible to pass await_new_state set to True when turning on or off a device to have pyatv wait for a state change. E.g. calling interface.Power.turn_off will block until the device has powered off:

await pwrc.turn_off(await_new_state=True)

If the device is already off, it will return immedietly.

To not block indefinitely, use wait_for with a timeout:

await asyncio.wait_for(pwrc.turn_off(await_new_state=True), timeout=5)