postlund/pyatv

Use custom ClientSession for AirPlay

postlund opened this issue · 1 comments

Short feature/function description
There is an AirPlay issue when using pyatv in Home Assistant where the connection is lingering after playing something using play_url (the spinning wheel is shown on the screen). This is because aiohttp keeps the connection laying around in case it's needed in the future (which is correct behavior), but it causes this problem. I belive it can be solved if the used ClientSession is disposed, but since the sessions is re-used from Home Assistant that isn't really possible.

The suggestion is to internally create a new ClientSession for AirPlay and use that instead of the provided one.

What needs to be done?
Change to use a new ClientSession for AirPlay when connecting. It must be disposed properly.

Is this a breaking change?
No

Anything else worth knowing?
Since authentication is performed, the same session must be used when authenticating and playing the media. So it's not possible to just change in player.py.

Verified to work by @junologue in #209. Closing.