2021-05-20 09:15:49 -06:00
|
|
|
"""GE Home Sensor Entities"""
|
2020-08-26 18:10:32 -06:00
|
|
|
import async_timeout
|
|
|
|
import logging
|
2020-12-28 15:46:15 -07:00
|
|
|
from typing import Callable
|
2020-08-26 18:10:32 -06:00
|
|
|
|
2020-12-28 15:46:15 -07:00
|
|
|
from homeassistant.components.water_heater import WaterHeaterEntity
|
2020-08-26 18:10:32 -06:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
2020-12-28 15:46:15 -07:00
|
|
|
from .entities import GeWaterHeater
|
2020-08-26 18:10:32 -06:00
|
|
|
from .const import DOMAIN
|
2021-05-20 09:15:49 -06:00
|
|
|
from .update_coordinator import GeHomeUpdateCoordinator
|
2020-08-26 18:10:32 -06:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable):
|
2021-05-20 09:15:49 -06:00
|
|
|
"""GE Home Water Heaters."""
|
2020-08-26 18:10:32 -06:00
|
|
|
_LOGGER.debug('Adding GE "Water Heaters"')
|
2021-05-20 09:15:49 -06:00
|
|
|
coordinator: GeHomeUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
2020-08-26 18:10:32 -06:00
|
|
|
|
|
|
|
# This should be a NOP, but let's be safe
|
|
|
|
with async_timeout.timeout(20):
|
|
|
|
await coordinator.initialization_future
|
|
|
|
_LOGGER.debug('Coordinator init future finished')
|
|
|
|
|
|
|
|
apis = list(coordinator.appliance_apis.values())
|
|
|
|
_LOGGER.debug(f'Found {len(apis):d} appliance APIs')
|
|
|
|
entities = [
|
2020-12-28 15:46:15 -07:00
|
|
|
entity
|
|
|
|
for api in apis
|
|
|
|
for entity in api.entities
|
|
|
|
if isinstance(entity, GeWaterHeater)
|
2020-08-26 18:10:32 -06:00
|
|
|
]
|
|
|
|
_LOGGER.debug(f'Found {len(entities):d} "water heaters"')
|
|
|
|
async_add_entities(entities)
|