1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

Fix webhook when doorbird not yet setup (#42657)

This commit is contained in:
J. Nick Koston 2020-11-04 05:34:07 -10:00 committed by GitHub
parent 34f5ad33e9
commit cca661574d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,9 +11,32 @@ def get_mac_address_from_doorstation_info(doorstation_info):
def get_doorstation_by_token(hass, token):
"""Get doorstation by slug."""
for config_entry_id in hass.data[DOMAIN]:
doorstation = hass.data[DOMAIN][config_entry_id][DOOR_STATION]
"""Get doorstation by token."""
return _get_doorstation_by_attr(hass, "token", token)
if token == doorstation.token:
def get_doorstation_by_slug(hass, slug):
"""Get doorstation by slug."""
return _get_doorstation_by_attr(hass, "slug", slug)
def _get_doorstation_by_attr(hass, attr, val):
for entry in hass.data[DOMAIN].values():
if DOOR_STATION not in entry:
continue
doorstation = entry[DOOR_STATION]
if getattr(doorstation, attr) == val:
return doorstation
return None
def get_all_doorstations(hass):
"""Get all doorstations."""
return [
entry[DOOR_STATION]
for entry in hass.data[DOMAIN].values()
if DOOR_STATION in entry
]