From 059f5bd9b413ca060300e09a6a1f0dffb4420f56 Mon Sep 17 00:00:00 2001 From: Erik Badman Date: Sat, 6 May 2023 17:47:14 +0000 Subject: [PATCH] Add try except in get_hostname_id function --- .../components/kostal_plenticore/helper.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/kostal_plenticore/helper.py b/homeassistant/components/kostal_plenticore/helper.py index 47ddf2d04d4..a1737510036 100644 --- a/homeassistant/components/kostal_plenticore/helper.py +++ b/homeassistant/components/kostal_plenticore/helper.py @@ -407,10 +407,14 @@ class PlenticoreDataFormatter: return PlenticoreDataFormatter.EM_STATES.get(value) -async def get_hostname_id(client: ApiClient) -> str: +async def get_hostname_id(client: ApiClient) -> str | None: """Check for known existing hostname ids.""" - all_settings = await client.get_settings() - for entry in all_settings["scb:network"]: - if entry.id in KNOWN_HOSTNAME_IDS: - return entry.id - raise ApiException("Hostname identifier not found in KNOWN_HOSTNAME_IDS") + try: + all_settings = await client.get_settings() + for entry in all_settings["scb:network"]: + if entry.id in KNOWN_HOSTNAME_IDS: + return entry.id + except (TypeError, ValueError): + return "Network:Hostname" + + return None