From 492b5421367e84fb12619093248dca89ca8577e3 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Sat, 28 Feb 2026 00:11:32 +0100 Subject: [PATCH 1/7] Fix Matter vacuum crash on nullable ServiceArea location info (#164411) --- homeassistant/components/matter/vacuum.py | 5 +- tests/components/matter/common.py | 1 + .../fixtures/nodes/roborock_saros_10.json | 540 ++++++++++++++++++ .../matter/snapshots/test_button.ambr | 50 ++ .../matter/snapshots/test_select.ambr | 72 +++ .../matter/snapshots/test_sensor.ambr | 277 +++++++++ .../matter/snapshots/test_vacuum.ambr | 50 ++ tests/components/matter/test_vacuum.py | 32 ++ 8 files changed, 1025 insertions(+), 2 deletions(-) create mode 100644 tests/components/matter/fixtures/nodes/roborock_saros_10.json diff --git a/homeassistant/components/matter/vacuum.py b/homeassistant/components/matter/vacuum.py index 2c478a5a8d2742..722e432e381881 100644 --- a/homeassistant/components/matter/vacuum.py +++ b/homeassistant/components/matter/vacuum.py @@ -168,8 +168,9 @@ def _current_segments(self) -> dict[str, Segment]: segments: dict[str, Segment] = {} for area in supported_areas: area_name = None - if area.areaInfo and area.areaInfo.locationInfo: - area_name = area.areaInfo.locationInfo.locationName + location_info = area.areaInfo.locationInfo + if location_info not in (None, clusters.NullValue): + area_name = location_info.locationName if area_name: segment_id = str(area.areaID) diff --git a/tests/components/matter/common.py b/tests/components/matter/common.py index d2fa07baa7f40f..23a5ec5755303d 100644 --- a/tests/components/matter/common.py +++ b/tests/components/matter/common.py @@ -92,6 +92,7 @@ "mock_window_covering_tilt", "onoff_light_with_levelcontrol_present", "resideo_x2s_thermostat", + "roborock_saros_10", "secuyou_smart_lock", "silabs_dishwasher", "silabs_evse_charging", diff --git a/tests/components/matter/fixtures/nodes/roborock_saros_10.json b/tests/components/matter/fixtures/nodes/roborock_saros_10.json new file mode 100644 index 00000000000000..208218972b63db --- /dev/null +++ b/tests/components/matter/fixtures/nodes/roborock_saros_10.json @@ -0,0 +1,540 @@ +{ + "node_id": 202, + "date_commissioned": "2025-01-01T00:00:00", + "last_interview": "2026-01-01T00:00:00", + "interview_version": 6, + "available": true, + "is_bridge": false, + "attributes": { + "0/29/0": [ + { + "0": 22, + "1": 1 + } + ], + "0/29/1": [29, 31, 40, 48, 49, 50, 51, 60, 62, 63], + "0/29/2": [], + "0/29/3": [1], + "0/29/65533": 2, + "0/29/65532": 0, + "0/29/65531": [0, 1, 2, 3, 65528, 65529, 65531, 65532, 65533], + "0/29/65529": [], + "0/29/65528": [], + "0/31/0": [ + { + "1": 5, + "2": 2, + "3": [112233], + "4": null, + "254": 2 + } + ], + "0/31/2": 4, + "0/31/3": 3, + "0/31/4": 4, + "0/31/65533": 2, + "0/31/65532": 0, + "0/31/65531": [0, 2, 3, 4, 65528, 65529, 65531, 65532, 65533], + "0/31/65529": [], + "0/31/65528": [], + "0/40/0": 18, + "0/40/1": "Roborock", + "0/40/2": 5248, + "0/40/3": "Robotic Vacuum Cleaner", + "0/40/4": 5, + "0/40/5": "", + "0/40/6": "**REDACTED**", + "0/40/7": 2, + "0/40/8": "1.4", + "0/40/9": 2, + "0/40/10": "1.4", + "0/40/13": "https://www.roborock.com", + "0/40/14": "Robotic Vacuum Cleaner", + "0/40/15": "RAPEED12345678", + "0/40/18": "12AB12AB12AB12AB", + "0/40/19": { + "0": 3, + "1": 65535 + }, + "0/40/21": 17039360, + "0/40/22": 1, + "0/40/24": 1, + "0/40/65533": 4, + "0/40/65532": 0, + "0/40/65531": [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 18, 19, 21, 22, 65528, + 65529, 65531, 65532, 65533 + ], + "0/40/65529": [], + "0/40/65528": [], + "0/48/0": 0, + "0/48/1": { + "0": 60, + "1": 900 + }, + "0/48/2": 0, + "0/48/3": 2, + "0/48/4": true, + "0/48/65533": 2, + "0/48/65532": 0, + "0/48/65531": [0, 1, 2, 3, 4, 65528, 65529, 65531, 65532, 65533], + "0/48/65529": [0, 2, 4], + "0/48/65528": [1, 3, 5], + "0/49/0": 1, + "0/49/1": [], + "0/49/4": true, + "0/49/5": 0, + "0/49/6": null, + "0/49/7": null, + "0/49/2": 30, + "0/49/3": 60, + "0/49/8": [0], + "0/49/65533": 2, + "0/49/65532": 1, + "0/49/65531": [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 65528, 65529, 65531, 65532, 65533 + ], + "0/49/65529": [0, 2, 4, 6, 8], + "0/49/65528": [1, 5, 7], + "0/50/65533": 1, + "0/50/65532": 0, + "0/50/65531": [65528, 65529, 65531, 65532, 65533], + "0/50/65529": [0], + "0/50/65528": [1], + "0/51/0": [ + { + "0": "ap0", + "1": false, + "2": null, + "3": null, + "4": "sko58laD", + "5": [], + "6": [], + "7": 0 + }, + { + "0": "wlan0", + "1": true, + "2": null, + "3": null, + "4": "sEo58laD", + "5": ["wKhQuQ=="], + "6": [ + "/XqKrJXsABCySjn//vJWgw==", + "KgIBaTwJABCySjn//vJWgw==", + "/oAAAAAAAACySjn//vJWgw==" + ], + "7": 0 + }, + { + "0": "sit0", + "1": false, + "2": null, + "3": null, + "4": "AAAAAAAA", + "5": [], + "6": [], + "7": 0 + }, + { + "0": "lo", + "1": true, + "2": null, + "3": null, + "4": "AAAAAAAA", + "5": ["fwAAAQ=="], + "6": ["AAAAAAAAAAAAAAAAAAAAAQ=="], + "7": 0 + } + ], + "0/51/1": 296, + "0/51/2": 8, + "0/51/3": 6328, + "0/51/8": false, + "0/51/65533": 2, + "0/51/65532": 0, + "0/51/65531": [0, 1, 2, 3, 8, 65528, 65529, 65531, 65532, 65533], + "0/51/65529": [0, 1], + "0/51/65528": [2], + "0/60/0": 0, + "0/60/1": null, + "0/60/2": null, + "0/60/65533": 1, + "0/60/65532": 0, + "0/60/65531": [0, 1, 2, 65528, 65529, 65531, 65532, 65533], + "0/60/65529": [0, 2], + "0/60/65528": [], + "0/62/0": [ + { + "1": "FTABAQEkAgE3AyQTAhgmBIAigScmBYAlTTo3BiQVAiQRyhgkBwEkCAEwCUEEFn0vNfCOD0dTxJ+/vIAsLHsPottGgAzLEYjD0IZda+wcLI6otwL3l70MZK44UQact9g+kLna4RHtR2DtJjzi3DcKNQEoARgkAgE2AwQCBAEYMAQUfe7BMayXJA5FAhU93iHoPeGaicwwBRS9bdraaL8JLSNzrDNJcbicl5ghHRgwC0DAfR8r1sKukiqQw8dPHxQBsDVYjQ2jyerfvkYRSMQGIr9Pr594PCSUazATbDgxf9kvIT7cpAnWVjA1YaYLXSlVGA==", + "2": "FTABAQEkAgE3AyQUARgmBIAigScmBYAlTTo3BiQTAhgkBwEkCAEwCUEEYKwzNQoI9xg/J/BXjm//XmufngPSiphrXcf/ZbJxf7K3k8Xo7I77pwece9Uj8QnKrMMUdloy0sNyxbIPkTGpyjcKNQEpARgkAmAwBBS9bdraaL8JLSNzrDNJcbicl5ghHTAFFBfVqc98NGU0Xt+pmyNVXJvnhDlkGDALQKoRuyZfkC/AbH9qIIxjOhkfJB2ZS8sovhbN1fo+cvSfZXdBw255Ytf9nag0yY2maE5thqhIE4MgGV9jwQ2EPysY", + "254": 2 + } + ], + "0/62/1": [ + { + "1": "BFhpm8fVgw4hzcuwFGwSe59XhvdUHtMntaUUbgCX0jqoaA1fjjcRYrZCA0PDImdLtZSkrUdug3S/euAVf4gvaKo=", + "2": 4939, + "3": 2, + "4": 202, + "5": "Home Assistant", + "254": 2 + } + ], + "0/62/2": 5, + "0/62/3": 2, + "0/62/4": [ + "FTABAQEkAgE3AyQUARgmBIAigScmBYAlTTo3BiQUARgkBwEkCAEwCUEEZGswP7Cx5r/rggyFyL5F/W2s7jQv9jdnF/BtORJ5CJLHyNrJouomrpNPkewkATT25URTzakxfZ/BC2RRof3LQjcKNQEpARgkAmAwBBSwDB1/C2jgnr2LPAd9KH/07G7HSjAFFLAMHX8LaOCevYs8B30of/TsbsdKGDALQGEJod+l+O0QOa/rnbYaghE4QgquJyT9pviD3sP2+MbUXJj1br+dZLQ7CfeCKfbM8EO9iPAe1ULLveIFfHakCpAY", + "FTABAQEkAgE3AyQUARgmBIAigScmBYAlTTo3BiQUARgkBwEkCAEwCUEEDheXhz87ejqXrjJrfcRfXbv1Co84yVLcfxYr3Q4VM5Fx0JCbQDNTmqeZ/BC67MDnaqXhrPHz6tPXjC7kar6RLDcKNQEpARgkAmAwBBQX1anPfDRlNF7fqZsjVVyb54Q5ZDAFFBfVqc98NGU0Xt+pmyNVXJvnhDlkGDALQFQj3btpuzZU/TNTTTh2Q/bUE8TTOP7U4kV4J8VNyl/phUUHSfnTAnaTR/YcUehZcgPJqnW6433HWTjsa8lopVMY" + ], + "0/62/5": 2, + "0/62/65533": 1, + "0/62/65532": 0, + "0/62/65531": [0, 1, 2, 3, 4, 5, 65528, 65529, 65531, 65532, 65533], + "0/62/65529": [0, 2, 4, 6, 7, 9, 10, 11], + "0/62/65528": [1, 3, 5, 8], + "0/63/0": [], + "0/63/1": [], + "0/63/2": 4, + "0/63/3": 3, + "0/63/65533": 2, + "0/63/65532": 0, + "0/63/65531": [0, 1, 2, 3, 65528, 65529, 65531, 65532, 65533], + "0/63/65529": [0, 1, 3, 4], + "0/63/65528": [2, 5], + "1/29/0": [ + { + "0": 17, + "1": 1 + }, + { + "0": 116, + "1": 1 + } + ], + "1/29/1": [3, 29, 47, 84, 85, 97, 336], + "1/29/2": [], + "1/29/3": [], + "1/29/65533": 2, + "1/29/65532": 0, + "1/29/65531": [0, 1, 2, 3, 65528, 65529, 65531, 65532, 65533], + "1/29/65529": [], + "1/29/65528": [], + "1/3/0": 0, + "1/3/1": 3, + "1/3/65533": 5, + "1/3/65532": 0, + "1/3/65531": [0, 1, 65528, 65529, 65531, 65532, 65533], + "1/3/65529": [0], + "1/3/65528": [], + "1/336/0": [ + { + "0": 1, + "1": 0, + "2": { + "0": { + "0": "Living room", + "1": null, + "2": 52 + }, + "1": null + } + }, + { + "0": 2, + "1": 0, + "2": { + "0": { + "0": "Bathroom", + "1": null, + "2": 6 + }, + "1": null + } + }, + { + "0": 3, + "1": 0, + "2": { + "0": { + "0": "Bedroom", + "1": null, + "2": 7 + }, + "1": null + } + }, + { + "0": 4, + "1": 0, + "2": { + "0": { + "0": "Office", + "1": null, + "2": 88 + }, + "1": null + } + }, + { + "0": 5, + "1": 0, + "2": { + "0": { + "0": "Corridor", + "1": null, + "2": 16 + }, + "1": null + } + }, + { + "0": 6, + "1": 0, + "2": { + "0": null, + "1": { + "0": 17, + "1": 2 + } + } + }, + { + "0": 7, + "1": 0, + "2": { + "0": null, + "1": { + "0": 43, + "1": 2 + } + } + } + ], + "1/336/2": [], + "1/336/65533": 1, + "1/336/65532": 4, + "1/336/65531": [0, 1, 2, 65528, 65529, 65531, 65532, 65533], + "1/336/65529": [0], + "1/336/65528": [1], + "1/336/1": [ + { + "0": 0, + "1": "Map-0" + } + ], + "1/47/0": 1, + "1/47/1": 0, + "1/47/2": "Primary Battery", + "1/47/31": [], + "1/47/12": 200, + "1/47/14": 0, + "1/47/15": false, + "1/47/16": 3, + "1/47/17": true, + "1/47/26": 2, + "1/47/28": true, + "1/47/65533": 3, + "1/47/65532": 6, + "1/47/65531": [ + 0, 1, 2, 12, 14, 15, 16, 17, 26, 28, 31, 65528, 65529, 65531, 65532, 65533 + ], + "1/47/65529": [], + "1/47/65528": [], + "1/84/0": [ + { + "label": "Idle", + "mode": 0, + "modeTags": [ + { + "value": 16384 + } + ] + }, + { + "label": "Cleaning", + "mode": 1, + "modeTags": [ + { + "value": 16385 + } + ] + }, + { + "label": "Mapping", + "mode": 2, + "modeTags": [ + { + "value": 16386 + } + ] + } + ], + "1/84/1": 0, + "1/84/65533": 3, + "1/84/65532": 0, + "1/84/65531": [0, 1, 65528, 65529, 65531, 65532, 65533], + "1/84/65529": [0], + "1/84/65528": [1], + "1/85/0": [ + { + "label": "Quiet, Vacuum Only", + "mode": 1, + "modeTags": [ + { + "value": 2 + }, + { + "value": 16385 + } + ] + }, + { + "label": "Auto, Vacuum Only", + "mode": 2, + "modeTags": [ + { + "value": 0 + }, + { + "value": 16385 + } + ] + }, + { + "label": "Deep Clean, Vacuum Only", + "mode": 3, + "modeTags": [ + { + "value": 16384 + }, + { + "value": 16385 + } + ] + }, + { + "label": "Quiet, Mop Only", + "mode": 4, + "modeTags": [ + { + "value": 2 + }, + { + "value": 16386 + } + ] + }, + { + "label": "Auto, Mop Only", + "mode": 5, + "modeTags": [ + { + "value": 0 + }, + { + "value": 16386 + } + ] + }, + { + "label": "Deep Clean, Mop Only", + "mode": 6, + "modeTags": [ + { + "value": 16384 + }, + { + "value": 16386 + } + ] + }, + { + "label": "Quiet, Vacuum and Mop", + "mode": 7, + "modeTags": [ + { + "value": 2 + }, + { + "value": 16385 + }, + { + "value": 16386 + } + ] + }, + { + "label": "Auto, Vacuum and Mop", + "mode": 8, + "modeTags": [ + { + "value": 0 + }, + { + "value": 16385 + }, + { + "value": 16386 + } + ] + }, + { + "label": "Deep Clean, Vacuum and Mop", + "mode": 9, + "modeTags": [ + { + "value": 16384 + }, + { + "value": 16385 + }, + { + "value": 16386 + } + ] + } + ], + "1/85/1": 8, + "1/85/65533": 3, + "1/85/65532": 0, + "1/85/65531": [0, 1, 65528, 65529, 65531, 65532, 65533], + "1/85/65529": [0], + "1/85/65528": [1], + "1/97/0": null, + "1/97/1": null, + "1/97/3": [ + { + "0": 0 + }, + { + "0": 1 + }, + { + "0": 2 + }, + { + "0": 3 + }, + { + "0": 64 + }, + { + "0": 65 + }, + { + "0": 66 + } + ], + "1/97/4": 66, + "1/97/5": { + "0": 0 + }, + "1/97/65533": 2, + "1/97/65532": 0, + "1/97/65531": [0, 1, 3, 4, 5, 65528, 65529, 65531, 65532, 65533], + "1/97/65529": [0, 3, 128], + "1/97/65528": [4] + }, + "attribute_subscriptions": [] +} diff --git a/tests/components/matter/snapshots/test_button.ambr b/tests/components/matter/snapshots/test_button.ambr index d7a9675825385a..e1389b605a5b6a 100644 --- a/tests/components/matter/snapshots/test_button.ambr +++ b/tests/components/matter/snapshots/test_button.ambr @@ -3485,6 +3485,56 @@ 'state': 'unknown', }) # --- +# name: test_buttons[roborock_saros_10][button.robotic_vacuum_cleaner_identify-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'button', + 'entity_category': , + 'entity_id': 'button.robotic_vacuum_cleaner_identify', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Identify', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Identify', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-IdentifyButton-3-1', + 'unit_of_measurement': None, + }) +# --- +# name: test_buttons[roborock_saros_10][button.robotic_vacuum_cleaner_identify-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'identify', + 'friendly_name': 'Robotic Vacuum Cleaner Identify', + }), + 'context': , + 'entity_id': 'button.robotic_vacuum_cleaner_identify', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_buttons[secuyou_smart_lock][button.secuyou_smart_lock_identify-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/snapshots/test_select.ambr b/tests/components/matter/snapshots/test_select.ambr index a4d4e2cba192d9..c22f0bff5fafbd 100644 --- a/tests/components/matter/snapshots/test_select.ambr +++ b/tests/components/matter/snapshots/test_select.ambr @@ -3995,6 +3995,78 @@ 'state': 'previous', }) # --- +# name: test_selects[roborock_saros_10][select.robotic_vacuum_cleaner_clean_mode-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'Quiet, Vacuum Only', + 'Auto, Vacuum Only', + 'Deep Clean, Vacuum Only', + 'Quiet, Mop Only', + 'Auto, Mop Only', + 'Deep Clean, Mop Only', + 'Quiet, Vacuum and Mop', + 'Auto, Vacuum and Mop', + 'Deep Clean, Vacuum and Mop', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': None, + 'entity_id': 'select.robotic_vacuum_cleaner_clean_mode', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Clean mode', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Clean mode', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'clean_mode', + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-MatterRvcCleanMode-85-1', + 'unit_of_measurement': None, + }) +# --- +# name: test_selects[roborock_saros_10][select.robotic_vacuum_cleaner_clean_mode-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Robotic Vacuum Cleaner Clean mode', + 'options': list([ + 'Quiet, Vacuum Only', + 'Auto, Vacuum Only', + 'Deep Clean, Vacuum Only', + 'Quiet, Mop Only', + 'Auto, Mop Only', + 'Deep Clean, Mop Only', + 'Quiet, Vacuum and Mop', + 'Auto, Vacuum and Mop', + 'Deep Clean, Vacuum and Mop', + ]), + }), + 'context': , + 'entity_id': 'select.robotic_vacuum_cleaner_clean_mode', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'Auto, Vacuum and Mop', + }) +# --- # name: test_selects[secuyou_smart_lock][select.secuyou_smart_lock_operating_mode-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/snapshots/test_sensor.ambr b/tests/components/matter/snapshots/test_sensor.ambr index 4f04f4e0ab2e66..c9b2fb5b2c0723 100644 --- a/tests/components/matter/snapshots/test_sensor.ambr +++ b/tests/components/matter/snapshots/test_sensor.ambr @@ -11473,6 +11473,283 @@ 'state': '20.55', }) # --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_battery-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_battery', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': None, + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-PowerSource-47-12', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_battery-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'battery', + 'friendly_name': 'Robotic Vacuum Cleaner Battery', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_battery', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '100', + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_battery_charge_state-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'not_charging', + 'charging', + 'full_charge', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_battery_charge_state', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Battery charge state', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery charge state', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'battery_charge_state', + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-PowerSourceBatChargeState-47-26', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_battery_charge_state-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'Robotic Vacuum Cleaner Battery charge state', + 'options': list([ + 'not_charging', + 'charging', + 'full_charge', + ]), + }), + 'context': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_battery_charge_state', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'full_charge', + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_operational_error-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'no_error', + 'unable_to_start_or_resume', + 'unable_to_complete_operation', + 'command_invalid_in_state', + 'failed_to_find_charging_dock', + 'stuck', + 'dust_bin_missing', + 'dust_bin_full', + 'water_tank_empty', + 'water_tank_missing', + 'water_tank_lid_open', + 'mop_cleaning_pad_missing', + 'low_battery', + 'cannot_reach_target_area', + 'dirty_water_tank_full', + 'dirty_water_tank_missing', + 'wheels_jammed', + 'brush_jammed', + 'navigation_sensor_obscured', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_operational_error', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Operational error', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Operational error', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'operational_error', + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-RvcOperationalStateOperationalError-97-5', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_operational_error-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'Robotic Vacuum Cleaner Operational error', + 'options': list([ + 'no_error', + 'unable_to_start_or_resume', + 'unable_to_complete_operation', + 'command_invalid_in_state', + 'failed_to_find_charging_dock', + 'stuck', + 'dust_bin_missing', + 'dust_bin_full', + 'water_tank_empty', + 'water_tank_missing', + 'water_tank_lid_open', + 'mop_cleaning_pad_missing', + 'low_battery', + 'cannot_reach_target_area', + 'dirty_water_tank_full', + 'dirty_water_tank_missing', + 'wheels_jammed', + 'brush_jammed', + 'navigation_sensor_obscured', + ]), + }), + 'context': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_operational_error', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'no_error', + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_operational_state-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'stopped', + 'running', + 'paused', + 'error', + 'seeking_charger', + 'charging', + 'docked', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.robotic_vacuum_cleaner_operational_state', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Operational state', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Operational state', + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'operational_state', + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-RvcOperationalState-97-4', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[roborock_saros_10][sensor.robotic_vacuum_cleaner_operational_state-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'Robotic Vacuum Cleaner Operational state', + 'options': list([ + 'stopped', + 'running', + 'paused', + 'error', + 'seeking_charger', + 'charging', + 'docked', + ]), + }), + 'context': , + 'entity_id': 'sensor.robotic_vacuum_cleaner_operational_state', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'docked', + }) +# --- # name: test_sensors[silabs_dishwasher][sensor.dishwasher_effective_current-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/snapshots/test_vacuum.ambr b/tests/components/matter/snapshots/test_vacuum.ambr index 73eb2d2388e99a..e1408b32c01735 100644 --- a/tests/components/matter/snapshots/test_vacuum.ambr +++ b/tests/components/matter/snapshots/test_vacuum.ambr @@ -149,6 +149,56 @@ 'state': 'idle', }) # --- +# name: test_vacuum[roborock_saros_10][vacuum.robotic_vacuum_cleaner-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'vacuum', + 'entity_category': None, + 'entity_id': 'vacuum.robotic_vacuum_cleaner', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'matter', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': , + 'translation_key': 'vacuum', + 'unique_id': '00000000000004D2-00000000000000CA-MatterNodeDevice-1-MatterVacuumCleaner-84-1', + 'unit_of_measurement': None, + }) +# --- +# name: test_vacuum[roborock_saros_10][vacuum.robotic_vacuum_cleaner-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Robotic Vacuum Cleaner', + 'supported_features': , + }), + 'context': , + 'entity_id': 'vacuum.robotic_vacuum_cleaner', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'docked', + }) +# --- # name: test_vacuum[switchbot_k11_plus][vacuum.k11-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/matter/test_vacuum.py b/tests/components/matter/test_vacuum.py index 4c866d6973bcf8..baefba7cc18052 100644 --- a/tests/components/matter/test_vacuum.py +++ b/tests/components/matter/test_vacuum.py @@ -338,6 +338,38 @@ async def test_vacuum_get_segments( assert segments[2] == {"id": "2290649224", "name": "My Location C", "group": None} +@pytest.mark.parametrize("node_fixture", ["roborock_saros_10"]) +async def test_vacuum_get_segments_nullable_location_info( + hass: HomeAssistant, + matter_node: MatterNode, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test vacuum get_segments handles nullable ServiceArea location info.""" + await async_setup_component(hass, "homeassistant", {}) + assert matter_node + + entity_ids = [state.entity_id for state in hass.states.async_all("vacuum")] + assert len(entity_ids) == 1 + entity_id = entity_ids[0] + state = hass.states.get(entity_id) + assert state + + client = await hass_ws_client(hass) + await client.send_json_auto_id( + {"type": "vacuum/get_segments", "entity_id": entity_id} + ) + + msg = await client.receive_json() + assert msg["success"] + assert msg["result"]["segments"] == [ + {"id": "1", "name": "Living room", "group": None}, + {"id": "2", "name": "Bathroom", "group": None}, + {"id": "3", "name": "Bedroom", "group": None}, + {"id": "4", "name": "Office", "group": None}, + {"id": "5", "name": "Corridor", "group": None}, + ] + + @pytest.mark.parametrize("node_fixture", ["mock_vacuum_cleaner"]) async def test_vacuum_clean_area( hass: HomeAssistant, From c7e78568d0a75ffa4127f0e0f5c2ed4252d29a1d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 28 Feb 2026 01:22:29 +0100 Subject: [PATCH 2/7] Enable real sockets in default_config setup test (#164366) --- tests/components/default_config/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/components/default_config/test_init.py b/tests/components/default_config/test_init.py index 8835e943076d92..6c7a705b0bdf8d 100644 --- a/tests/components/default_config/test_init.py +++ b/tests/components/default_config/test_init.py @@ -30,7 +30,7 @@ def recorder_url_mock(): yield -@pytest.mark.usefixtures("mock_bluetooth", "mock_zeroconf") +@pytest.mark.usefixtures("mock_bluetooth", "mock_zeroconf", "socket_enabled") async def test_setup(hass: HomeAssistant) -> None: """Test setup.""" recorder_helper.async_initialize_recorder(hass) From 3fae15c430f3c92da32a69e5ed219501bcb63ee1 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 28 Feb 2026 01:23:13 +0100 Subject: [PATCH 3/7] Fix fixture ordering in esphome dashboard tests (#164367) --- tests/components/esphome/test_dashboard.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/components/esphome/test_dashboard.py b/tests/components/esphome/test_dashboard.py index 36542b2bd09803..658475dfab2b86 100644 --- a/tests/components/esphome/test_dashboard.py +++ b/tests/components/esphome/test_dashboard.py @@ -19,9 +19,11 @@ from tests.common import MockConfigEntry -@pytest.mark.usefixtures("init_integration", "mock_dashboard") +@pytest.mark.usefixtures("mock_dashboard") async def test_dashboard_storage( hass: HomeAssistant, + mock_client: APIClient, + init_integration: MockConfigEntry, hass_storage: dict[str, Any], ) -> None: """Test dashboard storage.""" @@ -129,6 +131,7 @@ async def test_setup_dashboard_fails( async def test_setup_dashboard_fails_when_already_setup( hass: HomeAssistant, + mock_client: APIClient, mock_config_entry: MockConfigEntry, hass_storage: dict[str, Any], ) -> None: @@ -168,7 +171,9 @@ async def test_setup_dashboard_fails_when_already_setup( @pytest.mark.usefixtures("mock_dashboard") async def test_new_info_reload_config_entries( - hass: HomeAssistant, init_integration: MockConfigEntry + hass: HomeAssistant, + mock_client: APIClient, + init_integration: MockConfigEntry, ) -> None: """Test config entries are reloaded when new info is set.""" assert init_integration.state is ConfigEntryState.LOADED From 1be8b8e525f589ec2bb5bf179bc30628e0da032e Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 28 Feb 2026 01:23:47 +0100 Subject: [PATCH 4/7] Add discovery mocks to tplink init tests (#164386) --- tests/components/tplink/test_init.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/components/tplink/test_init.py b/tests/components/tplink/test_init.py index e5a973b67b4c37..d1a314943efb8a 100644 --- a/tests/components/tplink/test_init.py +++ b/tests/components/tplink/test_init.py @@ -545,7 +545,12 @@ async def test_unlink_devices( } assert device_entries[0].identifiers == set(test_identifiers) - with patch("homeassistant.components.tplink.CONF_CONFIG_ENTRY_MINOR_VERSION", 3): + with ( + patch("homeassistant.components.tplink.CONF_CONFIG_ENTRY_MINOR_VERSION", 3), + _patch_discovery(), + _patch_single_discovery(), + _patch_connect(), + ): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -596,6 +601,8 @@ async def _connect(config): patch("homeassistant.components.tplink.Device.connect", new=_connect), patch("homeassistant.components.tplink.PLATFORMS", []), patch("homeassistant.components.tplink.CONF_CONFIG_ENTRY_MINOR_VERSION", 4), + _patch_discovery(), + _patch_single_discovery(), ): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -640,6 +647,8 @@ async def test_move_credentials_hash_auth_error( ), patch("homeassistant.components.tplink.PLATFORMS", []), patch("homeassistant.components.tplink.CONF_CONFIG_ENTRY_MINOR_VERSION", 4), + _patch_discovery(), + _patch_single_discovery(), ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -682,6 +691,8 @@ async def test_move_credentials_hash_other_error( ), patch("homeassistant.components.tplink.PLATFORMS", []), patch("homeassistant.components.tplink.CONF_CONFIG_ENTRY_MINOR_VERSION", 4), + _patch_discovery(), + _patch_single_discovery(), ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -717,6 +728,8 @@ async def _connect(config): with ( patch("homeassistant.components.tplink.PLATFORMS", []), patch("homeassistant.components.tplink.Device.connect", new=_connect), + _patch_discovery(), + _patch_single_discovery(), ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -753,6 +766,8 @@ async def test_credentials_hash_auth_error( "homeassistant.components.tplink.Device.connect", side_effect=AuthenticationError, ) as connect_mock, + _patch_discovery(), + _patch_single_discovery(), ): entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -782,6 +797,7 @@ async def test_credentials_hash_auth_error( async def test_migrate_remove_device_config( hass: HomeAssistant, mock_connect: AsyncMock, + mock_discovery: AsyncMock, caplog: pytest.LogCaptureFixture, device_config: DeviceConfig, expected_entry_data: dict[str, Any], From 5b32e42b8cd87f61c9e61b23bdbfa3f29de38d10 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 28 Feb 2026 01:24:13 +0100 Subject: [PATCH 5/7] Add aioclient_mock to ssdp tests to prevent real HTTP requests (#164403) --- tests/components/ssdp/test_init.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/components/ssdp/test_init.py b/tests/components/ssdp/test_init.py index 2e213991a0318a..90f3c4ceea64b6 100644 --- a/tests/components/ssdp/test_init.py +++ b/tests/components/ssdp/test_init.py @@ -41,7 +41,11 @@ return_value={"mock-domain": [{"st": "mock-st"}]}, ) async def test_ssdp_flow_dispatched_on_st( - mock_get_ssdp, hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_flow_init + mock_get_ssdp, + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, + mock_flow_init, + aioclient_mock: AiohttpClientMocker, ) -> None: """Test matching based on ST.""" mock_ssdp_search_response = _ssdp_headers( @@ -84,7 +88,11 @@ async def test_ssdp_flow_dispatched_on_st( return_value={"mock-domain": [{"manufacturerURL": "mock-url"}]}, ) async def test_ssdp_flow_dispatched_on_manufacturer_url( - mock_get_ssdp, hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_flow_init + mock_get_ssdp, + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, + mock_flow_init, + aioclient_mock: AiohttpClientMocker, ) -> None: """Test matching based on manufacturerURL.""" mock_ssdp_search_response = _ssdp_headers( @@ -1038,6 +1046,7 @@ async def test_ssdp_rediscover( async def test_ssdp_rediscover_no_match( mock_get_ssdp, hass: HomeAssistant, + aioclient_mock: AiohttpClientMocker, mock_flow_init, entry_domain: str, entry_discovery_keys: dict[str, tuple[DiscoveryKey, ...]], From 7ef6c34149559e83e31f0dc896cfca8e204ba565 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 28 Feb 2026 01:25:04 +0100 Subject: [PATCH 6/7] Reject relative paths in SFTP storage backup location config flow (#164408) --- .../components/sftp_storage/config_flow.py | 11 +++++++ .../components/sftp_storage/strings.json | 1 + tests/components/sftp_storage/conftest.py | 6 ++-- tests/components/sftp_storage/test_backup.py | 2 +- .../sftp_storage/test_config_flow.py | 33 +++++++++++++++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sftp_storage/config_flow.py b/homeassistant/components/sftp_storage/config_flow.py index 3168810edab49c..cecd7d54b3579e 100644 --- a/homeassistant/components/sftp_storage/config_flow.py +++ b/homeassistant/components/sftp_storage/config_flow.py @@ -124,6 +124,17 @@ async def async_step_user( } ) + if not user_input[CONF_BACKUP_LOCATION].startswith("/"): + errors[CONF_BACKUP_LOCATION] = "backup_location_relative" + return self.async_show_form( + step_id=step_id, + data_schema=self.add_suggested_values_to_schema( + DATA_SCHEMA, user_input + ), + description_placeholders=placeholders, + errors=errors, + ) + try: # Validate auth input and save uploaded key file if provided user_input = await self._validate_auth_and_save_keyfile(user_input) diff --git a/homeassistant/components/sftp_storage/strings.json b/homeassistant/components/sftp_storage/strings.json index 9856286a0f10c6..dce60e9e3e5e8e 100644 --- a/homeassistant/components/sftp_storage/strings.json +++ b/homeassistant/components/sftp_storage/strings.json @@ -4,6 +4,7 @@ "already_configured": "Integration already configured. Host with same address, port and backup location already exists." }, "error": { + "backup_location_relative": "The remote path must be an absolute path (starting with `/`).", "invalid_key": "Invalid key uploaded. Please make sure key corresponds to valid SSH key algorithm.", "key_or_password_needed": "Please configure password or private key file location for SFTP Storage.", "os_error": "{error_message}. Please check if host and/or port are correct.", diff --git a/tests/components/sftp_storage/conftest.py b/tests/components/sftp_storage/conftest.py index 108039d994f69d..1f9a347873044b 100644 --- a/tests/components/sftp_storage/conftest.py +++ b/tests/components/sftp_storage/conftest.py @@ -31,7 +31,7 @@ type ComponentSetup = Callable[[], Awaitable[None]] BACKUP_METADATA = { - "file_path": "backup_location/backup.tar", + "file_path": "/backup_location/backup.tar", "metadata": { "addons": [{"name": "Test", "slug": "test", "version": "1.0.0"}], "backup_id": "test-backup", @@ -60,7 +60,7 @@ CONF_USERNAME: "username", CONF_PASSWORD: "password", CONF_PRIVATE_KEY_FILE: PRIVATE_KEY_FILE_UUID, - CONF_BACKUP_LOCATION: "backup_location", + CONF_BACKUP_LOCATION: "/backup_location", } TEST_AGENT_ID = ulid() @@ -118,7 +118,7 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry: CONF_USERNAME: "username", CONF_PASSWORD: "password", CONF_PRIVATE_KEY_FILE: str(private_key), - CONF_BACKUP_LOCATION: "backup_location", + CONF_BACKUP_LOCATION: "/backup_location", }, ) diff --git a/tests/components/sftp_storage/test_backup.py b/tests/components/sftp_storage/test_backup.py index 52cdcd49df15ba..9ae05f714c1fb5 100644 --- a/tests/components/sftp_storage/test_backup.py +++ b/tests/components/sftp_storage/test_backup.py @@ -151,7 +151,7 @@ async def test_agents_list_backups_include_bad_metadata( # Called two times, one for bad backup metadata and once for good assert mock_ssh_connection._sftp._mock_open._mock_read.call_count == 2 assert ( - "Failed to load backup metadata from file: backup_location/invalid.metadata.json. Expecting value: line 1 column 1 (char 0)" + "Failed to load backup metadata from file: /backup_location/invalid.metadata.json. Expecting value: line 1 column 1 (char 0)" in caplog.messages ) diff --git a/tests/components/sftp_storage/test_config_flow.py b/tests/components/sftp_storage/test_config_flow.py index 5f1d228a559871..23072527716840 100644 --- a/tests/components/sftp_storage/test_config_flow.py +++ b/tests/components/sftp_storage/test_config_flow.py @@ -15,6 +15,7 @@ SFTPStorageMissingPasswordOrPkey, ) from homeassistant.components.sftp_storage.const import ( + CONF_BACKUP_LOCATION, CONF_HOST, CONF_PASSWORD, CONF_PRIVATE_KEY_FILE, @@ -194,3 +195,35 @@ async def test_config_entry_error(hass: HomeAssistant) -> None: result["flow_id"], user_input ) assert "errors" in result and result["errors"]["base"] == "key_or_password_needed" + + +@pytest.mark.usefixtures("current_request_with_host") +@pytest.mark.usefixtures("mock_process_uploaded_file") +@pytest.mark.usefixtures("mock_ssh_connection") +async def test_relative_backup_location_rejected( + hass: HomeAssistant, +) -> None: + """Test that a relative backup location path is rejected.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_USER} + ) + assert result["step_id"] == "user" + + user_input = USER_INPUT.copy() + user_input[CONF_BACKUP_LOCATION] = "backups" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input + ) + + assert result["type"] is FlowResultType.FORM + assert result["errors"] == {CONF_BACKUP_LOCATION: "backup_location_relative"} + + # Fix the path and verify the flow succeeds + user_input[CONF_BACKUP_LOCATION] = "/backups" + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY From 642864959ad40859b07904b6035f2bcdef3ae8d7 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Sat, 28 Feb 2026 02:57:02 +0100 Subject: [PATCH 7/7] Update translatable exceptions for Powerfox integration (#164322) --- homeassistant/components/powerfox/__init__.py | 21 +++++++++++++--- .../components/powerfox/coordinator.py | 24 ++++++++++++------- .../components/powerfox/strings.json | 14 +++++++---- tests/components/powerfox/test_init.py | 11 ++++++--- tests/components/powerfox/test_sensor.py | 14 +++++++++-- 5 files changed, 63 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/powerfox/__init__.py b/homeassistant/components/powerfox/__init__.py index 06ede9dc2c2749..161b8c55e6544d 100644 --- a/homeassistant/components/powerfox/__init__.py +++ b/homeassistant/components/powerfox/__init__.py @@ -4,13 +4,19 @@ import asyncio -from powerfox import DeviceType, Powerfox, PowerfoxConnectionError +from powerfox import ( + DeviceType, + Powerfox, + PowerfoxAuthenticationError, + PowerfoxConnectionError, +) from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession +from .const import DOMAIN from .coordinator import ( PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator, @@ -30,9 +36,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: PowerfoxConfigEntry) -> try: devices = await client.all_devices() + except PowerfoxAuthenticationError as err: + await client.close() + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="auth_failed", + ) from err except PowerfoxConnectionError as err: await client.close() - raise ConfigEntryNotReady from err + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="connection_error", + ) from err coordinators: list[ PowerfoxDataUpdateCoordinator | PowerfoxReportDataUpdateCoordinator diff --git a/homeassistant/components/powerfox/coordinator.py b/homeassistant/components/powerfox/coordinator.py index 318f643b73a66f..ae0de87d3eefb8 100644 --- a/homeassistant/components/powerfox/coordinator.py +++ b/homeassistant/components/powerfox/coordinator.py @@ -59,18 +59,24 @@ async def _async_update_data(self) -> T: except PowerfoxAuthenticationError as err: raise ConfigEntryAuthFailed( translation_domain=DOMAIN, - translation_key="invalid_auth", - translation_placeholders={"error": str(err)}, + translation_key="auth_failed", ) from err - except ( - PowerfoxConnectionError, - PowerfoxNoDataError, - PowerfoxPrivacyError, - ) as err: + except PowerfoxConnectionError as err: raise UpdateFailed( translation_domain=DOMAIN, - translation_key="update_failed", - translation_placeholders={"error": str(err)}, + translation_key="connection_error", + ) from err + except PowerfoxNoDataError as err: + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="no_data_error", + translation_placeholders={"device_name": self.device.name}, + ) from err + except PowerfoxPrivacyError as err: + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="privacy_error", + translation_placeholders={"device_name": self.device.name}, ) from err async def _async_fetch_data(self) -> T: diff --git a/homeassistant/components/powerfox/strings.json b/homeassistant/components/powerfox/strings.json index be8169def68ccf..6b98677cf19260 100644 --- a/homeassistant/components/powerfox/strings.json +++ b/homeassistant/components/powerfox/strings.json @@ -116,11 +116,17 @@ } }, "exceptions": { - "invalid_auth": { - "message": "Error while authenticating with the Powerfox service: {error}" + "auth_failed": { + "message": "Authentication with the Powerfox service failed. Please re-authenticate your account." }, - "update_failed": { - "message": "Error while updating the Powerfox service: {error}" + "connection_error": { + "message": "Could not connect to the Powerfox service. Please check your network connection." + }, + "no_data_error": { + "message": "No data available for device \"{device_name}\". The device may not have reported data yet." + }, + "privacy_error": { + "message": "Data for device \"{device_name}\" is restricted due to privacy settings in the Powerfox app." } } } diff --git a/tests/components/powerfox/test_init.py b/tests/components/powerfox/test_init.py index 1ad60babc0438c..377140c338c334 100644 --- a/tests/components/powerfox/test_init.py +++ b/tests/components/powerfox/test_init.py @@ -5,6 +5,7 @@ from unittest.mock import AsyncMock from powerfox import PowerfoxAuthenticationError, PowerfoxConnectionError +import pytest from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant @@ -45,16 +46,20 @@ async def test_config_entry_not_ready( assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY -async def test_setup_entry_exception( +@pytest.mark.parametrize("method", ["all_devices", "device"]) +async def test_config_entry_auth_failed( hass: HomeAssistant, mock_powerfox_client: AsyncMock, mock_config_entry: MockConfigEntry, + method: str, ) -> None: - """Test ConfigEntryNotReady when API raises an exception during entry setup.""" + """Test ConfigEntryAuthFailed when authentication fails.""" + getattr(mock_powerfox_client, method).side_effect = PowerfoxAuthenticationError mock_config_entry.add_to_hass(hass) - mock_powerfox_client.device.side_effect = PowerfoxAuthenticationError await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR flows = hass.config_entries.flow.async_progress() diff --git a/tests/components/powerfox/test_sensor.py b/tests/components/powerfox/test_sensor.py index 459e8c61c1a21a..b2fb40a44b87af 100644 --- a/tests/components/powerfox/test_sensor.py +++ b/tests/components/powerfox/test_sensor.py @@ -6,7 +6,12 @@ from unittest.mock import AsyncMock, patch from freezegun.api import FrozenDateTimeFactory -from powerfox import DeviceReport, PowerfoxConnectionError +from powerfox import ( + DeviceReport, + PowerfoxConnectionError, + PowerfoxNoDataError, + PowerfoxPrivacyError, +) import pytest from syrupy.assertion import SnapshotAssertion @@ -35,11 +40,16 @@ async def test_all_sensors( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) +@pytest.mark.parametrize( + "exception", + [PowerfoxConnectionError, PowerfoxNoDataError, PowerfoxPrivacyError], +) async def test_update_failed( hass: HomeAssistant, mock_powerfox_client: AsyncMock, mock_config_entry: MockConfigEntry, freezer: FrozenDateTimeFactory, + exception: Exception, ) -> None: """Test entities become unavailable after failed update.""" await setup_integration(hass, mock_config_entry) @@ -47,7 +57,7 @@ async def test_update_failed( assert hass.states.get("sensor.poweropti_energy_usage").state is not None - mock_powerfox_client.device.side_effect = PowerfoxConnectionError + mock_powerfox_client.device.side_effect = exception freezer.tick(timedelta(minutes=5)) async_fire_time_changed(hass) await hass.async_block_till_done()