RogerSelwyn / Home_Assistant_SkyQ_MediaPlayer

Home Assistant SkyQ Media player component
MIT License
103 stars 17 forks source link

[BUG] Since updating to 2.7.10 my Sky Q box regularly becomes unavailable on HA #89

Closed jampez77 closed 2 years ago

jampez77 commented 2 years ago

Describe the bug
Since updating to 2.7.10 my Sky Q box regularly becomes unavailable on HA.

To be precise it will report as playing then off, then unavailable and then back to playing.

To Reproduce
Steps to reproduce the behavior: There is no trick to reproducing this, It's not tied to any channel or time. I just watch TV for a while and the state will change from 'playing' to 'off' to 'unavailable' and then back to 'playing'.

In reality the state should always be 'playing'

Expected behavior
I would expected the correct state to be represented in HA.

Screenshots

Screenshot 2022-01-13 at 11 31 08

Component versions

  1. What version of SkyQ component are you using? 2.7.10
  2. What was the last version where the problem was not shown? 2.7.9

Your configuration
How have you setup your devices, by UI or YAML? UI

Output of HA logs
Paste the relavant output of the HA log here.

2022-01-13 11:12:57 ERROR (SyncWorker_55) [pyskyqremote.classes.deviceaccess] X0030U - Error occurred: 192.168.1.113 : [Errno 111] Connection refused
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/pyskyqremote/classes/deviceaccess.py", line 101, in callSkyWebSocket
    ws = websocket.create_connection(WS_BASE_URL.format(self._host, method))
  File "/usr/local/lib/python3.9/site-packages/websocket/_core.py", line 606, in create_connection
    websock.connect(url, **options)
  File "/usr/local/lib/python3.9/site-packages/websocket/_core.py", line 249, in connect
    self.sock, addrs = connect(url, self.sock_opt, proxy_info(**options),
  File "/usr/local/lib/python3.9/site-packages/websocket/_http.py", line 130, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  File "/usr/local/lib/python3.9/site-packages/websocket/_http.py", line 208, in _open_socket
    raise err
  File "/usr/local/lib/python3.9/site-packages/websocket/_http.py", line 185, in _open_socket
    sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
2022-01-13 11:12:57 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.living_room fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 487, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 691, in async_device_update
    raise exc
  File "/config/custom_components/skyq/media_player.py", line 330, in async_update
    await self._async_updateCurrentProgramme()
  File "/config/custom_components/skyq/media_player.py", line 454, in _async_updateCurrentProgramme
    if app.appId == APP_EPG:
AttributeError: 'str' object has no attribute 'appId'
2022-01-13 11:24:27 WARNING (MainThread) [custom_components.skyq.media_player] W0030M - Device is not available: Living Room
RogerSelwyn commented 2 years ago

The change from 2.7.9 to 2.7.10 didn't touch anywhere near this piece of code and unless you are installing via yaml will not have affected you at all.

That said, you shouldn't be getting this error in the log, so I'll try to identify what the issue is.

jampez77 commented 2 years ago

Thanks, I did think the changes for 2.7.10 sounded unrelated.

Not sure it will matter but I've manually set the IP address on the Sky Q box itself.

RogerSelwyn commented 2 years ago

This has identified a bug (which in 99% of cases you'd never see), but when I look at that pair of errors it shows your SkyQ box has rejected the connection (which was to find out what the current app is that is running (usually the EPG). I'd change some coding around that some time back, and this has identified where I wasn't handling that failure.

I'll release a new version shortly which should remove the W0030M error, but the X0030U error looks valid.

RogerSelwyn commented 2 years ago

This release will resolve the W0030M error. X0030U suggests your SkyQ box is rejecting websocket calls. If it happens every 5 seconds (or at least I think it is 5) then it is always rejecting. This is the only websocket call it makes, so I'll take a look and see if I can replace it with a restapi call, but I don't think that is possible.

https://github.com/RogerSelwyn/Home_Assistant_SkyQ_MediaPlayer/releases/tag/v2.7.11

RogerSelwyn commented 2 years ago

This is the only websocket call it makes, so I'll take a look and see if I can replace it with a restapi call, but I don't think that is possible.

I can't see an alternative in the various apis that I am aware of.

jampez77 commented 2 years ago

Thanks for the quick turn around. I've updated it now, will keep an eye on it and let you know if it's happening. So far so good though.

jampez77 commented 2 years ago

So it's just happened again unfortunately, here are the logs:

2022-01-13 14:00:28 WARNING (MainThread) [custom_components.skyq.sensor] W0010S - Device is not available: Living Room Used Storage
2022-01-13 14:00:40 WARNING (MainThread) [custom_components.skyq.media_player] W0030M - Device is not available: Living Room
RogerSelwyn commented 2 years ago

That suggests the connection to your SkyQ box is unstable., and I was wrong saying it would get rid of W0030M (sorry), it removed the error: 'AttributeError: 'str' object has no attribute 'appId'

W0030M means it can't access your box to check to see if it is switched on. You can check whether this is true using this query:-

http://192.168.x.xxx:9006/as/system/information

If it is momentary drops in connection, then you may need to automate it using the HA restful sensor - https://www.home-assistant.io/integrations/sensor.rest/

It is looking for an 'activeStandby' setting of true/false

jampez77 commented 2 years ago

It's definitely switched on as I'm currently watching it. I've looked at the system info and realised that it must be the powerline adapter I'm using that's dropping out. Will have a look to confirm if i can.

RogerSelwyn commented 2 years ago

You wouldn't get that error, even if in standby. It means it can't contact the box, (which in Eco power mode you will get at 2:45 am as it goes into deep sleep), so there is a network problem. It could be your powerlines are going into some sort of power save. I use Devolo Magic 2 and they work fine.

jampez77 commented 2 years ago

I have a few TP link ones and they've been solid for the longest time. I did cut the power off the other day while putting a socket in so maybe that's related, I'm also seeing it with other devices on powerline adapters so pretty safe to say that's the culprit.

jampez77 commented 2 years ago

For anyone encountering similar problems. I eventually figured out that the Sky Q box itself was to blame for these issues.

To fix I reset the Network setup on the box and viola all is well now.