Refactor coordinator
Closed this issue · 7 comments
Inspired by the work of @EuleMitKeule the coordinator
should be refactored from the philips.py
file
I have found a way to request continuous status updates from the CX3550/01 fan and thought I'd share my findings here:
The only way to get status updates seems to be to send commands to the fan. We can use this to send the command to reduce the beeper volume to 0 every few seconds. This way we don't get annoyed by the constant beeping by the status request commands being sent, but get notified even when the fan is manipulated by directly pressing buttons. I have tried this out in a sample python project and it works great. I think this should be included as an optional mechanism to poll status updates in the coordinator for entities that define such a command.
For devices that do not have such a command, the state has to be assumed. This can be done by modifying the local copy of the device state every time a command is invoked by Home Assistant. When a status update is received, the dictionary then gets updated with the actual state.
You mean introducing a setting to poll status for people who don't get automatic push updates?
I lack that experience as so my devices push updates so the time.
As to your second point: I noticed in your code that you did this already for the fan entity and I've copied this over for all other entities as well in the refactoring.
This is also one reason why the refactoring right now requires to setup all devices fresh. Note to self: I need to implement an automatic upgrade path.
I lack that experience as so my devices push updates so the time.
The CX3550/01 does not send any status updates on its own, and the get_status()
method of the CoAPClient
from aioairctrl
does not work either. That's why the entity's representation of the state can quickly become out of sync when controlling the fan manually until a command is sent and the latest status is received.
That's why I think it would be a good idea to allow the subentities to optionally define a variable that holds the command that should be sent every x seconds to get a status update.
If you want I could implement this and open a PR towards the branch you are working on refactoring the coordinator.
We could make that a config option
Btw, I moved back from my fork to this repo and the new coordinator seems to work great with the CX3550/01 fan. Thanks!
I still think the optional state polling via the beep command would be a great addition, since the fan doesn't push any state updates when something is changed manually on the device.
Ideally, there is a config option setting that allows the integration to be reconfigured from the UI with a polling interval for this. Let's create a new issue for that idea. Would you still be happy to provide a PR?