mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Use runtime_data in intellifire (#144979)
This commit is contained in:
parent
28990e1db5
commit
912798ee34
@ -8,7 +8,6 @@ from intellifire4py import UnifiedFireplace
|
|||||||
from intellifire4py.cloud_interface import IntelliFireCloudInterface
|
from intellifire4py.cloud_interface import IntelliFireCloudInterface
|
||||||
from intellifire4py.model import IntelliFireCommonFireplaceData
|
from intellifire4py.model import IntelliFireCommonFireplaceData
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -27,12 +26,11 @@ from .const import (
|
|||||||
CONF_SERIAL,
|
CONF_SERIAL,
|
||||||
CONF_USER_ID,
|
CONF_USER_ID,
|
||||||
CONF_WEB_CLIENT_ID,
|
CONF_WEB_CLIENT_ID,
|
||||||
DOMAIN,
|
|
||||||
INIT_WAIT_TIME_SECONDS,
|
INIT_WAIT_TIME_SECONDS,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
STARTUP_TIMEOUT,
|
STARTUP_TIMEOUT,
|
||||||
)
|
)
|
||||||
from .coordinator import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -45,7 +43,9 @@ PLATFORMS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _construct_common_data(entry: ConfigEntry) -> IntelliFireCommonFireplaceData:
|
def _construct_common_data(
|
||||||
|
entry: IntellifireConfigEntry,
|
||||||
|
) -> IntelliFireCommonFireplaceData:
|
||||||
"""Convert config entry data into IntelliFireCommonFireplaceData."""
|
"""Convert config entry data into IntelliFireCommonFireplaceData."""
|
||||||
|
|
||||||
return IntelliFireCommonFireplaceData(
|
return IntelliFireCommonFireplaceData(
|
||||||
@ -60,7 +60,9 @@ def _construct_common_data(entry: ConfigEntry) -> IntelliFireCommonFireplaceData
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_migrate_entry(
|
||||||
|
hass: HomeAssistant, config_entry: IntellifireConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Migrate entries."""
|
"""Migrate entries."""
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Migrating configuration from version %s.%s",
|
"Migrating configuration from version %s.%s",
|
||||||
@ -105,7 +107,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: IntellifireConfigEntry) -> bool:
|
||||||
"""Set up IntelliFire from a config entry."""
|
"""Set up IntelliFire from a config entry."""
|
||||||
|
|
||||||
if CONF_USERNAME not in entry.data:
|
if CONF_USERNAME not in entry.data:
|
||||||
@ -133,7 +135,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
LOGGER.debug("Fireplace to Initialized - Awaiting first refresh")
|
LOGGER.debug("Fireplace to Initialized - Awaiting first refresh")
|
||||||
await data_update_coordinator.async_config_entry_first_refresh()
|
await data_update_coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = data_update_coordinator
|
entry.runtime_data = data_update_coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@ -151,9 +153,8 @@ async def _async_wait_for_initialization(
|
|||||||
await asyncio.sleep(INIT_WAIT_TIME_SECONDS)
|
await asyncio.sleep(INIT_WAIT_TIME_SECONDS)
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, entry: IntellifireConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -10,13 +10,11 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
@ -151,11 +149,11 @@ INTELLIFIRE_BINARY_SENSORS: tuple[IntellifireBinarySensorEntityDescription, ...]
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a IntelliFire On/Off Sensor."""
|
"""Set up a IntelliFire On/Off Sensor."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
IntellifireBinarySensor(coordinator=coordinator, description=description)
|
IntellifireBinarySensor(coordinator=coordinator, description=description)
|
||||||
|
@ -10,13 +10,12 @@ 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.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import IntellifireDataUpdateCoordinator
|
from .const import DEFAULT_THERMOSTAT_TEMP, LOGGER
|
||||||
from .const import DEFAULT_THERMOSTAT_TEMP, DOMAIN, LOGGER
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
INTELLIFIRE_CLIMATES: tuple[ClimateEntityDescription, ...] = (
|
INTELLIFIRE_CLIMATES: tuple[ClimateEntityDescription, ...] = (
|
||||||
@ -26,11 +25,11 @@ INTELLIFIRE_CLIMATES: tuple[ClimateEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Configure the fan entry.."""
|
"""Configure the fan entry.."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
if coordinator.data.has_thermostat:
|
if coordinator.data.has_thermostat:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
@ -16,16 +16,18 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
|
|
||||||
|
type IntellifireConfigEntry = ConfigEntry[IntellifireDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class IntellifireDataUpdateCoordinator(DataUpdateCoordinator[IntelliFirePollData]):
|
class IntellifireDataUpdateCoordinator(DataUpdateCoordinator[IntelliFirePollData]):
|
||||||
"""Class to manage the polling of the fireplace API."""
|
"""Class to manage the polling of the fireplace API."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: IntellifireConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: IntellifireConfigEntry,
|
||||||
fireplace: UnifiedFireplace,
|
fireplace: UnifiedFireplace,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Coordinator."""
|
"""Initialize the Coordinator."""
|
||||||
|
@ -15,7 +15,6 @@ from homeassistant.components.fan import (
|
|||||||
FanEntityDescription,
|
FanEntityDescription,
|
||||||
FanEntityFeature,
|
FanEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.util.percentage import (
|
from homeassistant.util.percentage import (
|
||||||
@ -23,8 +22,8 @@ from homeassistant.util.percentage import (
|
|||||||
ranged_value_to_percentage,
|
ranged_value_to_percentage,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import LOGGER
|
||||||
from .coordinator import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +56,11 @@ INTELLIFIRE_FANS: tuple[IntellifireFanEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the fans."""
|
"""Set up the fans."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
if coordinator.data.has_fan:
|
if coordinator.data.has_fan:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
@ -15,12 +15,11 @@ from homeassistant.components.light import (
|
|||||||
LightEntity,
|
LightEntity,
|
||||||
LightEntityDescription,
|
LightEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import LOGGER
|
||||||
from .coordinator import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
@ -84,11 +83,11 @@ class IntellifireLight(IntellifireEntity, LightEntity):
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the fans."""
|
"""Set up the fans."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
if coordinator.data.has_light:
|
if coordinator.data.has_light:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
@ -9,22 +9,21 @@ from homeassistant.components.number import (
|
|||||||
NumberEntityDescription,
|
NumberEntityDescription,
|
||||||
NumberMode,
|
NumberMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import LOGGER
|
||||||
from .coordinator import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the fans."""
|
"""Set up the fans."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
description = NumberEntityDescription(
|
description = NumberEntityDescription(
|
||||||
key="flame_control",
|
key="flame_control",
|
||||||
|
@ -12,14 +12,12 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory, UnitOfTemperature
|
from homeassistant.const import EntityCategory, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
from .coordinator import IntellifireDataUpdateCoordinator
|
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
@ -142,12 +140,12 @@ INTELLIFIRE_SENSORS: tuple[IntellifireSensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Define setup entry call."""
|
"""Define setup entry call."""
|
||||||
|
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
IntelliFireSensor(coordinator=coordinator, description=description)
|
IntelliFireSensor(coordinator=coordinator, description=description)
|
||||||
for description in INTELLIFIRE_SENSORS
|
for description in INTELLIFIRE_SENSORS
|
||||||
|
@ -7,12 +7,10 @@ from dataclasses import dataclass
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import IntellifireDataUpdateCoordinator
|
from .coordinator import IntellifireConfigEntry, IntellifireDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import IntellifireEntity
|
from .entity import IntellifireEntity
|
||||||
|
|
||||||
|
|
||||||
@ -52,11 +50,11 @@ INTELLIFIRE_SWITCHES: tuple[IntellifireSwitchEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: IntellifireConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Configure switch entities."""
|
"""Configure switch entities."""
|
||||||
coordinator: IntellifireDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
IntellifireSwitch(coordinator=coordinator, description=description)
|
IntellifireSwitch(coordinator=coordinator, description=description)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user