cyr-ius / cozytouchpy

Cozytouch python implementation
GNU General Public License v3.0
12 stars 7 forks source link

Cache mechanism #4

Closed bestlibre closed 3 years ago

bestlibre commented 4 years ago

This is a continuation of https://github.com/biker91620/cozypy/issues/7

I will try to get the json ASAP.

I'm still thinking that if it is possible to get the data for all the devices in one call, it should be done. I have 9 heaters and there's at least one call to the API for each of them. I'm suspecting more, one for each sensor in home assistant.

cyr-ius commented 4 years ago

I completely agree, if we want to limit the number of calls, we must necessarily implement an HA coordinator, because HA is basically designed to make a call by entity. It is not a problem for me to do so.

The problem is not the HA plugin but the Cozytouchpy API which is written to make many calls.

I started from this API because unfortunately I do not have enough elements to write an API which correctly exploits the Overkiz json for all devices.

bestlibre commented 4 years ago

If you call 'https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup' instead of 'https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup/devices' you get a json with more information (bidge, rooms, place, etc). But for the devices data I think that the 'setup/devices' url is sufficient.

This is a json with the information from one heater. Let me know if I can try something.

cyr-ius commented 4 years ago

Very good I'm rewriting the cozytouch API to make it much easier to use in the HA plugin

bestlibre commented 4 years ago

I will not have the time to propose a PR porting the new logic (from the hotfix branch) to the heater. But if you can do it, I will test it

bestlibre commented 4 years ago

Have you made some progress on the cozytouchpy rewrite ?

I have found this doc about the coordinator in home-assistant. I think this is probably the right way to integrate cozytouch in home assistant :

Your modification of water_heater in hass-cozytouch goes in the right direction, but the use of the coordinator will permit to exploit data in climate, sensor and binary_sensor.

bestlibre commented 4 years ago

I have looked at the problem again, and I think I have a solution. With the switch to asynchronous logic it is possible to keep the update in the main thread and this simplify the caching of the data. I have made two pull request, in this project and in the home assistant integration This is still a work in progress but it is working. I have dramatically reduced the number of calls to the API.

What are you thinking of these PR ?

cyr-ius commented 4 years ago

the first version that I modified of biker had been to carry it entirely in asynchronous unfortunately in the new version of HomeAssisant, I encountered problems because it controls the calls in their loop of events and I thus made a roll back. I will test again with your PR My first version with asyncio https://github.com/Cyr-ius/cozytouchpy/tree/v1.5.0/cozytouchpy

bestlibre commented 4 years ago

I have switched from requests to aiohttp which is asyncio friendly.

cyr-ius commented 4 years ago

I just released a beta version of cozytouch with your PR https://pypi.org/project/cozytouchpy/1.6.2b0/

I just tested the component in HA. Everything seems good to me. I finish my tests and if everything is OK, I push a version tomorrow