Best methodology to avoid UI flip-flopping on custom components w/ "slow" external libraries?

Hello everyone,

I am trying to develop some basic custom components for HA for my own use (ie. basic switch entity controling and requesting states on a 3rd party system).

While everything seems to work smothly, I am facing a flip-flop issue on the lovelace UI for the attached switch button. When the switch is toogled from off to on in the UI, it switches immediately back to off for some time - from 1 to 60 seconds) … then back to on.

I perfectly know the reason : the external library I am using takes time to aknowledge the change, so for several seconds after beeing asked to switch the state, it library will still answser the previous state when is_on() is fired, of even after an update(). Because of this, the UI will only reflect the right value after the next CONF_SCAN_INTERVAL …

Question : Is there any way to kind of “delay” for a few seconds the update() and is_on() state check after a change is triggered on a switch in the UI ? That would fix the flip-flop effect.