this is my first time writing a new topic. So i am hope that i am doing everything right.
I am learning to develop a HA-Integrations and therefore i read the whole starting development guidelines at https://developers.home-assistant.io/docs/development_index .
So my current question is a conceptual question therefore here are just some code snippets:
I have written a integration that uses a library to interact with a cover. The integration fetch the data with polling.
Like in the guides there is a async_setup_entry method which load the modules.
The cover-class contains the basic methods:
async_open_cover... for opening the cover
async_close_cover... for closing the cover
property state that returns STATE_OPEN or STATE_CLOSED depending on the state
async_update... which calls the library and get the current state of the module
So now the interesting part. The cover is very slow. So if I send the command
async_open_cover... the cover start to move but take some time to open. The library response optimistically with state open, So everything is fine and the frontend of HA shows open. But HA calls directly after the
async_update... and because the real state of the cover is still closed until the cover is fully open, the state switches back to close.
If that happens, i have to wait for the next SCAN_INTERVAL which will set the state correctly.
If i remove the code in the
async_update... method, everything works fine. But the drawback is, that the states won’t be updated within the automatic polling of HA.
I have no clue how to solve this problem in a beautiful manner.
What is the right way to solve such problems?