1 """The EufyLife integration."""
3 from __future__
import annotations
5 from eufylife_ble_client
import EufyLifeBLEDevice
13 from .const
import DOMAIN
14 from .models
import EufyLifeData
16 PLATFORMS: list[Platform] = [Platform.SENSOR]
20 """Set up EufyLife device from a config entry."""
21 address = entry.unique_id
22 assert address
is not None
24 model = entry.data[CONF_MODEL]
25 client = EufyLifeBLEDevice(model=model)
28 def _async_update_ble(
29 service_info: bluetooth.BluetoothServiceInfoBleak,
30 change: bluetooth.BluetoothChange,
32 """Update from a ble callback."""
33 client.set_ble_device_and_advertisement_data(
34 service_info.device, service_info.advertisement
36 if not client.advertisement_data_contains_state:
37 hass.async_create_task(client.connect())
39 entry.async_on_unload(
40 bluetooth.async_register_callback(
44 bluetooth.BluetoothScanningMode.ACTIVE,
48 hass.data.setdefault(DOMAIN, {})[entry.entry_id] =
EufyLifeData(
54 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
57 """Close the connection."""
60 entry.async_on_unload(
61 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop)
67 """Unload a config entry."""
68 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
69 hass.data[DOMAIN].pop(entry.entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None _async_stop(HomeAssistant hass, bool restart)