From 3e1499f78b5989667b1bdbda92dcb202ca07c607 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 22 Jan 2021 12:16:32 +0300 Subject: [PATCH] fix get_port --- custom_components/mega/hub.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/custom_components/mega/hub.py b/custom_components/mega/hub.py index c192eb9..5ee5c3d 100644 --- a/custom_components/mega/hub.py +++ b/custom_components/mega/hub.py @@ -71,6 +71,7 @@ class MegaD: self._callbacks: typing.DefaultDict[int, typing.List[typing.Callable[[dict], typing.Coroutine]]] = defaultdict(list) self._loop = loop self.values = {} + self.last_port = None self.updater = DataUpdateCoordinator( hass, self.lg, @@ -176,7 +177,7 @@ class MegaD: qos=2, retain=False, ) - await asyncio.wait_for(self.cnd.wait(), timeout=15) + await asyncio.wait_for(self.cnd.wait_for(lambda: self.last_port == port), timeout=15) async def get_all_ports(self): for x in range(37): @@ -189,7 +190,8 @@ class MegaD: async with self.cnd: self.last_update = datetime.now() self.values[port] = value - self.cnd.notify() + self.last_port = port + self.cnd.notify_all() def _process_msg(self, msg): try: