From 45c463b61c2c00e595ed5a8bee01eace59c3e56c Mon Sep 17 00:00:00 2001 From: Tobias Sauerwein Date: Tue, 7 Dec 2021 13:56:31 +0100 Subject: [PATCH] Fix Netatmo climate issue (#61154) Signed-off-by: cgtobi --- homeassistant/components/netatmo/climate.py | 11 +- .../components/netatmo/data_handler.py | 6 +- homeassistant/components/netatmo/select.py | 8 ++ .../netatmo/fixtures/homesdata.json | 102 ++++++++++++++++-- .../homestatus_111111111111111111111401.json | 4 + 5 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 tests/components/netatmo/fixtures/homestatus_111111111111111111111401.json diff --git a/homeassistant/components/netatmo/climate.py b/homeassistant/components/netatmo/climate.py index 49e02f566a0..1ead9d7cbdb 100644 --- a/homeassistant/components/netatmo/climate.py +++ b/homeassistant/components/netatmo/climate.py @@ -135,9 +135,14 @@ async def async_setup_entry( entities = [] for home_id in climate_topology.home_ids: signal_name = f"{CLIMATE_STATE_CLASS_NAME}-{home_id}" - await data_handler.register_data_class( - CLIMATE_STATE_CLASS_NAME, signal_name, None, home_id=home_id - ) + + try: + await data_handler.register_data_class( + CLIMATE_STATE_CLASS_NAME, signal_name, None, home_id=home_id + ) + except KeyError: + continue + climate_state = data_handler.data[signal_name] climate_topology.register_handler(home_id, climate_state.process_topology) diff --git a/homeassistant/components/netatmo/data_handler.py b/homeassistant/components/netatmo/data_handler.py index c62522a931a..7a97ec3748f 100644 --- a/homeassistant/components/netatmo/data_handler.py +++ b/homeassistant/components/netatmo/data_handler.py @@ -194,7 +194,11 @@ class NetatmoDataHandler: self._auth, **kwargs ) - await self.async_fetch_data(data_class_entry) + try: + await self.async_fetch_data(data_class_entry) + except KeyError: + self.data_classes.pop(data_class_entry) + raise self._queue.append(self.data_classes[data_class_entry]) _LOGGER.debug("Data class %s added", data_class_entry) diff --git a/homeassistant/components/netatmo/select.py b/homeassistant/components/netatmo/select.py index 9902155be73..98576497f3e 100644 --- a/homeassistant/components/netatmo/select.py +++ b/homeassistant/components/netatmo/select.py @@ -48,6 +48,14 @@ async def async_setup_entry( entities = [] for home_id in climate_topology.home_ids: signal_name = f"{CLIMATE_STATE_CLASS_NAME}-{home_id}" + + try: + await data_handler.register_data_class( + CLIMATE_STATE_CLASS_NAME, signal_name, None, home_id=home_id + ) + except KeyError: + continue + await data_handler.register_data_class( CLIMATE_STATE_CLASS_NAME, signal_name, None, home_id=home_id ) diff --git a/tests/components/netatmo/fixtures/homesdata.json b/tests/components/netatmo/fixtures/homesdata.json index fd63a0c200f..8c6587ca973 100644 --- a/tests/components/netatmo/fixtures/homesdata.json +++ b/tests/components/netatmo/fixtures/homesdata.json @@ -5,7 +5,10 @@ "id": "91763b24c43d3e344f424e8b", "name": "MYHOME", "altitude": 112, - "coordinates": [52.516263, 13.377726], + "coordinates": [ + 52.516263, + 13.377726 + ], "country": "DE", "timezone": "Europe/Berlin", "rooms": [ @@ -13,25 +16,33 @@ "id": "2746182631", "name": "Livingroom", "type": "livingroom", - "module_ids": ["12:34:56:00:01:ae"] + "module_ids": [ + "12:34:56:00:01:ae" + ] }, { "id": "3688132631", "name": "Hall", "type": "custom", - "module_ids": ["12:34:56:00:f1:62"] + "module_ids": [ + "12:34:56:00:f1:62" + ] }, { "id": "2833524037", "name": "Entrada", "type": "lobby", - "module_ids": ["12:34:56:03:a5:54"] + "module_ids": [ + "12:34:56:03:a5:54" + ] }, { "id": "2940411577", "name": "Cocina", "type": "kitchen", - "module_ids": ["12:34:56:03:a0:ac"] + "module_ids": [ + "12:34:56:03:a0:ac" + ] } ], "modules": [ @@ -388,6 +399,85 @@ } ], "therm_mode": "schedule" + }, + { + "id": "111111111111111111111401", + "name": "Home with no modules", + "altitude": 9, + "coordinates": [ + 1.23456789, + 50.0987654 + ], + "country": "BE", + "timezone": "Europe/Brussels", + "rooms": [ + { + "id": "1111111401", + "name": "Livingroom", + "type": "livingroom" + } + ], + "temperature_control_mode": "heating", + "therm_mode": "away", + "therm_setpoint_default_duration": 120, + "cooling_mode": "schedule", + "schedules": [ + { + "away_temp": 14, + "hg_temp": 7, + "name": "Week", + "timetable": [ + { + "zone_id": 1, + "m_offset": 0 + }, + { + "zone_id": 6, + "m_offset": 420 + } + ], + "zones": [ + { + "type": 0, + "name": "Comfort", + "rooms_temp": [], + "id": 0, + "rooms": [] + }, + { + "type": 1, + "name": "Nacht", + "rooms_temp": [], + "id": 1, + "rooms": [] + }, + { + "type": 5, + "name": "Eco", + "rooms_temp": [], + "id": 4, + "rooms": [] + }, + { + "type": 4, + "name": "Tussenin", + "rooms_temp": [], + "id": 5, + "rooms": [] + }, + { + "type": 4, + "name": "Ochtend", + "rooms_temp": [], + "id": 6, + "rooms": [] + } + ], + "id": "700000000000000000000401", + "selected": true, + "type": "therm" + } + ] } ], "user": { @@ -404,4 +494,4 @@ "status": "ok", "time_exec": 0.056135892868042, "time_server": 1559171003 -} +} \ No newline at end of file diff --git a/tests/components/netatmo/fixtures/homestatus_111111111111111111111401.json b/tests/components/netatmo/fixtures/homestatus_111111111111111111111401.json new file mode 100644 index 00000000000..2ae65dc0d21 --- /dev/null +++ b/tests/components/netatmo/fixtures/homestatus_111111111111111111111401.json @@ -0,0 +1,4 @@ +{ + "status": "ok", + "time_server": 1638873670 +} \ No newline at end of file