From 1548e8c364e848e42a874d0ff07691c37e6e50e6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 25 Jan 2021 20:17:15 +0300 Subject: [PATCH] fix multiple megas --- custom_components/mega/http.py | 5 ++--- custom_components/mega/hub.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/custom_components/mega/http.py b/custom_components/mega/http.py index 9db655d..061d00d 100644 --- a/custom_components/mega/http.py +++ b/custom_components/mega/http.py @@ -26,8 +26,7 @@ class MegaView(HomeAssistantView): def __init__(self, cfg: dict): self._try = 0 self.allowed_hosts = {'::1'} - self.callbacks: typing.DefaultDict[int, typing.List[typing.Callable[[dict], typing.Coroutine]]] \ - = defaultdict(list) + self.callbacks = defaultdict(lambda: defaultdict(list)) self.templates: typing.Dict[str, typing.Dict[str, Template]] = { mid: { pt: cfg[mid][pt][CONF_RESPONSE_TEMPLATE] @@ -64,7 +63,7 @@ class MegaView(HomeAssistantView): data = data.copy() ret = 'd' if port is not None: - for cb in self.callbacks[port]: + for cb in self.callbacks[hub.id][port]: cb(data) template: Template = self.templates.get(hub.id, {}).get(port) if hub.update_all: diff --git a/custom_components/mega/hub.py b/custom_components/mega/hub.py index 7de399d..85964f3 100644 --- a/custom_components/mega/hub.py +++ b/custom_components/mega/hub.py @@ -307,7 +307,7 @@ class MegaD: if self.mqtt_inputs: self._callbacks[port].append(callback) else: - self.http.callbacks[port].append(callback) + self.http.callbacks[self.id][port].append(callback) async def authenticate(self) -> bool: """Test if we can authenticate with the host."""