Skip to content

Commit

Permalink
Fix InvalidStateError: invalid state when enable statistics sensors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Necroneco committed Sep 18, 2024
1 parent 82ad2d9 commit a0ed833
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions custom_components/xiaomi_gateway3/core/gate/miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,17 @@ async def mqtt_publish_multiple(
self, device: XDevice, payload: dict, gw2, delay: float = 1.0
):
fut = asyncio.get_event_loop().create_future()
device.add_listener(fut.set_result)

def try_set_result(r):
if not fut.done():
fut.set_result(r)

device.add_listener(try_set_result)
await self.mqtt.publish("miio/command", payload)
try:
async with asyncio.timeout(delay):
await fut
except TimeoutError:
await gw2.mqtt.publish("miio/command", payload)
finally:
device.remove_listener(fut.set_result)
device.remove_listener(try_set_result)

0 comments on commit a0ed833

Please sign in to comment.