Open bowenjfung opened 9 months ago
It's really hard to tell why this happens, it obviously has to do with the connect phase somehow (when setting up the Companion connection). Would have to check logs in the Apple TV by enabling development mode to see what really happens. I recommend that you create a daemon that maintains a persistent connection instead of polling (and listen to power changes using a listener). It will be more reliable, faster and likely result in fewer issues. There will likely still be issues every now and then, don't believe there's any way to "fix" that. But you can just re-connect in those cases. Is also possible to use atvscript
.
Describe the bug
I'm using
homebridge-cmdswitch2
as a dummy switch for my ATV.I've found that using Companion pairing (rather than Airplay) is more consistent when it comes to reading the power state of the ATV, and can accurately identify when just audio is playing (turning on speakers and avoiding turning on my TV).
However, when I use Companion pairing for the
state_cmd
atvremote command (rather than Airplay), I get a regularly recurring logged error a couple of times an hour.My understanding is that the
state_cmd
is triggered off by an error, so a call likepower_state | grep -i 'PowerState.On'
will trigger the switch on when the ATV power state is on, but fail silently otherwise (or at least this is what is happening when I run it in a CLI). So the command itself seems fine, and that's validated by the fact that the regularity of the error doesn't seem to be related to thestate_cmd
polling interval.This error doesn't seem to cause any issues with my setup, but might be incident with some RAM buildup. I can't quite tell what the timeout is related to.
Error log
How to reproduce the bug?
Set up a
homebridge-cmdswitch2
using a Companion pairedstate_cmd
atvremote call to check ATV power state (power_state | grep -i 'PowerState.On'
).What is expected behavior?
No errors!
Operating System
Linux
Python
Other
pyatv
0.14.0
Device
Apple TV 4K (3rd Gen) iOS 17
Additional context
NA