mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Use runtime_data in bsblan (#129089)
This commit is contained in:
parent
a2c9aa7662
commit
f91a1363cb
@ -15,11 +15,13 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import CONF_PASSKEY, DOMAIN
|
from .const import CONF_PASSKEY
|
||||||
from .coordinator import BSBLanUpdateCoordinator
|
from .coordinator import BSBLanUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
||||||
|
|
||||||
|
type BSBLanConfigEntry = ConfigEntry[BSBLanData]
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class BSBLanData:
|
class BSBLanData:
|
||||||
@ -32,7 +34,7 @@ class BSBLanData:
|
|||||||
static: StaticState
|
static: StaticState
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: BSBLanConfigEntry) -> bool:
|
||||||
"""Set up BSB-Lan from a config entry."""
|
"""Set up BSB-Lan from a config entry."""
|
||||||
|
|
||||||
# create config using BSBLANConfig
|
# create config using BSBLANConfig
|
||||||
@ -57,7 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
info = await bsblan.info()
|
info = await bsblan.info()
|
||||||
static = await bsblan.static_values()
|
static = await bsblan.static_values()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = BSBLanData(
|
entry.runtime_data = BSBLanData(
|
||||||
client=bsblan,
|
client=bsblan,
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
device=device,
|
device=device,
|
||||||
@ -70,11 +72,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: BSBLanConfigEntry) -> bool:
|
||||||
"""Unload BSBLAN config entry."""
|
"""Unload BSBLAN config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
# Cleanup
|
|
||||||
del hass.data[DOMAIN][entry.entry_id]
|
|
||||||
if not hass.data[DOMAIN]:
|
|
||||||
del hass.data[DOMAIN]
|
|
||||||
return unload_ok
|
|
||||||
|
@ -15,7 +15,6 @@ from homeassistant.components.climate import (
|
|||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
@ -23,7 +22,7 @@ from homeassistant.helpers.device_registry import format_mac
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.enum import try_parse_enum
|
from homeassistant.util.enum import try_parse_enum
|
||||||
|
|
||||||
from . import BSBLanData
|
from . import BSBLanConfigEntry, BSBLanData
|
||||||
from .const import ATTR_TARGET_TEMPERATURE, DOMAIN
|
from .const import ATTR_TARGET_TEMPERATURE, DOMAIN
|
||||||
from .entity import BSBLanEntity
|
from .entity import BSBLanEntity
|
||||||
|
|
||||||
@ -43,18 +42,12 @@ PRESET_MODES = [
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: BSBLanConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up BSBLAN device based on a config entry."""
|
"""Set up BSBLAN device based on a config entry."""
|
||||||
data: BSBLanData = hass.data[DOMAIN][entry.entry_id]
|
data = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities([BSBLANClimate(data)])
|
||||||
[
|
|
||||||
BSBLANClimate(
|
|
||||||
data,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BSBLANClimate(BSBLanEntity, ClimateEntity):
|
class BSBLANClimate(BSBLanEntity, ClimateEntity):
|
||||||
|
@ -4,18 +4,16 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import BSBLanData
|
from . import BSBLanConfigEntry
|
||||||
from .const import DOMAIN
|
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: BSBLanConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
data: BSBLanData = hass.data[DOMAIN][entry.entry_id]
|
data = entry.runtime_data
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"info": data.info.to_dict(),
|
"info": data.info.to_dict(),
|
||||||
|
@ -11,14 +11,12 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import UnitOfTemperature
|
from homeassistant.const import UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import BSBLanData
|
from . import BSBLanConfigEntry, BSBLanData
|
||||||
from .const import DOMAIN
|
|
||||||
from .coordinator import BSBLanCoordinatorData
|
from .coordinator import BSBLanCoordinatorData
|
||||||
from .entity import BSBLanEntity
|
from .entity import BSBLanEntity
|
||||||
|
|
||||||
@ -52,11 +50,11 @@ SENSOR_TYPES: tuple[BSBLanSensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: BSBLanConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up BSB-Lan sensor based on a config entry."""
|
"""Set up BSB-Lan sensor based on a config entry."""
|
||||||
data: BSBLanData = hass.data[DOMAIN][entry.entry_id]
|
data = entry.runtime_data
|
||||||
async_add_entities(BSBLanSensor(data, description) for description in SENSOR_TYPES)
|
async_add_entities(BSBLanSensor(data, description) for description in SENSOR_TYPES)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user