From 139a6473d23bec7cbd8a045da688436e5d2fbbfe Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 07:52:27 +0000 Subject: [PATCH 01/15] Add unique home ID device dispatch --- homeassistant/components/tado/__init__.py | 26 +++++++++------ homeassistant/components/tado/const.py | 3 +- .../components/tado/device_tracker.py | 32 +++++++++++++------ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 7f166ccf01acb..b8e03a0a4a11f 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -27,6 +27,7 @@ INSIDE_TEMPERATURE_MEASUREMENT, PRESET_AUTO, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, + SIGNAL_TADO_MOBILE_DEVICES_UPDATE, SIGNAL_TADO_UPDATE_RECEIVED, TEMP_OFFSET, UPDATE_LISTENER, @@ -161,6 +162,7 @@ def __init__(self, hass, username, password, fallback): self.tado = None self.zones = None self.devices = None + self.mobile_devices = None self.data = { "device": {}, "mobile_device": {}, @@ -180,13 +182,14 @@ def setup(self): # Load zones and devices self.zones = self.tado.get_zones() self.devices = self.tado.get_devices() + self.mobile_devices = self.tado.get_mobile_devices() tado_home = self.tado.get_me()["homes"][0] self.home_id = tado_home["id"] self.home_name = tado_home["name"] def get_mobile_devices(self): """Return the Tado mobile devices.""" - return self.tado.getMobileDevices() + return self.tado.get_mobile_devices() @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): @@ -205,16 +208,19 @@ def update_mobile_devices(self) -> None: for mobile_device in mobile_devices: self.data["mobile_device"][mobile_device["id"]] = mobile_device + _LOGGER.debug( + "Dispatching update to %s mobile device: %s", + self.home_id, + mobile_device, + ) + dispatcher_send( + self.hass, + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format( + self.home_id, mobile_device["id"] + ), + ) - _LOGGER.debug( - "Dispatching update to %s mobile devices: %s", - self.home_id, - mobile_devices, - ) - dispatcher_send( - self.hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, - ) + dispatcher_send(self.hass, SIGNAL_TADO_MOBILE_DEVICES_UPDATE) def update_devices(self): """Update the device data from Tado.""" diff --git a/homeassistant/components/tado/const.py b/homeassistant/components/tado/const.py index c14906c3a8966..7ad2db5e2447f 100644 --- a/homeassistant/components/tado/const.py +++ b/homeassistant/components/tado/const.py @@ -179,7 +179,8 @@ DOMAIN = "tado" SIGNAL_TADO_UPDATE_RECEIVED = "tado_update_received_{}_{}_{}" -SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received" +SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received_{}_{}" +SIGNAL_TADO_MOBILE_DEVICES_UPDATE = "tao_mobile_devices_update" UNIQUE_ID = "unique_id" DEFAULT_NAME = "Tado" diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index 9c50318639dab..7e7123007558a 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -22,7 +22,13 @@ from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType -from .const import CONF_HOME_ID, DATA, DOMAIN, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED +from .const import ( + CONF_HOME_ID, + DATA, + DOMAIN, + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, + SIGNAL_TADO_MOBILE_DEVICES_UPDATE, +) _LOGGER = logging.getLogger(__name__) @@ -90,7 +96,7 @@ def update_devices() -> None: entry.async_on_unload( async_dispatcher_connect( hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, + SIGNAL_TADO_MOBILE_DEVICES_UPDATE, update_devices, ) ) @@ -104,17 +110,17 @@ def add_tracked_entities( tracked: set[str], ) -> None: """Add new tracker entities from Tado.""" - _LOGGER.debug("Fetching Tado devices from API") + _LOGGER.debug("Fetching Tado devices from API for (newly) tracked entities") new_tracked = [] - for device_key, device in tado.data["mobile_device"].items(): - if device_key in tracked: + for device in tado.mobile_devices: + if device["id"] in tracked: continue _LOGGER.debug( - "Adding Tado device %s with deviceID %s", device["name"], device_key + "Adding Tado device %s with deviceID %s", device["name"], device["id"] ) - new_tracked.append(TadoDeviceTrackerEntity(device_key, device["name"], tado)) - tracked.add(device_key) + new_tracked.append(TadoDeviceTrackerEntity(device["id"], device["name"], tado)) + tracked.add(device["id"]) async_add_entities(new_tracked) @@ -148,7 +154,11 @@ def update_state(self) -> None: self._device_name, self._device_id, ) - device = self._tado.data["mobile_device"][self._device_id] + + for mobile_device in self._tado.mobile_devices: + if mobile_device["id"] == self._device_id: + device = mobile_device + break self._active = False if device.get("location") is not None and device["location"]["atHome"]: @@ -169,7 +179,9 @@ async def async_added_to_hass(self) -> None: self.async_on_remove( async_dispatcher_connect( self.hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format( + self._tado.home_id, self._device_id + ), self.on_demand_update, ) ) From 5faf7adeaa9be64707be035d3d5958be6d09a29f Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 08:17:17 +0000 Subject: [PATCH 02/15] Adding fixture for new setup --- .../tado/fixtures/mobile_devices.json | 26 +++++++++++++++++++ tests/components/tado/util.py | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 tests/components/tado/fixtures/mobile_devices.json diff --git a/tests/components/tado/fixtures/mobile_devices.json b/tests/components/tado/fixtures/mobile_devices.json new file mode 100644 index 0000000000000..80700a1e42670 --- /dev/null +++ b/tests/components/tado/fixtures/mobile_devices.json @@ -0,0 +1,26 @@ +[ + { + "name": "Home", + "id": 123456, + "settings": { + "geoTrackingEnabled": false, + "specialOffersEnabled": false, + "onDemandLogRetrievalEnabled": false, + "pushNotifications": { + "lowBatteryReminder": true, + "awayModeReminder": true, + "homeModeReminder": true, + "openWindowReminder": true, + "energySavingsReportReminder": true, + "incidentDetection": true, + "energyIqReminder": false + } + }, + "deviceMetadata": { + "platform": "Android", + "osVersion": "14", + "model": "Samsung", + "locale": "nl" + } + } +] diff --git a/tests/components/tado/util.py b/tests/components/tado/util.py index 21e0e255ed11f..dd7c108c9843e 100644 --- a/tests/components/tado/util.py +++ b/tests/components/tado/util.py @@ -17,6 +17,7 @@ async def async_init_integration( token_fixture = "tado/token.json" devices_fixture = "tado/devices.json" + mobile_devices_fixture = "tado/mobile_devices.json" me_fixture = "tado/me.json" weather_fixture = "tado/weather.json" home_state_fixture = "tado/home_state.json" @@ -70,6 +71,10 @@ async def async_init_integration( "https://my.tado.com/api/v2/homes/1/devices", text=load_fixture(devices_fixture), ) + m.get( + "https://my.tado.com/api/v2/homes/1/mobileDevices", + text=load_fixture(mobile_devices_fixture), + ) m.get( "https://my.tado.com/api/v2/devices/WR1/", text=load_fixture(device_wr1_fixture), From 22a502bd8c6ee0b9d681bb6be4bd6dfae698caac Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 08:41:23 +0000 Subject: [PATCH 03/15] Minor refactor work --- homeassistant/components/tado/__init__.py | 1 + .../components/tado/device_tracker.py | 22 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index b8e03a0a4a11f..3790522a02703 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -195,6 +195,7 @@ def get_mobile_devices(self): def update(self): """Update the registered zones.""" self.update_devices() + self.update_mobile_devices() self.update_zones() self.update_home() diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index 7e7123007558a..747782069b191 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -2,7 +2,6 @@ from __future__ import annotations import logging -from typing import Any import voluptuous as vol @@ -22,6 +21,7 @@ from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType +from . import TadoConnector from .const import ( CONF_HOME_ID, DATA, @@ -105,22 +105,22 @@ def update_devices() -> None: @callback def add_tracked_entities( hass: HomeAssistant, - tado: Any, + tado: TadoConnector, async_add_entities: AddEntitiesCallback, tracked: set[str], ) -> None: """Add new tracker entities from Tado.""" _LOGGER.debug("Fetching Tado devices from API for (newly) tracked entities") new_tracked = [] - for device in tado.mobile_devices: - if device["id"] in tracked: + for device_key, device in tado.data["mobile_device"].items(): + if device_key in tracked: continue _LOGGER.debug( - "Adding Tado device %s with deviceID %s", device["name"], device["id"] + "Adding Tado device %s with deviceID %s", device["name"], device_key ) - new_tracked.append(TadoDeviceTrackerEntity(device["id"], device["name"], tado)) - tracked.add(device["id"]) + new_tracked.append(TadoDeviceTrackerEntity(device_key, device["name"], tado)) + tracked.add(device_key) async_add_entities(new_tracked) @@ -134,7 +134,7 @@ def __init__( self, device_id: str, device_name: str, - tado: Any, + tado: TadoConnector, ) -> None: """Initialize a Tado Device Tracker entity.""" super().__init__() @@ -154,11 +154,7 @@ def update_state(self) -> None: self._device_name, self._device_id, ) - - for mobile_device in self._tado.mobile_devices: - if mobile_device["id"] == self._device_id: - device = mobile_device - break + device = self._tado.data["mobile_device"][self._device_id] self._active = False if device.get("location") is not None and device["location"]["atHome"]: From c5109c76b5b82b7e8059f19611c0e9d34cb8edca Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 11:06:16 +0000 Subject: [PATCH 04/15] Add check for unlinked to different homes --- homeassistant/components/tado/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 3790522a02703..a90c4c27d493b 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -207,6 +207,12 @@ def update_mobile_devices(self) -> None: _LOGGER.error("Unable to connect to Tado while updating mobile devices") return + if len(mobile_devices) == 0: + _LOGGER.warning( + "No linked mobile devices found for home ID %s", self.home_id + ) + return + for mobile_device in mobile_devices: self.data["mobile_device"][mobile_device["id"]] = mobile_device _LOGGER.debug( @@ -231,6 +237,10 @@ def update_devices(self): _LOGGER.error("Unable to connect to Tado while updating devices") return + if len(devices) == 0: + _LOGGER.warning("No linked devices found for home ID %s", self.home_id) + return + for device in devices: device_short_serial_no = device["shortSerialNo"] _LOGGER.debug("Updating device %s", device_short_serial_no) From 9efc0a00024e64d387e77d6bff31dfabe76ac9ad Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 11:52:40 +0000 Subject: [PATCH 05/15] If the interface returns an error --- homeassistant/components/tado/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index a90c4c27d493b..7d28bd8ca66b0 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -213,6 +213,14 @@ def update_mobile_devices(self) -> None: ) return + if mobile_devices.get("errors"): + _LOGGER.error( + "Error for home ID %s while updating mobile devices: %s", + self.home_id, + mobile_devices["errors"], + ) + return + for mobile_device in mobile_devices: self.data["mobile_device"][mobile_device["id"]] = mobile_device _LOGGER.debug( @@ -241,6 +249,14 @@ def update_devices(self): _LOGGER.warning("No linked devices found for home ID %s", self.home_id) return + if devices.get("errors"): + _LOGGER.error( + "Error for home ID %s while updating devices: %s", + self.home_id, + devices["errors"], + ) + return + for device in devices: device_short_serial_no = device["shortSerialNo"] _LOGGER.debug("Updating device %s", device_short_serial_no) From 7ab2a6a332dfbd71e1de1695cfcd2ac25f166db9 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 11:57:23 +0000 Subject: [PATCH 06/15] Proper error handling --- homeassistant/components/tado/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 7d28bd8ca66b0..eae5b45a2e0fd 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -213,7 +213,7 @@ def update_mobile_devices(self) -> None: ) return - if mobile_devices.get("errors"): + if "errors" in mobile_devices and len(mobile_devices["errors"]) > 0: _LOGGER.error( "Error for home ID %s while updating mobile devices: %s", self.home_id, @@ -249,7 +249,7 @@ def update_devices(self): _LOGGER.warning("No linked devices found for home ID %s", self.home_id) return - if devices.get("errors"): + if "errors" in devices and len(devices["errors"]) > 0: _LOGGER.error( "Error for home ID %s while updating devices: %s", self.home_id, From 64f483fae1105c97569a831f7e659acea9b257bf Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 13:45:46 +0000 Subject: [PATCH 07/15] Feedback fixes --- homeassistant/components/tado/__init__.py | 12 +++--------- homeassistant/components/tado/const.py | 2 +- homeassistant/components/tado/device_tracker.py | 4 +--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index eae5b45a2e0fd..86847913a4dff 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -162,7 +162,6 @@ def __init__(self, hass, username, password, fallback): self.tado = None self.zones = None self.devices = None - self.mobile_devices = None self.data = { "device": {}, "mobile_device": {}, @@ -182,7 +181,6 @@ def setup(self): # Load zones and devices self.zones = self.tado.get_zones() self.devices = self.tado.get_devices() - self.mobile_devices = self.tado.get_mobile_devices() tado_home = self.tado.get_me()["homes"][0] self.home_id = tado_home["id"] self.home_name = tado_home["name"] @@ -208,9 +206,7 @@ def update_mobile_devices(self) -> None: return if len(mobile_devices) == 0: - _LOGGER.warning( - "No linked mobile devices found for home ID %s", self.home_id - ) + _LOGGER.debug("No linked mobile devices found for home ID %s", self.home_id) return if "errors" in mobile_devices and len(mobile_devices["errors"]) > 0: @@ -230,9 +226,7 @@ def update_mobile_devices(self) -> None: ) dispatcher_send( self.hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format( - self.home_id, mobile_device["id"] - ), + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.home_id), ) dispatcher_send(self.hass, SIGNAL_TADO_MOBILE_DEVICES_UPDATE) @@ -246,7 +240,7 @@ def update_devices(self): return if len(devices) == 0: - _LOGGER.warning("No linked devices found for home ID %s", self.home_id) + _LOGGER.debug("No linked devices found for home ID %s", self.home_id) return if "errors" in devices and len(devices["errors"]) > 0: diff --git a/homeassistant/components/tado/const.py b/homeassistant/components/tado/const.py index 7ad2db5e2447f..6456122d8453a 100644 --- a/homeassistant/components/tado/const.py +++ b/homeassistant/components/tado/const.py @@ -179,7 +179,7 @@ DOMAIN = "tado" SIGNAL_TADO_UPDATE_RECEIVED = "tado_update_received_{}_{}_{}" -SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received_{}_{}" +SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received_{}" SIGNAL_TADO_MOBILE_DEVICES_UPDATE = "tao_mobile_devices_update" UNIQUE_ID = "unique_id" diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index 747782069b191..a4376acec7f00 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -175,9 +175,7 @@ async def async_added_to_hass(self) -> None: self.async_on_remove( async_dispatcher_connect( self.hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format( - self._tado.home_id, self._device_id - ), + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self._tado.home_id), self.on_demand_update, ) ) From 83cda3d74e4ff23ad65a839fc45a5699ad3a5a3e Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 13:49:21 +0000 Subject: [PATCH 08/15] Comments for error in client --- homeassistant/components/tado/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 86847913a4dff..0cf660c8aacbd 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -209,6 +209,7 @@ def update_mobile_devices(self) -> None: _LOGGER.debug("No linked mobile devices found for home ID %s", self.home_id) return + # Make request at PyTado the library should fix it, so this can be removed if "errors" in mobile_devices and len(mobile_devices["errors"]) > 0: _LOGGER.error( "Error for home ID %s while updating mobile devices: %s", @@ -243,6 +244,7 @@ def update_devices(self): _LOGGER.debug("No linked devices found for home ID %s", self.home_id) return + # Make request at PyTado the library should fix it, so this can be removed if "errors" in devices and len(devices["errors"]) > 0: _LOGGER.error( "Error for home ID %s while updating devices: %s", From 38014591a36028e6f9469dd1afdce714e0dfba27 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 13:55:55 +0000 Subject: [PATCH 09/15] Typo --- homeassistant/components/tado/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/tado/const.py b/homeassistant/components/tado/const.py index 6456122d8453a..b4269c6669647 100644 --- a/homeassistant/components/tado/const.py +++ b/homeassistant/components/tado/const.py @@ -180,7 +180,7 @@ SIGNAL_TADO_UPDATE_RECEIVED = "tado_update_received_{}_{}_{}" SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received_{}" -SIGNAL_TADO_MOBILE_DEVICES_UPDATE = "tao_mobile_devices_update" +SIGNAL_TADO_MOBILE_DEVICES_UPDATE = "tado_mobile_devices_update" UNIQUE_ID = "unique_id" DEFAULT_NAME = "Tado" From 9360cfc6b176b61842a47f830bf389c511f6b983 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 15:03:04 +0100 Subject: [PATCH 10/15] Update homeassistant/components/tado/__init__.py Co-authored-by: Martin Hjelmare --- homeassistant/components/tado/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 0cf660c8aacbd..a710f178885d6 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -210,7 +210,7 @@ def update_mobile_devices(self) -> None: return # Make request at PyTado the library should fix it, so this can be removed - if "errors" in mobile_devices and len(mobile_devices["errors"]) > 0: + if "errors" in mobile_devices and mobile_devices["errors"]: _LOGGER.error( "Error for home ID %s while updating mobile devices: %s", self.home_id, From ffc6724c5bdce59d3b6b4b1bf7d6900689a24609 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 15:03:10 +0100 Subject: [PATCH 11/15] Update homeassistant/components/tado/__init__.py Co-authored-by: Martin Hjelmare --- homeassistant/components/tado/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index a710f178885d6..f2930e5613992 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -209,7 +209,8 @@ def update_mobile_devices(self) -> None: _LOGGER.debug("No linked mobile devices found for home ID %s", self.home_id) return - # Make request at PyTado the library should fix it, so this can be removed + # Errors are planned to be converted to exceptions + # in PyTado library, so this can be removed if "errors" in mobile_devices and mobile_devices["errors"]: _LOGGER.error( "Error for home ID %s while updating mobile devices: %s", From c52ca7852315b7b172b3cd8bdd767039d14c95b1 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 14:04:33 +0000 Subject: [PATCH 12/15] Update devices fix standard --- homeassistant/components/tado/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index f2930e5613992..1adcc88200c78 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -245,8 +245,9 @@ def update_devices(self): _LOGGER.debug("No linked devices found for home ID %s", self.home_id) return - # Make request at PyTado the library should fix it, so this can be removed - if "errors" in devices and len(devices["errors"]) > 0: + # Errors are planned to be converted to exceptions + # in PyTado library, so this can be removed + if "errors" in devices and devices["errors"]: _LOGGER.error( "Error for home ID %s while updating devices: %s", self.home_id, From 1e1c898703e9d997d49522ce591c8be18435878b Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 14:05:36 +0000 Subject: [PATCH 13/15] Dispatch out of loop --- homeassistant/components/tado/__init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 1adcc88200c78..53b4dc9cdd1f3 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -226,10 +226,11 @@ def update_mobile_devices(self) -> None: self.home_id, mobile_device, ) - dispatcher_send( - self.hass, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.home_id), - ) + + dispatcher_send( + self.hass, + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.home_id), + ) dispatcher_send(self.hass, SIGNAL_TADO_MOBILE_DEVICES_UPDATE) From c177dee064a4e03ad0c33debd7614983d26bf2f2 Mon Sep 17 00:00:00 2001 From: Erwin Douna Date: Tue, 9 Jan 2024 15:14:47 +0000 Subject: [PATCH 14/15] Update dispatcher --- homeassistant/components/tado/__init__.py | 3 --- homeassistant/components/tado/const.py | 1 - homeassistant/components/tado/device_tracker.py | 10 ++-------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 53b4dc9cdd1f3..215e57157ac68 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -27,7 +27,6 @@ INSIDE_TEMPERATURE_MEASUREMENT, PRESET_AUTO, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, - SIGNAL_TADO_MOBILE_DEVICES_UPDATE, SIGNAL_TADO_UPDATE_RECEIVED, TEMP_OFFSET, UPDATE_LISTENER, @@ -232,8 +231,6 @@ def update_mobile_devices(self) -> None: SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.home_id), ) - dispatcher_send(self.hass, SIGNAL_TADO_MOBILE_DEVICES_UPDATE) - def update_devices(self): """Update the device data from Tado.""" try: diff --git a/homeassistant/components/tado/const.py b/homeassistant/components/tado/const.py index b4269c6669647..ee24af29b9dce 100644 --- a/homeassistant/components/tado/const.py +++ b/homeassistant/components/tado/const.py @@ -180,7 +180,6 @@ SIGNAL_TADO_UPDATE_RECEIVED = "tado_update_received_{}_{}_{}" SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED = "tado_mobile_device_update_received_{}" -SIGNAL_TADO_MOBILE_DEVICES_UPDATE = "tado_mobile_devices_update" UNIQUE_ID = "unique_id" DEFAULT_NAME = "Tado" diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index a4376acec7f00..3ec75dee4bfba 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -22,13 +22,7 @@ from homeassistant.helpers.typing import ConfigType from . import TadoConnector -from .const import ( - CONF_HOME_ID, - DATA, - DOMAIN, - SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED, - SIGNAL_TADO_MOBILE_DEVICES_UPDATE, -) +from .const import CONF_HOME_ID, DATA, DOMAIN, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED _LOGGER = logging.getLogger(__name__) @@ -96,7 +90,7 @@ def update_devices() -> None: entry.async_on_unload( async_dispatcher_connect( hass, - SIGNAL_TADO_MOBILE_DEVICES_UPDATE, + SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(tado.home_id), update_devices, ) ) From ec1a4f206e7da2c1562020bec1078a1f5c1ad6c5 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Tue, 9 Jan 2024 16:24:43 +0100 Subject: [PATCH 15/15] Clean up --- homeassistant/components/tado/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 215e57157ac68..871d6c2e6b19b 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -204,7 +204,7 @@ def update_mobile_devices(self) -> None: _LOGGER.error("Unable to connect to Tado while updating mobile devices") return - if len(mobile_devices) == 0: + if not mobile_devices: _LOGGER.debug("No linked mobile devices found for home ID %s", self.home_id) return @@ -239,7 +239,7 @@ def update_devices(self): _LOGGER.error("Unable to connect to Tado while updating devices") return - if len(devices) == 0: + if not devices: _LOGGER.debug("No linked devices found for home ID %s", self.home_id) return