Fix webhook when doorbird not yet setup (#42657)
parent
34f5ad33e9
commit
cca661574d
|
@ -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
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue