question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Device and power state are not aligned

See original GitHub issue

Describe the bug

Device and power states are managed independently by pyatv. Unfortunately, the power state is a bit unreliable and it sometimes happens that it reports Off even though something is playing. One such case is when using the Apple TV as an AirPlay receiver, only to receive and play audio but not use any screen as output. The power state more or less mirrors if there is a monitor on or not (which is not totally true either because turn_on with Companion will cause the power state to be reported on On even if no screen is on). So it’s a pickle…

My suggestion is to at least change power state to on when something is playing as that makes more sense. It will potentially trigger lots of changes between on and off whenever media plays or not, so that’s the flipside of this.

Error log

No response

How to reproduce the bug?

Stream audio to an Apple TV without having the TV turned on: pyatv shall report Off as power_state but still provide a playing state.

What is expected behavior?

Power state should be reported as On.

Operating System

Any

Python

Other

pyatv

any

Device

Apple TV 4 and later

Additional context

Reported here: https://github.com/postlund/pyatv/issues/1333#issuecomment-961279579

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
postlundcommented, Dec 14, 2021

I know, that’s the problem. Trying to bend the universe here… As the feature is in there now, I would prefer to just keep it there and try to improve the situation as much as I can and people will have to live with a few oddities. Maybe it can be further improved over time as well. I’ll use that as my goal, but might have to change direction later on.

I think I know the issue, just need to come up with a test for it. The device_state solely depends on what the media player framework in the Apple TV says is currently playing. There are situations where the Music app remains active and paused, like a “default state”. So even you aren’t actively choosing what to play, something else might keep it looking like it is playing.

1reaction
postlundcommented, Dec 14, 2021

I would have preferred an optional flag for power management (or to not implement it at all actually), but I got run over on that because people are too keen on that feature unfortunately. It makes the code in the integration a bit…ugly… So I’ll have to think about this a bit.

But things should work rather OK as long as power state is updated correctly according to play state. So I think some additional work is needed to fix that. I didn’t think too much about it before, but this situation should never happen:

{"result": "success", "datetime": "2021-12-13T16:13:28.437542+01:00", "hash": "gnNF4NFEw\u2206n6gH8F48n", "media_type": "music", "device_state": "paused", "title": "UN DIA (ONE DAY)", "artist": "J Balvin, Dua Lipa, Bad Bunny & Tainy", "album": "UN DIA (ONE DAY) - Single", "genre": "Latin urban", "total_time": 231, "position": 41, "shuffle": "songs", "repeat": "off", "series_name": null, "season_number": null, "episode_number": null, "content_identifier": null, "app": "Muziek", "app_id": "com.apple.TVMusic"}
{"result": "success", "datetime": "2021-12-13T16:13:28.477203+01:00", "power_state": "off"}

As long as device_state is not idle, the power state must be totally ignored and it doesn’t seem to be. So I guess I need to go bug hunting here.

And yes, CEC is a total buggy sack of… yeah. It is a standard that has not been very well treated, mainly by manufacturers I guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory alignment is always power of 2
Modern computer memory is conceptually addressed as bytes, but the real hardware transfer is done in a multiple (a power of 2) of...
Read more >
HELP! Mouse Pointer not aligned with what is on my screen.
For about the past week I'm having an issue with my mouse pointer not aligning properly with what is the screen. It seems...
Read more >
An Alignment Page Prints after Every Power Up or Print Job
Follow these steps to resolve the issue of an alignment page that prints whenever the product is turned on or off, or a...
Read more >
Alignment, Nonalignment, and Small Powers: 1945-1965
world politics. Thus J. W. Burton argues that the nonaligned states are "not involved in the power dispute" between the United States and...
Read more >
The New Non-Aligned Movement | The Heritage Foundation
Previously served at the Department of State. This USSR-era map spots areas of the world aligned with the Western Powers by treaties, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found