1 """The Airthings BLE integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from airthings_ble
import AirthingsBluetoothDeviceData, AirthingsDevice
9 from bleak.backends.device
import BLEDevice
10 from bleak_retry_connector
import close_stale_connections_by_address
19 from .const
import DEFAULT_SCAN_INTERVAL, DOMAIN
21 _LOGGER = logging.getLogger(__name__)
23 type AirthingsBLEConfigEntry = ConfigEntry[AirthingsBLEDataUpdateCoordinator]
27 """Class to manage fetching Airthings BLE data."""
30 config_entry: AirthingsBLEConfigEntry
32 def __init__(self, hass: HomeAssistant, entry: AirthingsBLEConfigEntry) ->
None:
33 """Initialize the coordinator."""
34 self.
airthingsairthings = AirthingsBluetoothDeviceData(
35 _LOGGER, hass.config.units
is METRIC_SYSTEM
42 update_interval=
timedelta(seconds=DEFAULT_SCAN_INTERVAL),
46 """Set up the coordinator."""
49 assert address
is not None
51 await close_stale_connections_by_address(address)
53 ble_device = bluetooth.async_ble_device_from_address(self.
hasshass, address)
57 f
"Could not find Airthings device with address {address}"
62 """Get data from Airthings BLE."""
65 except Exception
as err:
66 raise UpdateFailed(f
"Unable to fetch data: {err}")
from err
None __init__(self, HomeAssistant hass, AirthingsBLEConfigEntry entry)
AirthingsDevice _async_update_data(self)
str|None update_device(HomeAssistant hass, ConfigEntry config_entry, ConfigType config)