From db8784233515f234e46ed7ee0e96509b09d94b31 Mon Sep 17 00:00:00 2001 From: Matt Snyder Date: Sun, 13 Jan 2019 11:47:50 -0600 Subject: [PATCH] Show persistent notification on Doorbird schedule failure (#20033) * Remove unnecessary return. Add persistent notification on failure to configure doorbird schedule. * Update doorbirdpy to 2.0.5 * Fix bare except * Bump version again * Lint * Return false --- homeassistant/components/doorbird.py | 19 +++++++++++++++---- requirements_all.txt | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/doorbird.py b/homeassistant/components/doorbird.py index f952d1ddc1c..28747bbe8be 100644 --- a/homeassistant/components/doorbird.py +++ b/homeassistant/components/doorbird.py @@ -6,6 +6,7 @@ https://home-assistant.io/components/doorbird/ """ import logging +from urllib.error import HTTPError import voluptuous as vol from homeassistant.components.http import HomeAssistantView @@ -14,7 +15,7 @@ from homeassistant.const import CONF_HOST, CONF_USERNAME, \ import homeassistant.helpers.config_validation as cv from homeassistant.util import slugify, dt as dt_util -REQUIREMENTS = ['doorbirdpy==2.0.4'] +REQUIREMENTS = ['doorbirdpy==2.0.6'] _LOGGER = logging.getLogger(__name__) @@ -113,7 +114,18 @@ def setup(hass, config): # Subscribe to doorbell or motion events if events: - doorstation.update_schedule(hass) + try: + doorstation.update_schedule(hass) + except HTTPError: + hass.components.persistent_notification.create( + 'Doorbird configuration failed. Please verify that API ' + 'Operator permission is enabled for the Doorbird user. ' + 'A restart will be required once permissions have been ' + 'verified.', + title='Doorbird Configuration Failure', + notification_id='doorbird_schedule_error') + + return False hass.data[DOMAIN] = doorstations @@ -230,6 +242,7 @@ class ConfiguredDoorBird(): if not self.webhook_is_registered(hass_url): self.device.change_favorite('http', 'Home Assistant ({} events)' .format(event), hass_url) + fav_id = self.get_webhook_id(hass_url) if not fav_id: @@ -253,8 +266,6 @@ class ConfiguredDoorBird(): for relay in self._relay_nums: entry = self.device.get_schedule_entry(event, str(relay)) entry.output.append(output) - resp = self.device.change_schedule(entry) - return resp else: entry = self.device.get_schedule_entry(event) entry.output.append(output) diff --git a/requirements_all.txt b/requirements_all.txt index 22cc8e6ea97..f7f56db88b7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -327,7 +327,7 @@ distro==1.3.0 dlipower==0.7.165 # homeassistant.components.doorbird -doorbirdpy==2.0.4 +doorbirdpy==2.0.6 # homeassistant.components.sensor.dovado dovado==0.4.1