From 6996ad35415c0ec6e8ea5fe0efadab1471da4efd Mon Sep 17 00:00:00 2001 From: gjbadros Date: Mon, 9 Dec 2019 00:14:55 -0800 Subject: [PATCH] Protect Doorbird platform from failing when individual doorbird fails (#29374) * Wrap connection attempt by try/except block so an individual downed doorbird does not fail the whole platform * Fixed lint warning * Disable too-broad-exception pylint warning since the whole point of this is to catch all exceptions and log them while letting processing continue; I don't disable a lint warning lightly, but this is the entire intent of this PR. * Fixed name of pylint warning to broad-except * Use _LOGGER.exception to get the stack trace too, per PEP8 recommendation for a bare Exception being caught. * per @balloob, switch to just catching OSError on a narrow block; I'm not sure this protects all problems with Doorbird device startup, but it protects against the primary one I experience. --- homeassistant/components/doorbird/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index d92ff3d3692..680ee1354eb 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -67,8 +67,14 @@ def setup(hass, config): token = doorstation_config.get(CONF_TOKEN) name = doorstation_config.get(CONF_NAME) or "DoorBird {}".format(index + 1) - device = DoorBird(device_ip, username, password) - status = device.ready() + try: + device = DoorBird(device_ip, username, password) + status = device.ready() + except OSError as oserr: + _LOGGER.error( + "Failed to setup doorbird at %s: %s; not retrying", device_ip, oserr + ) + continue if status[0]: doorstation = ConfiguredDoorBird(device, name, events, custom_url, token)