alandtse / tesla

Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login.
Apache License 2.0
555 stars 99 forks source link

perf: avoid writing state when the controller did not actually update #954

Closed bdraco closed 2 months ago

bdraco commented 2 months ago

https://github.com/alandtse/tesla/pull/953 didn't work because the data is actually a bool. This is a second attempt

948 made me realize that the car data was being polled far less frequently than I thought as the underlying library was caching, but every time the coordinator fired, it would still callback all the listeners and write the state of all the entities which meant we ended up writing state every 10 seconds even if nothing has changed.

Keep track of when the controller was last updated in each entity and if it has not changed, we skip the state write.

This reduced the number of calls to async_write_ha_state by 62% on my production HA instance!

bdraco commented 2 months ago

This works as expected

bdraco commented 2 months ago

need to push it to my other system for testing so I have it tested on two systems first

bdraco commented 2 months ago

73 writes/min, down from 1000s

Screenshot 2024-04-26 at 12 40 25 PM
bdraco commented 2 months ago

down to 78 on the other instance, nice!

Screenshot 2024-04-26 at 12 57 55 PM
alandtse commented 2 months ago

Do we need to bump the minimum ha version too?

bdraco commented 2 months ago

No need to bump the minimum version. It's more than new enough with this design