From abfba1f4556493518dcd5548eefb806a97281ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCndler?= Date: Tue, 24 Aug 2021 17:56:36 +0200 Subject: [PATCH] Handle missing mac address in syncthru (#55154) * Fix access errors to mac address printer.raw() is the only attribute accessed and will always be present. However depending on the printer, the mac address might be missing. * Update homeassistant/components/syncthru/__init__.py Co-authored-by: J. Nick Koston * Update homeassistant/components/syncthru/__init__.py Co-authored-by: J. Nick Koston * Update homeassistant/components/syncthru/__init__.py Co-authored-by: J. Nick Koston Co-authored-by: J. Nick Koston --- homeassistant/components/syncthru/__init__.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/syncthru/__init__.py b/homeassistant/components/syncthru/__init__.py index 9045b82e2ac..c422bfa6f33 100644 --- a/homeassistant/components/syncthru/__init__.py +++ b/homeassistant/components/syncthru/__init__.py @@ -86,11 +86,6 @@ def device_identifiers(printer: SyncThru) -> set[tuple[str, str]] | None: def device_connections(printer: SyncThru) -> set[tuple[str, str]]: """Get device connections for device registry.""" - connections = set() - try: - mac = printer.raw()["identity"]["mac_addr"] - if mac: - connections.add((dr.CONNECTION_NETWORK_MAC, mac)) - except AttributeError: - pass - return connections + if mac := printer.raw().get("identity", {}).get("mac_addr"): + return {(dr.CONNECTION_NETWORK_MAC, mac)} + return set()