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 <nick@koston.org>

* Update homeassistant/components/syncthru/__init__.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Update homeassistant/components/syncthru/__init__.py

Co-authored-by: J. Nick Koston <nick@koston.org>

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Niels Mündler 2021-08-24 17:56:36 +02:00 committed by GitHub
parent 2e62de5116
commit abfba1f455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()