howanghk / homebridge-ewelink

Homebridge plugin to control Sonoff relays with OEM firmware
MIT License
81 stars 46 forks source link

A big one - Refactoring & WebSocket Client Improvements #114

Open dhutchison opened 3 years ago

dhutchison commented 3 years ago

This is a much bigger set of changes than I was intending to include in a single PR, but here it goes. I think it is time to start getting these changes looked at by a wider group. Ideally we can get these tested & merged in.

This has done a pile of refactoring to remove duplication in the plugin for how it was reading the status for devices. As part of this, and adding experimental support for getting the device status with WebSockets (#74), the approach to loading data has been separated out. In lib, there is now an api.js file which handles all the API operations which the plugin was performing. This then internally deals with working out what needs to go to the REST, WebSockets and Lan mode APIs depending on the feature flags enabled.

These feature flags are now documented in the README file, which is worth reading to get a feel for the changes being introduced.

There is also an additional fakeFan setting which I have been using to allow testing of Fan type devices. This refactoring has removed a lot of duplication in how the fan Active and Light statuses were being loaded, as these were just switches.

This has introduced for the LAN and WebSocket clients caching of device status information (albeit for a short period for the latter), which should help with issues where the websocket is closed due to too many quick requests being made for the same device.

The main area I have been unable to test changes in is for Blinds, so hoping someone is able to try some pre-release code to check if my branch functions.

howanghk commented 3 years ago

Wow thank you @dhutchison ! That's a lot of hard work! It would take some time for me to review this before merging.

prasad-edlabadka commented 3 years ago

Any tentative date for merging this?

howanghk commented 3 years ago

Hi @prasad-edlabadka please try https://github.com/bwp91/homebridge-ewelink which is more active and better.