safepay / sensor.fronius

A Fronius Sensor for Home Assistant
MIT License
80 stars 32 forks source link

Improvment to Async I/O to fix warning in HA 0.109 and performance improvements #29

Closed nilrog closed 4 years ago

nilrog commented 4 years ago

This pull-request contains two changes:

  1. Fix the warning about I/O being done on the main thread (check/warning introduced in HA 0.109),
  2. Changed sensor state updated from polling by HA to pushing to HA.

Async I/O (1) This integration was calling requests.get() three times everytime HA polled the state of the sensors and was pinpointed by HA with a warning starting in 0.109. The new implementation uses aiohttp to send the request so all I/O is now async.

Polling vs. Pushing (2) Previously this sensors published by this integration was polled by HA at regular intervals. And the sensor "updates" could be with slightly out-dated data. The new implementation will push the sensor states to HA as soon as the response to the request(s) towards the inverter comes back. Each API endpoint is responsible for pushing out sensor states as soon as the response to their request is received. This change also allows the user to configure, via scan_interval, how frequently they want this integration to poll the inverter.

Bonus I updated the README with some information on how to create additional sensors needed to configure the energy view in the Power Wheel card.

I published my changes yesterday and apart for myself I have three other persons reporting back that the warning in HA is gone and the sensors are updating properly. See this issue for info: https://github.com/safepay/sensor.fronius/issues/28

safepay commented 4 years ago

Thanks for doing this. Beyond my capabilities!