Use runtime_data in venstar integration (#168613)
This commit is contained in:
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
from venstarcolortouch import VenstarColorTouch
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
@@ -15,13 +14,15 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN, VENSTAR_TIMEOUT
|
||||
from .coordinator import VenstarDataUpdateCoordinator
|
||||
from .const import VENSTAR_TIMEOUT
|
||||
from .coordinator import VenstarConfigEntry, VenstarDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: VenstarConfigEntry
|
||||
) -> bool:
|
||||
"""Set up the Venstar thermostat."""
|
||||
username = config_entry.data.get(CONF_USERNAME)
|
||||
password = config_entry.data.get(CONF_PASSWORD)
|
||||
@@ -46,17 +47,14 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
)
|
||||
await venstar_data_coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = venstar_data_coordinator
|
||||
config_entry.runtime_data = venstar_data_coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, config_entry: VenstarConfigEntry
|
||||
) -> bool:
|
||||
"""Unload the config and platforms."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||
config_entry, PLATFORMS
|
||||
)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||
|
||||
@@ -4,21 +4,20 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import VenstarConfigEntry
|
||||
from .entity import VenstarEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VenstarConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Vensar device binary_sensors based on a config entry."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
if coordinator.client.alerts is None:
|
||||
return
|
||||
|
||||
@@ -20,7 +20,7 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_HOST,
|
||||
@@ -50,7 +50,7 @@ from .const import (
|
||||
DOMAIN,
|
||||
HOLD_MODE_TEMPERATURE,
|
||||
)
|
||||
from .coordinator import VenstarDataUpdateCoordinator
|
||||
from .coordinator import VenstarConfigEntry, VenstarDataUpdateCoordinator
|
||||
from .entity import VenstarEntity
|
||||
|
||||
PLATFORM_SCHEMA = CLIMATE_PLATFORM_SCHEMA.extend(
|
||||
@@ -70,11 +70,11 @@ PLATFORM_SCHEMA = CLIMATE_PLATFORM_SCHEMA.extend(
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VenstarConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Venstar thermostat."""
|
||||
venstar_data_coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
venstar_data_coordinator = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
[
|
||||
VenstarThermostat(
|
||||
@@ -122,7 +122,7 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||
def __init__(
|
||||
self,
|
||||
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
||||
config: ConfigEntry,
|
||||
config: VenstarConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the thermostat."""
|
||||
super().__init__(venstar_data_coordinator, config)
|
||||
|
||||
@@ -14,16 +14,18 @@ from homeassistant.helpers import update_coordinator
|
||||
|
||||
from .const import _LOGGER, DOMAIN, VENSTAR_SLEEP
|
||||
|
||||
type VenstarConfigEntry = ConfigEntry[VenstarDataUpdateCoordinator]
|
||||
|
||||
|
||||
class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator[None]):
|
||||
"""Class to manage fetching Venstar data."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: VenstarConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VenstarConfigEntry,
|
||||
venstar_connection: VenstarColorTouch,
|
||||
) -> None:
|
||||
"""Initialize global Venstar data updater."""
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import VenstarDataUpdateCoordinator
|
||||
from .coordinator import VenstarConfigEntry, VenstarDataUpdateCoordinator
|
||||
|
||||
|
||||
class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
|
||||
@@ -19,7 +18,7 @@ class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
|
||||
def __init__(
|
||||
self,
|
||||
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
||||
config: ConfigEntry,
|
||||
config: VenstarConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the data object."""
|
||||
super().__init__(venstar_data_coordinator)
|
||||
|
||||
@@ -12,7 +12,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
PERCENTAGE,
|
||||
@@ -23,8 +22,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import VenstarDataUpdateCoordinator
|
||||
from .coordinator import VenstarConfigEntry, VenstarDataUpdateCoordinator
|
||||
from .entity import VenstarEntity
|
||||
|
||||
RUNTIME_HEAT1 = "heat1"
|
||||
@@ -80,11 +78,11 @@ class VenstarSensorEntityDescription(SensorEntityDescription):
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VenstarConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Venstar device sensors based on a config entry."""
|
||||
coordinator: VenstarDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator = config_entry.runtime_data
|
||||
entities: list[Entity] = []
|
||||
|
||||
if sensors := coordinator.client.get_sensor_list():
|
||||
@@ -142,7 +140,7 @@ class VenstarSensor(VenstarEntity, SensorEntity):
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: VenstarDataUpdateCoordinator,
|
||||
config: ConfigEntry,
|
||||
config: VenstarConfigEntry,
|
||||
entity_description: VenstarSensorEntityDescription,
|
||||
sensor_name: str,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user