mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use runtime_data in ecobee (#136632)
This commit is contained in:
parent
6c9ff41b0b
commit
55278ebfc8
@ -27,6 +27,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Optional(CONF_API_KEY): cv.string})}, extra=vol.ALLOW_EXTRA
|
||||
)
|
||||
|
||||
type EcobeeConfigEntry = ConfigEntry[EcobeeData]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Ecobee uses config flow for configuration.
|
||||
@ -52,23 +54,23 @@ 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: EcobeeConfigEntry) -> bool:
|
||||
"""Set up ecobee via a config entry."""
|
||||
api_key = entry.data[CONF_API_KEY]
|
||||
refresh_token = entry.data[CONF_REFRESH_TOKEN]
|
||||
|
||||
data = EcobeeData(hass, entry, api_key=api_key, refresh_token=refresh_token)
|
||||
runtime_data = EcobeeData(hass, entry, api_key=api_key, refresh_token=refresh_token)
|
||||
|
||||
if not await data.refresh():
|
||||
if not await runtime_data.refresh():
|
||||
return False
|
||||
|
||||
await data.update()
|
||||
await runtime_data.update()
|
||||
|
||||
if data.ecobee.thermostats is None:
|
||||
if runtime_data.ecobee.thermostats is None:
|
||||
_LOGGER.error("No ecobee devices found to set up")
|
||||
return False
|
||||
|
||||
hass.data[DOMAIN] = data
|
||||
entry.runtime_data = runtime_data
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
@ -117,9 +119,6 @@ class EcobeeData:
|
||||
return False
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: EcobeeConfigEntry) -> bool:
|
||||
"""Unload the config entry and platforms."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data.pop(DOMAIN)
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -6,21 +6,21 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EcobeeConfigEntry
|
||||
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ecobee binary (occupancy) sensors."""
|
||||
data = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
dev = []
|
||||
for index in range(len(data.ecobee.thermostats)):
|
||||
for sensor in data.ecobee.get_remote_sensors(index):
|
||||
|
@ -21,7 +21,6 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_TEMPERATURE,
|
||||
@ -39,7 +38,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||
|
||||
from . import EcobeeData
|
||||
from . import EcobeeConfigEntry, EcobeeData
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
ATTR_ACTIVE_SENSORS,
|
||||
@ -201,12 +200,12 @@ SUPPORT_FLAGS = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat."""
|
||||
|
||||
data = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
entities = []
|
||||
|
||||
for index in range(len(data.ecobee.thermostats)):
|
||||
|
@ -12,11 +12,11 @@ from homeassistant.components.humidifier import (
|
||||
HumidifierEntity,
|
||||
HumidifierEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EcobeeConfigEntry
|
||||
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=3)
|
||||
@ -27,11 +27,11 @@ MODE_OFF = "off"
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat humidifier entity."""
|
||||
data = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
entities = []
|
||||
for index in range(len(data.ecobee.thermostats)):
|
||||
thermostat = data.ecobee.get_thermostat(index)
|
||||
|
@ -3,22 +3,20 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.notify import NotifyEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EcobeeData
|
||||
from .const import DOMAIN
|
||||
from . import EcobeeConfigEntry, EcobeeData
|
||||
from .entity import EcobeeBaseEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat."""
|
||||
data: EcobeeData = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
EcobeeNotifyEntity(data, index) for index in range(len(data.ecobee.thermostats))
|
||||
)
|
||||
|
@ -12,13 +12,11 @@ from homeassistant.components.number import (
|
||||
NumberEntityDescription,
|
||||
NumberMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfTemperature, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EcobeeData
|
||||
from .const import DOMAIN
|
||||
from . import EcobeeConfigEntry, EcobeeData
|
||||
from .entity import EcobeeBaseEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -54,11 +52,11 @@ VENTILATOR_NUMBERS = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat number entity."""
|
||||
data: EcobeeData = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
|
||||
assert data is not None
|
||||
|
||||
|
@ -12,7 +12,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
@ -23,6 +22,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import EcobeeConfigEntry
|
||||
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
|
||||
|
||||
|
||||
@ -73,11 +73,11 @@ SENSOR_TYPES: tuple[EcobeeSensorEntityDescription, ...] = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ecobee sensors."""
|
||||
data = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
entities = [
|
||||
EcobeeSensor(data, sensor["name"], index, description)
|
||||
for index in range(len(data.ecobee.thermostats))
|
||||
|
@ -8,14 +8,13 @@ from typing import Any
|
||||
|
||||
from homeassistant.components.climate import HVACMode
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import EcobeeData
|
||||
from . import EcobeeConfigEntry, EcobeeData
|
||||
from .climate import HASS_TO_ECOBEE_HVAC
|
||||
from .const import DOMAIN, ECOBEE_AUX_HEAT_ONLY
|
||||
from .const import ECOBEE_AUX_HEAT_ONLY
|
||||
from .entity import EcobeeBaseEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -25,11 +24,11 @@ DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat switch entity."""
|
||||
data: EcobeeData = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
|
||||
entities: list[SwitchEntity] = [
|
||||
EcobeeVentilator20MinSwitch(
|
||||
|
@ -17,7 +17,6 @@ from homeassistant.components.weather import (
|
||||
WeatherEntity,
|
||||
WeatherEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
UnitOfLength,
|
||||
UnitOfPressure,
|
||||
@ -29,6 +28,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import EcobeeConfigEntry
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
ECOBEE_MODEL_TO_NAME,
|
||||
@ -39,11 +39,11 @@ from .const import (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: EcobeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ecobee weather platform."""
|
||||
data = hass.data[DOMAIN]
|
||||
data = config_entry.runtime_data
|
||||
dev = []
|
||||
for index in range(len(data.ecobee.thermostats)):
|
||||
thermostat = data.ecobee.get_thermostat(index)
|
||||
|
Loading…
x
Reference in New Issue
Block a user