From b79057348ded59527c4f9508b1c6627914b0e78b Mon Sep 17 00:00:00 2001 From: carstenschroeder Date: Thu, 3 Jan 2019 19:47:16 +0100 Subject: [PATCH] Add exception handling to ADS shutdown (#19682) * Added exception handling to ADS shutdown * corrected whitespaces * deleted blank line --- homeassistant/components/ads/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/ads/__init__.py b/homeassistant/components/ads/__init__.py index 100444c0211..015a12dcfa9 100644 --- a/homeassistant/components/ads/__init__.py +++ b/homeassistant/components/ads/__init__.py @@ -125,16 +125,23 @@ class AdsHub: def shutdown(self, *args, **kwargs): """Shutdown ADS connection.""" + import pyads _LOGGER.debug("Shutting down ADS") for notification_item in self._notification_items.values(): - self._client.del_device_notification( - notification_item.hnotify, - notification_item.huser - ) _LOGGER.debug( "Deleting device notification %d, %d", notification_item.hnotify, notification_item.huser) - self._client.close() + try: + self._client.del_device_notification( + notification_item.hnotify, + notification_item.huser + ) + except pyads.ADSError as err: + _LOGGER.error(err) + try: + self._client.close() + except pyads.ADSError as err: + _LOGGER.error(err) def register_device(self, device): """Register a new device."""