mirror of https://github.com/home-assistant/core
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
"""The Leaone integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from leaone_ble import LeaoneBluetoothDeviceData
|
|
|
|
from homeassistant.components.bluetooth import BluetoothScanningMode
|
|
from homeassistant.components.bluetooth.passive_update_processor import (
|
|
PassiveBluetoothProcessorCoordinator,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import DOMAIN
|
|
|
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up Leaone BLE device from a config entry."""
|
|
address = entry.unique_id
|
|
assert address is not None
|
|
data = LeaoneBluetoothDeviceData()
|
|
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
|
|
PassiveBluetoothProcessorCoordinator(
|
|
hass,
|
|
_LOGGER,
|
|
address=address,
|
|
mode=BluetoothScanningMode.PASSIVE,
|
|
update_method=data.update,
|
|
)
|
|
)
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
entry.async_on_unload(
|
|
coordinator.async_start()
|
|
) # only start after all platforms have had a chance to subscribe
|
|
return True
|
|
|
|
|
|
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[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|