2020-08-26 18:10:32 -06:00
|
|
|
"""GE Kitchen Sensor Entities"""
|
|
|
|
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
|
2020-12-28 15:46:15 -07:00
|
|
|
from .update_coordinator import GeKitchenUpdateCoordinator
|
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):
|
2020-12-28 15:46:15 -07:00
|
|
|
"""GE Kitchen Water Heaters."""
|
2020-08-26 18:10:32 -06:00
|
|
|
_LOGGER.debug('Adding GE "Water Heaters"')
|
2020-12-28 15:46:15 -07:00
|
|
|
coordinator: GeKitchenUpdateCoordinator = 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)
|