Store runtime data inside the config entry in iBeacon (#117936)
store runtime data inside the config entry Co-authored-by: J. Nick Koston <nick@koston.org>pull/117917/head^2
parent
deded19bb3
commit
be6598ea4f
|
@ -9,10 +9,12 @@ from homeassistant.helpers.device_registry import DeviceEntry, async_get
|
|||
from .const import DOMAIN, PLATFORMS
|
||||
from .coordinator import IBeaconCoordinator
|
||||
|
||||
type IBeaconConfigEntry = ConfigEntry[IBeaconCoordinator]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: IBeaconConfigEntry) -> bool:
|
||||
"""Set up Bluetooth LE Tracker from a config entry."""
|
||||
coordinator = hass.data[DOMAIN] = IBeaconCoordinator(hass, entry, async_get(hass))
|
||||
entry.runtime_data = coordinator = IBeaconCoordinator(hass, entry, async_get(hass))
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
await coordinator.async_start()
|
||||
return True
|
||||
|
@ -20,16 +22,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data.pop(DOMAIN)
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_remove_config_entry_device(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
|
||||
hass: HomeAssistant, config_entry: IBeaconConfigEntry, device_entry: DeviceEntry
|
||||
) -> bool:
|
||||
"""Remove iBeacon config entry from a device."""
|
||||
coordinator: IBeaconCoordinator = hass.data[DOMAIN]
|
||||
coordinator = config_entry.runtime_data
|
||||
return not any(
|
||||
identifier
|
||||
for identifier in device_entry.identifiers
|
||||
|
|
|
@ -6,22 +6,24 @@ from ibeacon_ble import iBeaconAdvertisement
|
|||
|
||||
from homeassistant.components.device_tracker import SourceType
|
||||
from homeassistant.components.device_tracker.config_entry import BaseTrackerEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, SIGNAL_IBEACON_DEVICE_NEW
|
||||
from . import IBeaconConfigEntry
|
||||
from .const import SIGNAL_IBEACON_DEVICE_NEW
|
||||
from .coordinator import IBeaconCoordinator
|
||||
from .entity import IBeaconEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: IBeaconConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up device tracker for iBeacon Tracker component."""
|
||||
coordinator: IBeaconCoordinator = hass.data[DOMAIN]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
@callback
|
||||
def _async_device_new(
|
||||
|
|
|
@ -13,13 +13,13 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfLength
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, SIGNAL_IBEACON_DEVICE_NEW
|
||||
from . import IBeaconConfigEntry
|
||||
from .const import SIGNAL_IBEACON_DEVICE_NEW
|
||||
from .coordinator import IBeaconCoordinator
|
||||
from .entity import IBeaconEntity
|
||||
|
||||
|
@ -67,10 +67,12 @@ SENSOR_DESCRIPTIONS = (
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: IBeaconConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up sensors for iBeacon Tracker component."""
|
||||
coordinator: IBeaconCoordinator = hass.data[DOMAIN]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
@callback
|
||||
def _async_device_new(
|
||||
|
|
Loading…
Reference in New Issue