Home Assistant Unofficial Reference 2024.12.1
util.py
Go to the documentation of this file.
1 """DoorBird integration utils."""
2 
3 from typing import Any, cast
4 
5 from homeassistant.core import HomeAssistant, callback
6 
7 from .const import DOMAIN
8 from .device import ConfiguredDoorBird
9 from .models import DoorBirdConfigEntry
10 
11 
12 def get_mac_address_from_door_station_info(door_station_info: dict[str, Any]) -> str:
13  """Get the mac address depending on the device type."""
14  return door_station_info.get("PRIMARY_MAC_ADDR", door_station_info["WIFI_MAC_ADDR"]) # type: ignore[no-any-return]
15 
16 
18  hass: HomeAssistant, token: str
19 ) -> ConfiguredDoorBird | None:
20  """Get door station by token."""
21  for entry in async_get_entries(hass):
22  door_station = entry.runtime_data.door_station
23  if door_station.token == token:
24  return door_station
25  return None
26 
27 
28 @callback
29 def async_get_entries(hass: HomeAssistant) -> list[DoorBirdConfigEntry]:
30  """Get all the doorbird entries."""
31  entries = hass.config_entries.async_entries(
32  DOMAIN, include_ignore=True, include_disabled=True
33  )
34  active_entries = [entry for entry in entries if hasattr(entry, "runtime_data")]
35  return cast(list[DoorBirdConfigEntry], active_entries)
ConfiguredDoorBird|None get_door_station_by_token(HomeAssistant hass, str token)
Definition: util.py:19
str get_mac_address_from_door_station_info(dict[str, Any] door_station_info)
Definition: util.py:12
list[DoorBirdConfigEntry] async_get_entries(HomeAssistant hass)
Definition: util.py:29