Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The iBeacon tracker integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers import device_registry as dr
8 from homeassistant.helpers.device_registry import DeviceEntry
9 
10 from .const import DOMAIN, PLATFORMS
11 from .coordinator import IBeaconCoordinator
12 
13 type IBeaconConfigEntry = ConfigEntry[IBeaconCoordinator]
14 
15 
16 async def async_setup_entry(hass: HomeAssistant, entry: IBeaconConfigEntry) -> bool:
17  """Set up Bluetooth LE Tracker from a config entry."""
18  entry.runtime_data = coordinator = IBeaconCoordinator(
19  hass, entry, dr.async_get(hass)
20  )
21  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
22  await coordinator.async_start()
23  return True
24 
25 
26 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
27  """Unload a config entry."""
28  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
29 
30 
32  hass: HomeAssistant, config_entry: IBeaconConfigEntry, device_entry: DeviceEntry
33 ) -> bool:
34  """Remove iBeacon config entry from a device."""
35  coordinator = config_entry.runtime_data
36  return not any(
37  identifier
38  for identifier in device_entry.identifiers
39  if identifier[0] == DOMAIN and coordinator.async_device_id_seen(identifier[1])
40  )
bool async_setup_entry(HomeAssistant hass, IBeaconConfigEntry entry)
Definition: __init__.py:16
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:26
bool async_remove_config_entry_device(HomeAssistant hass, IBeaconConfigEntry config_entry, DeviceEntry device_entry)
Definition: __init__.py:33