1 """The Medcom BLE integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from bleak
import BleakError
9 from medcom_ble
import MedcomBleDeviceData
19 from .const
import DEFAULT_SCAN_INTERVAL, DOMAIN
22 PLATFORMS: list[Platform] = [Platform.SENSOR]
24 _LOGGER = logging.getLogger(__name__)
28 """Set up Medcom BLE radiation monitor from a config entry."""
30 address = entry.unique_id
31 elevation = hass.config.elevation
32 is_metric = hass.config.units
is METRIC_SYSTEM
33 assert address
is not None
35 ble_device = bluetooth.async_ble_device_from_address(hass, address)
38 f
"Could not find Medcom BLE device with address {address}"
41 async
def _async_update_method():
42 """Get data from Medcom BLE radiation monitor."""
43 ble_device = bluetooth.async_ble_device_from_address(hass, address)
44 inspector = MedcomBleDeviceData(_LOGGER, elevation, is_metric)
47 data = await inspector.update_device(ble_device)
48 except BleakError
as err:
49 raise UpdateFailed(f
"Unable to fetch data: {err}")
from err
58 update_method=_async_update_method,
59 update_interval=
timedelta(seconds=DEFAULT_SCAN_INTERVAL),
62 await coordinator.async_config_entry_first_refresh()
64 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
66 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
72 """Unload a config entry."""
73 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
74 hass.data[DOMAIN].pop(entry.entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)