这是indexloc提供的服务,不要输入任何密码
Skip to content

Unable to listen play status / PushListener #2686

@bsamartins

Description

@bsamartins

What do you need help with?

Trying to listen to play status changes on my appletv.

I've used atvremote wizard to authorize pyatv and when running atvremote push_updates --id my_device_id I get events.

I've setup my own script to capture events but no event is being logged.

import asyncio
import pyatv
import sys
from pyatv import interface
from pyatv.const import (
    FeatureName,
    FeatureState,
)

device_id = set(["my_device_id"])

class MyPushListener(interface.PushListener, interface.DeviceListener):
    def playstatus_update(self, updater, playstatus: interface.Playing) -> None:
        print(f"playstatus updated: {playstatus}")

    def playstatus_error(self, updater, exception: Exception) -> None:
        print(f"playstatus error: {exception}")

    def connection_lost(self, exception):
            print("Lost connection:", str(exception))

    def connection_closed(self):
        print("Connection closed!")

async def main():
    print(f"device id {device_id}")

    loop = asyncio.get_event_loop()    

    results = await pyatv.scan(identifier=device_id, loop=loop)

    if not results:
        print("Device not found")
        exit(-1)

    for device in results:
        print(f"Device: {device.name}, {device.services}")

    try:
        device = results[0]
        atv = await pyatv.connect(device, loop=loop)        
        print("Connected")
        
        if atv.features.in_state(FeatureState.Available, FeatureName.PushUpdates):
            print(f"push updates available: {atv.push_updater}")
            atv.push_updater.listener = MyPushListener()
            atv.push_updater.start()
            print(f"Push updater active: {atv.push_updater.active}")
        else:
            print("NOTE: Push updates are not supported in this configuration")

        print("Waiting")        
        loop.run_in_executor(None, sys.stdin.readline)        
    except Exception as ex:
        print(f"Failed to connect to device: {ex}")
        if atv:
            atv.close()
    
asyncio.run(main())
device id {'my_device_id'}
Device: AppleTV, [<pyatv.core.MutableService object at 0x105be86e0>, <pyatv.core.MutableService object at 0x105a879d0>, <pyatv.core.MutableService object at 0x105a87750>]
Connected
push updates available: <pyatv.core.facade.FacadePushUpdater object at 0x105be9550>
Push updater active: True
Waiting

Not sure what I'm doing wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions