mirror of
https://github.com/home-assistant/core.git
synced 2026-07-04 21:25:26 +01:00
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""The Avea integration."""
|
|
|
|
import avea
|
|
|
|
from homeassistant.components.bluetooth import (
|
|
BluetoothReachabilityIntent,
|
|
async_address_reachability_diagnostics,
|
|
async_ble_device_from_address,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_ADDRESS, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
from .const import DOMAIN
|
|
|
|
type AveaConfigEntry = ConfigEntry[avea.Bulb]
|
|
|
|
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: AveaConfigEntry) -> bool:
|
|
"""Set up Avea from a config entry."""
|
|
address = entry.data[CONF_ADDRESS]
|
|
ble_device = async_ble_device_from_address(hass, address, connectable=True)
|
|
if not ble_device:
|
|
raise ConfigEntryNotReady(
|
|
translation_domain=DOMAIN,
|
|
translation_key="device_not_found",
|
|
translation_placeholders={
|
|
"address": address,
|
|
"reason": async_address_reachability_diagnostics(
|
|
hass,
|
|
address.upper(),
|
|
BluetoothReachabilityIntent.CONNECTION,
|
|
),
|
|
},
|
|
)
|
|
|
|
entry.runtime_data = avea.Bulb(ble_device)
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: AveaConfigEntry) -> bool:
|
|
"""Unload an Avea config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|