Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Aranet integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from aranet4.client import Aranet4Advertisement
8 
9 from homeassistant.components.bluetooth import BluetoothScanningMode
10 from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
12  PassiveBluetoothProcessorCoordinator,
13 )
14 from homeassistant.config_entries import ConfigEntry
15 from homeassistant.const import Platform
16 from homeassistant.core import HomeAssistant
17 
18 PLATFORMS: list[Platform] = [Platform.SENSOR]
19 
20 _LOGGER = logging.getLogger(__name__)
21 
22 type AranetConfigEntry = ConfigEntry[
23  PassiveBluetoothProcessorCoordinator[Aranet4Advertisement]
24 ]
25 
26 
28  service_info: BluetoothServiceInfoBleak,
29 ) -> Aranet4Advertisement:
30  return Aranet4Advertisement(service_info.device, service_info.advertisement)
31 
32 
33 async def async_setup_entry(hass: HomeAssistant, entry: AranetConfigEntry) -> bool:
34  """Set up Aranet from a config entry."""
35 
36  address = entry.unique_id
37  assert address is not None
39  hass,
40  _LOGGER,
41  address=address,
42  mode=BluetoothScanningMode.PASSIVE,
43  update_method=_service_info_to_adv,
44  )
45  entry.runtime_data = coordinator
46  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
47  # only start after all platforms have had a chance to subscribe
48  entry.async_on_unload(coordinator.async_start())
49  return True
50 
51 
52 async def async_unload_entry(hass: HomeAssistant, entry: AranetConfigEntry) -> bool:
53  """Unload a config entry."""
54  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AranetConfigEntry entry)
Definition: __init__.py:52
bool async_setup_entry(HomeAssistant hass, AranetConfigEntry entry)
Definition: __init__.py:33
Aranet4Advertisement _service_info_to_adv(BluetoothServiceInfoBleak service_info)
Definition: __init__.py:29