fsaris / home-assistant-zonneplan-one

Unofficial Zonneplan integration for Home Assistant
https://github.com/fsaris/home-assistant-zonneplan-one
MIT License
104 stars 17 forks source link

Only call the summary endpoint once #83

Closed fsaris closed 9 months ago

fsaris commented 9 months ago

From #49

We have noticed that a fair amount of HomeAssistant installations have started requesting updates every 10 seconds, for some installations this has lead to an average of 1 request every second. Did you change something or do these people have a version where the update timer was changed to 10 seconds?

We would love to leave the current limits in place but if this continues we will be forced to implement rate limiting since we are not expecting this many requests.

I also noticed that if a customer has electricity and gas that the integration requests the /summary endpoint for both connections. The data in /summary is essentially the same for each connection.

Can you look into this and see why it's happening?

@rdgout the refresh was only for a short time set to 10 seconds and this wasn't part of a official release. Maybe it's the charge point users that are testing a beta, but there is already a new release that only polls every 5 minutes.

Will have a look at the summary call

fsaris commented 9 months ago

@rdgout are you sure you're seeing multiple calls to the summary endpoint? The code should already prevent it from being called more then once (if there is a response) https://github.com/fsaris/home-assistant-zonneplan-one/blob/97e14184ec2e3a77c0da943bc5be3b22badba013/custom_components/zonneplan_one/coordinator.py#L129

fsaris commented 9 months ago

Ah, found it.

It's called multiple times for the users that are still on the 10seconds interval. Because of the etag check that was added the request can give no response and it will try the other connection.

Now interval is back to 5min it shouldn't happen anymore. But will also update the code that it doesn't depend on a response the prevent a second request

rdgout commented 9 months ago

@fsaris great to hear you found it!

We were seeing about 40% more traffic coming our way so it might have been your beta testers (and some others who were on that release). It is pretty important that the 10 seconds limit doesn't work like that for all requests but only for the charge point requests.

I think the next best thing to do for this integration is add some sort of caching layer which allows the amount of requests to be lowered down. For example, the user-accounts/me endpoint provides information about which contracts you can inquire about. However, it's probably not needed to request this every 5 minutes. Once every hour should probably be more than enough, provided you store the contracts locally and only refresh every hour or when the local store is empty.