Migrate doorbird to use entry.runtime_data (#121413)
This commit is contained in:
parent
b6609fa77c
commit
792c6a9cd9
7 changed files with 40 additions and 42 deletions
|
@ -1,12 +1,12 @@
|
|||
"""DoorBird integration utils."""
|
||||
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .device import ConfiguredDoorBird
|
||||
from .models import DoorBirdData
|
||||
from .models import DoorBirdConfigEntry
|
||||
|
||||
|
||||
def get_mac_address_from_door_station_info(door_station_info: dict[str, Any]) -> str:
|
||||
|
@ -18,9 +18,18 @@ def get_door_station_by_token(
|
|||
hass: HomeAssistant, token: str
|
||||
) -> ConfiguredDoorBird | None:
|
||||
"""Get door station by token."""
|
||||
domain_data: dict[str, DoorBirdData] = hass.data[DOMAIN]
|
||||
for data in domain_data.values():
|
||||
door_station = data.door_station
|
||||
for entry in async_get_entries(hass):
|
||||
door_station = entry.runtime_data.door_station
|
||||
if door_station.token == token:
|
||||
return door_station
|
||||
return None
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_entries(hass: HomeAssistant) -> list[DoorBirdConfigEntry]:
|
||||
"""Get all the doorbird entries."""
|
||||
entries = hass.config_entries.async_entries(
|
||||
DOMAIN, include_ignore=True, include_disabled=True
|
||||
)
|
||||
active_entries = [entry for entry in entries if hasattr(entry, "runtime_data")]
|
||||
return cast(list[DoorBirdConfigEntry], active_entries)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue