2021-08-01 08:54:21 -06:00
|
|
|
"""GE Home Climate Entities"""
|
|
|
|
import logging
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
from homeassistant.components.climate import ClimateEntity
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-10-16 08:44:14 -06:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
from homeassistant.helpers import entity_registry as er
|
2021-08-01 08:54:21 -06:00
|
|
|
|
|
|
|
from .entities import GeClimate
|
|
|
|
from .const import DOMAIN
|
2022-10-16 08:44:14 -06:00
|
|
|
from .devices import ApplianceApi
|
2021-08-01 08:54:21 -06:00
|
|
|
from .update_coordinator import GeHomeUpdateCoordinator
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable):
|
2022-10-16 08:44:14 -06:00
|
|
|
"""GE Climate Devices."""
|
|
|
|
|
2021-08-01 08:54:21 -06:00
|
|
|
_LOGGER.debug('Adding GE Climate Entities')
|
|
|
|
coordinator: GeHomeUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
2022-10-16 08:44:14 -06:00
|
|
|
registry = er.async_get(hass)
|
2021-08-01 08:54:21 -06:00
|
|
|
|
2022-10-16 08:44:14 -06:00
|
|
|
@callback
|
|
|
|
def async_devices_discovered(apis: list[ApplianceApi]):
|
|
|
|
_LOGGER.debug(f'Found {len(apis):d} appliance APIs')
|
2021-08-01 08:54:21 -06:00
|
|
|
|
2022-10-16 08:44:14 -06:00
|
|
|
entities = [
|
|
|
|
entity
|
|
|
|
for api in apis
|
|
|
|
for entity in api.entities
|
|
|
|
if isinstance(entity, GeClimate)
|
|
|
|
if not registry.async_is_registered(entity.entity_id)
|
|
|
|
]
|
|
|
|
_LOGGER.debug(f'Found {len(entities):d} unregistered climate entities')
|
|
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered)
|