2021-05-20 09:15:49 -06:00
|
|
|
"""GE Home Sensor Entities"""
|
2020-08-13 15:10:55 -06:00
|
|
|
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
|
|
|
|
2020-08-26 07:22:54 -06:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
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 GeErdBinarySensor
|
2021-05-20 09:15:49 -06:00
|
|
|
from .update_coordinator import GeHomeUpdateCoordinator
|
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):
|
2021-05-20 09:15:49 -06:00
|
|
|
"""GE Home sensors."""
|
2020-08-13 15:10:55 -06:00
|
|
|
|
2021-05-20 09:15:49 -06:00
|
|
|
coordinator: GeHomeUpdateCoordinator = 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
|
|
|
|
|
|
|
|
apis = coordinator.appliance_apis.values()
|
2020-08-24 19:22:32 -06:00
|
|
|
_LOGGER.debug(f'Found {len(apis):d} appliance APIs')
|
|
|
|
entities = [
|
2020-08-13 15:10:55 -06:00
|
|
|
entity
|
|
|
|
for api in apis
|
|
|
|
for entity in api.entities
|
2020-08-26 07:22:54 -06:00
|
|
|
if isinstance(entity, GeErdBinarySensor) and not isinstance(entity, SwitchEntity)
|
2020-08-13 15:10:55 -06:00
|
|
|
]
|
2020-08-24 19:22:32 -06:00
|
|
|
_LOGGER.debug(f'Found {len(entities):d} binary sensors ')
|
|
|
|
async_add_entities(entities)
|