Skip to content

Commit

Permalink
Use runtime_data in ecobee (home-assistant#136632)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jan 27, 2025
1 parent 6c9ff41 commit 55278eb
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 42 deletions.
21 changes: 10 additions & 11 deletions homeassistant/components/ecobee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
{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.
Expand All @@ -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)

Expand Down Expand Up @@ -117,9 +119,6 @@ async def refresh(self) -> bool:
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 changes: 3 additions & 3 deletions homeassistant/components/ecobee/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
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):
Expand Down
7 changes: 3 additions & 4 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_TEMPERATURE,
Expand All @@ -39,7 +38,7 @@
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,
Expand Down Expand Up @@ -201,12 +200,12 @@

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)):
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/ecobee/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
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)
Expand All @@ -27,11 +27,11 @@

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)
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/ecobee/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/ecobee/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
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__)
Expand Down Expand Up @@ -54,11 +52,11 @@ class EcobeeNumberEntityDescription(NumberEntityDescription):

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

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/ecobee/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_MILLION,
Expand All @@ -23,6 +22,7 @@
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


Expand Down Expand Up @@ -73,11 +73,11 @@ class EcobeeSensorEntityDescription(SensorEntityDescription):

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))
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/ecobee/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

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__)
Expand All @@ -25,11 +24,11 @@

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(
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/ecobee/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
WeatherEntity,
WeatherEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
UnitOfLength,
UnitOfPressure,
Expand All @@ -29,6 +28,7 @@
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,
Expand All @@ -39,11 +39,11 @@

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)
Expand Down

0 comments on commit 55278eb

Please sign in to comment.