Allow doorbird to still setup with missing operator permission (#64727)

This commit is contained in:
J. Nick Koston 2022-01-22 18:45:30 -10:00 committed by GitHub
parent b713a951dd
commit b587e49300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -252,8 +252,11 @@ class ConfiguredDoorBird:
if self.custom_url is not None: if self.custom_url is not None:
hass_url = self.custom_url hass_url = self.custom_url
favorites = self.device.favorites() if not self.doorstation_events:
# User may not have permission to get the favorites
return
favorites = self.device.favorites()
for event in self.doorstation_events: for event in self.doorstation_events:
self._register_event(hass_url, event, favs=favorites) self._register_event(hass_url, event, favs=favorites)
@ -272,16 +275,16 @@ class ConfiguredDoorBird:
url = f"{hass_url}{API_URL}/{event}?token={self._token}" url = f"{hass_url}{API_URL}/{event}?token={self._token}"
# Register HA URL as webhook if not already, then get the ID # Register HA URL as webhook if not already, then get the ID
if not self.webhook_is_registered(url, favs=favs): if self.webhook_is_registered(url, favs=favs):
self.device.change_favorite("http", f"Home Assistant ({event})", url) return
if not self.get_webhook_id(url, favs=favs): self.device.change_favorite("http", f"Home Assistant ({event})", url)
if not self.webhook_is_registered(url):
_LOGGER.warning( _LOGGER.warning(
'Could not find favorite for URL "%s". ' 'Skipping sensor "%s"', 'Could not find favorite for URL "%s". ' 'Skipping sensor "%s"',
url, url,
event, event,
) )
return
def webhook_is_registered(self, url, favs=None) -> bool: def webhook_is_registered(self, url, favs=None) -> bool:
"""Return whether the given URL is registered as a device favorite.""" """Return whether the given URL is registered as a device favorite."""