Migrate ESPHome to use entry.runtime_data (#120402)
This commit is contained in:
parent
7453b7df63
commit
fccb7ea1f9
22 changed files with 93 additions and 79 deletions
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||
from aioesphomeapi import APIClient
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
|
@ -21,7 +20,7 @@ from .dashboard import async_setup as async_setup_dashboard
|
|||
from .domain_data import DomainData
|
||||
|
||||
# Import config flow so that it's added to the registry
|
||||
from .entry_data import RuntimeEntryData
|
||||
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
||||
from .manager import ESPHomeManager, cleanup_instance
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
@ -33,7 +32,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> bool:
|
||||
"""Set up the esphome component."""
|
||||
host = entry.data[CONF_HOST]
|
||||
port = entry.data[CONF_PORT]
|
||||
|
@ -59,7 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
store=domain_data.get_or_create_store(hass, entry),
|
||||
original_options=dict(entry.options),
|
||||
)
|
||||
domain_data.set_entry_data(entry, entry_data)
|
||||
entry.runtime_data = entry_data
|
||||
|
||||
manager = ESPHomeManager(
|
||||
hass, entry, host, password, cli, zeroconf_instance, domain_data, entry_data
|
||||
|
@ -69,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> bool:
|
||||
"""Unload an esphome config entry."""
|
||||
entry_data = await cleanup_instance(hass, entry)
|
||||
return await hass.config_entries.async_unload_platforms(
|
||||
|
@ -77,6 +76,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
)
|
||||
|
||||
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> None:
|
||||
"""Remove an esphome config entry."""
|
||||
await DomainData.get(hass).get_or_create_store(hass, entry).async_remove()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue