core: Harmony Fails To Update 0.85.0dev0

Home Assistant release with the issue:

0.85.0dev0

Last working Home Assistant release (if known):

0…84.3

Operating environment (Hass.io/Docker/Windows/etc.):

venv Component/platform:

remote.harmony

https://www.home-assistant.io/components/remote.harmony/

Description of problem:

After attempting to start an activity or turning off the remote, the remote fails to update even though the action was performed successfully.

On Services tab remote.turn_on

{
  "entity_id": "remote.harmony_hub_bedroom",
"activity": "Bedroom SHIELD TV"
}

Or on the front end if the remote is on turn it off by toggling it.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

remote:
 - platform: harmony
   name: Harmony Hub Bedroom
   host: 192.168.1.21

Traceback (if applicable):

2018-12-19 09:06:33 ERROR (MainThread) [homeassistant.helpers.entity] Update for remote.harmony_hub_bedroom fails
Traceback (most recent call last):
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 347, in async_device_update
    await self.async_update()
  File "/home/pi/home-assistant/homeassistant/components/remote/harmony.py", line 205, in async_update
    activity_id = await self._client.get_current_activity()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 234, in get_current_activity
    'vnd.logitech.harmony/vnd.logitech.harmony.engine'
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 184, in _send_request
    return await self._wait_response(msgid)
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 190, in _wait_response
    response_json = await self._websocket.recv()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/websockets/protocol.py", line 319, in recv
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006, no reason.
2018-12-19 09:06:38 ERROR (MainThread) [homeassistant.helpers.entity] Update for remote.harmony_hub_bedroom fails
Traceback (most recent call last):
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 347, in async_device_update
    await self.async_update()
  File "/home/pi/home-assistant/homeassistant/components/remote/harmony.py", line 205, in async_update
    activity_id = await self._client.get_current_activity()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 234, in get_current_activity
    'vnd.logitech.harmony/vnd.logitech.harmony.engine'
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 158, in _send_request
    await self._perform_connect()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 113, in _perform_connect
    if not self._websocket.closed:
AttributeError: 'WebSocketClientProtocol' object has no attribute 'closed'
2018-12-19 09:06:44 ERROR (MainThread) [homeassistant.helpers.entity] Update for remote.harmony_hub_bedroom fails
Traceback (most recent call last):
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
    await self.async_device_update()
  File "/home/pi/home-assistant/homeassistant/helpers/entity.py", line 347, in async_device_update
    await self.async_update()
  File "/home/pi/home-assistant/homeassistant/components/remote/harmony.py", line 205, in async_update
    activity_id = await self._client.get_current_activity()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 234, in get_current_activity
    'vnd.logitech.harmony/vnd.logitech.harmony.engine'
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 158, in _send_request
    await self._perform_connect()
  File "/home/pi/home-assistant/lib/python3.6/site-packages/pyharmony/client.py", line 113, in _perform_connect
    if not self._websocket.closed:
AttributeError: 'WebSocketClientProtocol' object has no attribute 'closed'

The bottom error continues to repeat itself until HA is restarted, then the correct state is shown until the next action is performed.

Additional information: CC: @ehendrix23

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (22 by maintainers)

Most upvoted comments

Thanks, that just seems to confirm further to me on what might be going on and then what I’m working on now should fix this. 😃

@nolenjohan , The version in 0.84.6 works with web sockets as it was a patch to allow Harmony to keep on working with the new firmware (which dropped XMPP).

What was suggested was temporary for some to get a updated version in their HASS while it was still further tested and then would be going for approvals.

Version 0.85 includes a new harmony platform based on a new library providing a number of further improvements as well. It is still based on web sockets as Logitech has not made a GA release available with XMPP support back in. Once they do I will then update the library to use XMPP instead as that is what’s Logitech’s initial direction provided for this.

For now, if it works for you I would not do anything until you can update your HASS.

@dshokouhi, @ronytomen

I’ve got a full updated version ready using a new module I developed. This one will be able to better handle everything. If you would be willing to test it out and let me know of any issues. Working good here but then again I do not have every scenario here. 😃 This should resolve the issue you have reported as well.

It has the following improvements:

  • Full async support
  • No more polling for updates, when an activity is changed from another source (i.e. remote) then HASS will be updated through a notification
  • Set available state if for some reason disconnected from HUB.
  • Automatic reconnect to HUB if disconnected
  • When sending a command with repeat it will be send done as 1 “transaction” preventing anything else from HASS to send a command in the middle.
  • Automatic config update. If anything is changed on the HUB (i.e. device added, rename, …) then it is detected and configuration is updated. The Harmony files with the configuration are automatically updates as well then.
  • Unique message identifications ensuring that HUB responses are correctly identified and processed

How to update:

  1. In your HASS config folder create folder custom_components/remote (if not there)
  2. Change to that folder
  3. Make a copy of the current harmony.py (if already there): cp harmony.py harmony.py.bak
  4. Download updated harmony component: curl https://raw.githubusercontent.com/ehendrix23/home-assistant/Use_aioharmony_for_harmony/homeassistant/components/remote/harmony.py -o harmony.py

Now restart HASS. The new aiomodule will be downloaded automatically.

If you have issues, reverting back is as easy as replacing harmony.py in your custom folder back with the copy made earlier (harmony.py.bak) and restarting HASS.

Appreciate it!

I’m not 100% sure, but I think the issue here is that it is still waiting for responses on the start activity when at the same time having send a request for update. And what end up might be having 2 different ones reading (or something like that). Got it somewhat in my mind on what is going on, just the explaining is the issue.

I was already going to look into how we handle responses etc. to be able to re-enable callback so that HASS does not have to poll every 5 seconds. Going to be a bit before I have something on that but I think it might help with this issue as well.

I think right now in your case there are 2 tasks (or more) running to read from that socket ending up causing this issue.

My idea is to have only 1 running all the time to read anything coming in. When something is then executed and needs a response it will then “register” with the “reader” identifying the message ID or so it is waiting for. When the “reader” then receives something it will match it with the message ID and provide the response to the correct one.

But, it will take me a bit of time to develop and then do some initial testing. Not to mention to think a bit more on exactly how I would do this. <g>.

Yup that is correct only those 2 service calls it seems and np happy to help! If you need anything else feel free to tag me, I am also on discord same user name 😃