Add exception handling to ADS shutdown ()

* Added exception handling to ADS shutdown

* corrected whitespaces

* deleted blank line
pull/19766/head
carstenschroeder 2019-01-03 19:47:16 +01:00 committed by Martin Hjelmare
parent 6b18b92bdd
commit b79057348d
1 changed files with 12 additions and 5 deletions
homeassistant/components/ads

View File

@ -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."""