beveradb / sonoff-lan-mode-homeassistant

Home Assistant platform to control Sonoff switches running the latest Itead firmware, locally (LAN mode).
MIT License
74 stars 36 forks source link

After device is not operated for a long time, connection is dropped #66

Closed mattsaxon closed 5 years ago

mattsaxon commented 5 years ago

HA WebSockets library requirement for v6.0 which means ping/pong not fully implemented.

This PR (https://github.com/beveradb/pysonofflan/pull/48) can recover from this state, but the responsiveness of the switch is reduced.

Option to resolve;

  1. Upgrade HA to WS7
  2. Run 'local' copy of WS7 in custom_components folder
  3. Implement Ping/Pong on top of WS6
  4. Send other keep alive messages (e.g. switch messages)
  5. Switch away from WS to a different library
mattsaxon commented 5 years ago

A point of note which I am still trying to get my head around is that the requirements file https://github.com/beveradb/sonoff-lan-mode-homeassistant/blob/master/requirements_dev.txt specifies WebSockets 0.56, this seems to be from a different implementation (https://pypi.org/project/websocket_client/) as opposed to https://pypi.org/project/websockets/

What is the lineage here?

mattsaxon commented 5 years ago

Following on the option 1 above, upgrading HA to WS7, I can see that only a single component specifies WS6, which is webostv.

Furthermore, there is a fairly recent update to move from WS3.2 to WS6.0 here https://github.com/home-assistant/home-assistant/pull/16578.

mattsaxon commented 5 years ago

Further info. I tried to upgrade to WS7 manually, but I couldn't make this upgrade. First the discord.py component complained that the version was too new. I removed this component using 'pip', but I still couldn't force the upgrade. I wonder if this may be because I'm using hassio? (whilst I was able to remove discord and upgrade pip itself inside the docker container, when trying to upgrade to WS7, I got GCC errors.

I've abandoned the idea of upgrading for now due to the many dependencies and instead am pursuing option 3, to implement the ping/pong on top of WS6 in the SonoffLANModeClientProtocol class.

I have this working now and am testing.

beveradb commented 5 years ago

HA WebSockets library requirement for v6.0 which means ping/pong not fully implemented.

  1. Implement Ping/Pong on top of WS6

I'm glad to hear you've got option 3 (custom implementation of ping/pong) working, but the reinvention of the wheel is certainly frustrating, especially as it looks like it's down to a low-effort decision in the discord.py project...

requirements_dev.txt specifies WebSockets 0.56 What is the lineage here?

Sorry for the confusion here, that requirements_dev.txt file is probably totally meaningless at this point; it pre-dates the creation of pysonofflan and re-implementation of the core connectivity functionality in that project with support for async. I must have just forgotten to delete it from this project at that point - I've deleted it now.

The only actual requirement this project has is pysonofflan, which in turn only has these three dependencies.

Following on the option 1 above, upgrading HA to WS7, I can see that only a single component specifies WS6, which is webostv. the discord.py component complained that the version was too new

Yeah, from what I recall of my own attempts a few months ago, the webostv module actually has no issues if updated to use WS7, but the discord.py library falls over (see link above) unfortunately so would need a bit more investigation in that project first.

I've abandoned the idea of upgrading [...] pursuing option 3 I have this working now and am testing.

Awesome work, thank you!

mattsaxon commented 5 years ago

Resolved in latest pysonofflan 0.3.0