diff --git a/homeassistant/components/home_connect/__init__.py b/homeassistant/components/home_connect/__init__.py index 47a5aa99edbb66..2c351f4dfa1b94 100644 --- a/homeassistant/components/home_connect/__init__.py +++ b/homeassistant/components/home_connect/__init__.py @@ -329,10 +329,10 @@ def update_unique_id( def get_dict_from_home_connect_error(err: api.HomeConnectError) -> dict[str, Any]: """Return a dict from a Home Connect error.""" - return ( - err.args[0] + return { + "description": cast(dict[str, Any], err.args[0]).get("description", "?") if len(err.args) > 0 and isinstance(err.args[0], dict) - else {"description": err.args[0]} + else err.args[0] if len(err.args) > 0 and isinstance(err.args[0], str) - else {} - ) + else "?", + } diff --git a/homeassistant/components/home_connect/strings.json b/homeassistant/components/home_connect/strings.json index eb57d822b155a0..934aed5b7d5f56 100644 --- a/homeassistant/components/home_connect/strings.json +++ b/homeassistant/components/home_connect/strings.json @@ -38,13 +38,13 @@ "message": "Error while trying to set color of {entity_id}: {description}" }, "set_setting": { - "message": "Error while trying to assign the value \"{value}\" to the setting \"{key}\" for {entity_id}: {description}" + "message": "Error while trying to assign the value \"{value}\" to the setting \"{setting_key}\" for {entity_id}: {description}" }, "turn_on": { - "message": "Error while trying to turn on {entity_id} ({key}): {description}" + "message": "Error while trying to turn on {entity_id} ({setting_key}): {description}" }, "turn_off": { - "message": "Error while trying to turn off {entity_id} ({key}): {description}" + "message": "Error while trying to turn off {entity_id} ({setting_key}): {description}" }, "start_program": { "message": "Error while trying to start program {program}: {description}" diff --git a/tests/components/home_connect/test_switch.py b/tests/components/home_connect/test_switch.py index 06201ffd58c9a7..e4f45fbcdf9cba 100644 --- a/tests/components/home_connect/test_switch.py +++ b/tests/components/home_connect/test_switch.py @@ -162,7 +162,7 @@ async def test_switch_functionality( SERVICE_TURN_OFF, "set_setting", "Dishwasher", - r"Error.*turn.*off.*appliance.*value", + r"Error.*turn.*off.*", ), ( "switch.dishwasher_power", @@ -170,7 +170,7 @@ async def test_switch_functionality( SERVICE_TURN_ON, "set_setting", "Dishwasher", - r"Error.*turn.*on.*appliance.*", + r"Error.*turn.*on.*", ), ( "switch.dishwasher_child_lock", @@ -178,7 +178,7 @@ async def test_switch_functionality( SERVICE_TURN_ON, "set_setting", "Dishwasher", - r"Error.*turn.*on.*key.*", + r"Error.*turn.*on.*", ), ( "switch.dishwasher_child_lock", @@ -186,7 +186,7 @@ async def test_switch_functionality( SERVICE_TURN_OFF, "set_setting", "Dishwasher", - r"Error.*turn.*off.*key.*", + r"Error.*turn.*off.*", ), ], indirect=["problematic_appliance"], @@ -297,7 +297,7 @@ async def test_ent_desc_switch_functionality( SERVICE_TURN_ON, "set_setting", "FridgeFreezer", - r"Error.*turn.*on.*key.*", + r"Error.*turn.*on.*", ), ( "switch.fridgefreezer_freezer_super_mode", @@ -305,7 +305,7 @@ async def test_ent_desc_switch_functionality( SERVICE_TURN_OFF, "set_setting", "FridgeFreezer", - r"Error.*turn.*off.*key.*", + r"Error.*turn.*off.*", ), ], indirect=["problematic_appliance"],