I’m writing a custom integration for some lights. The lights are integrated by polling manufacturer’s API. I get each light’s state from it - on/off, brightness, color temperature, etc. The problem comes when I change the state from HA. I write state via API inside async_turn_on. API response contains the new state and I call self.async_write_ha_state to update HA.
However, as soon as the handler is done async_update is called as well. It seems that there’s a bit of a lag on the API side. Even though my update responds with the correct new state, reading state from API immediately after still responds with the old one for a few milliseconds.
I’ve also tried using schedule_update_ha_state(force_refresh=False).
What I’m hoping to do is to delay calling async_update until the next polling interval. Ideally, it will be offset from the time I called the API to set the new state. For example, if I poll every minute on 00 second mark, and I update the state at 3:15:48 second, the next update will be 3:16:48 and not at 3:17:00. But I would take even not calling async_update immediately.