2020-08-13 15:10:55 -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-13 15:10:55 -06:00
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2020-08-26 07:22:54 -06:00
|
|
|
|
2020-08-13 15:10:55 -06:00
|
|
|
from .const import DOMAIN
|
2020-12-28 15:46:15 -07:00
|
|
|
from .entities import GeErdSensor
|
|
|
|
from .update_coordinator import GeKitchenUpdateCoordinator
|
2020-08-13 15:10:55 -06:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable):
|
|
|
|
"""GE Kitchen sensors."""
|
|
|
|
_LOGGER.debug('Adding GE Kitchen sensors')
|
2020-12-28 15:46:15 -07:00
|
|
|
coordinator: GeKitchenUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
2020-08-13 15:10:55 -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 = [
|
|
|
|
entity
|
|
|
|
for api in apis
|
|
|
|
for entity in api.entities
|
2020-08-24 19:22:32 -06:00
|
|
|
if isinstance(entity, GeErdSensor) and entity.erd_code in api.appliance._property_cache
|
2020-08-13 15:10:55 -06:00
|
|
|
]
|
|
|
|
_LOGGER.debug(f'Found {len(entities):d} sensors')
|
|
|
|
async_add_entities(entities)
|