From 30a6095342e7082d8ea542af677b67123abf2489 Mon Sep 17 00:00:00 2001 From: baunan <59838425+baunan@users.noreply.github.com> Date: Sun, 12 Nov 2023 08:52:14 +0100 Subject: [PATCH 1/2] Update coordinator.py update data update data o handle loop --- custom_components/sector/coordinator.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/custom_components/sector/coordinator.py b/custom_components/sector/coordinator.py index 82dcbf8..7571a65 100644 --- a/custom_components/sector/coordinator.py +++ b/custom_components/sector/coordinator.py @@ -142,11 +142,14 @@ async def async_first_refresh(self) -> dict[str, Any]: if not response_panellist: raise UpdateFailed("Could not retrieve panels") LOGGER.debug("Panels retrieved: %s", response_panellist) + data2 = {} for panel in response_panellist: - data: dict[str, Any] = {panel["PanelId"]: {}} - data[panel["PanelId"]]["name"] = panel["DisplayName"] - data[panel["PanelId"]]["id"] = panel["PanelId"] - data[panel["PanelId"]]["alarmstatus"] = 0 + data1: dict[str, Any] = {panel["PanelId"]: {}} + data1[panel["PanelId"]]["name"] = panel["DisplayName"] + data1[panel["PanelId"]]["id"] = panel["PanelId"] + data1[panel["PanelId"]]["alarmstatus"] = 0 + data2.update(data1.copy()) + data: dict[str, Any] = data2 panel_id = panel["PanelId"] LOGGER.debug("trying to get Panel for panel_id: %s", panel_id) From c981f7239a0b2a779d2c60cc035ed7c755de4b19 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 12 Nov 2023 22:59:32 +0100 Subject: [PATCH 2/2] Mods --- custom_components/sector/coordinator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/custom_components/sector/coordinator.py b/custom_components/sector/coordinator.py index 7571a65..e006360 100644 --- a/custom_components/sector/coordinator.py +++ b/custom_components/sector/coordinator.py @@ -142,14 +142,12 @@ async def async_first_refresh(self) -> dict[str, Any]: if not response_panellist: raise UpdateFailed("Could not retrieve panels") LOGGER.debug("Panels retrieved: %s", response_panellist) - data2 = {} + return_data = {} for panel in response_panellist: - data1: dict[str, Any] = {panel["PanelId"]: {}} - data1[panel["PanelId"]]["name"] = panel["DisplayName"] - data1[panel["PanelId"]]["id"] = panel["PanelId"] - data1[panel["PanelId"]]["alarmstatus"] = 0 - data2.update(data1.copy()) - data: dict[str, Any] = data2 + data: dict[str, Any] = {panel["PanelId"]: {}} + data[panel["PanelId"]]["name"] = panel["DisplayName"] + data[panel["PanelId"]]["id"] = panel["PanelId"] + data[panel["PanelId"]]["alarmstatus"] = 0 panel_id = panel["PanelId"] LOGGER.debug("trying to get Panel for panel_id: %s", panel_id) @@ -200,6 +198,8 @@ async def async_first_refresh(self) -> dict[str, Any]: } data[panel["PanelId"]]["switch"] = switch_dict + return_data.update(data.copy()) + LOGGER.debug("Trying to get user info") response_getuser = await self._request(API_URL + "/Login/GetUser") if not response_getuser or not isinstance(response_getuser, dict): @@ -207,7 +207,7 @@ async def async_first_refresh(self) -> dict[str, Any]: LOGGER.debug("User info retrieved %s", response_getuser) self.logname = response_getuser.get("User", {}).get("UserName") - return data + return return_data async def _async_update_data(self) -> dict[str, Any]: """Fetch info from API."""