40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""Heating MPC custom integration, initial release shadow-only."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.const import Platform
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.storage import Store
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import HeatingMPCCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.BINARY_SENSOR]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
coordinator = HeatingMPCCoordinator(hass, entry)
|
|
await coordinator.async_restore_model()
|
|
await coordinator.async_config_entry_first_refresh()
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
|
|
return True
|
|
|
|
|
|
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|
await hass.config_entries.async_reload(entry.entry_id)
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
if ok:
|
|
hass.data[DOMAIN].pop(entry.entry_id, None)
|
|
return ok
|
|
|
|
|
|
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|
"""Remove the learned model when this integration instance is deleted."""
|
|
store = Store(hass, 1, f"{DOMAIN}.{entry.entry_id}")
|
|
await store.async_remove()
|