2021-05-20 09:15:49 -06:00
|
|
|
"""GE Home Sensor Entities"""
|
2020-08-13 15:10:55 -06:00
|
|
|
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
|
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
|
2020-08-26 07:22:54 -06:00
|
|
|
|
2020-08-13 15:10:55 -06:00
|
|
|
from .const import DOMAIN
|
2022-10-16 08:44:14 -06:00
|
|
|
from .devices import ApplianceApi
|
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):
|
2022-10-16 08:44:14 -06:00
|
|
|
"""GE Home binary sensors."""
|
2020-08-13 15:10:55 -06:00
|
|
|
|
2022-10-16 08:44:14 -06:00
|
|
|
_LOGGER.debug('Adding GE Binary Sensor Entities')
|
2021-05-20 09:15:49 -06:00
|
|
|
coordinator: GeHomeUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
2022-10-16 08:44:14 -06:00
|
|
|
registry = er.async_get(hass)
|
2020-08-13 15:10:55 -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')
|
2020-08-13 15:10:55 -06:00
|
|
|
|
2022-10-16 08:44:14 -06:00
|
|
|
entities = [
|
|
|
|
entity
|
|
|
|
for api in apis
|
|
|
|
for entity in api.entities
|
|
|
|
if isinstance(entity, GeErdBinarySensor) and not isinstance(entity, SwitchEntity)
|
|
|
|
if not registry.async_is_registered(entity.entity_id)
|
|
|
|
]
|
|
|
|
_LOGGER.debug(f'Found {len(entities):d} unregistered binary sensors')
|
|
|
|
async_add_entities(entities)
|
2024-01-28 08:07:52 -07:00
|
|
|
|
|
|
|
#if we're already initialized at this point, call device
|
|
|
|
#discovery directly, otherwise add a callback based on the
|
|
|
|
#ready signal
|
|
|
|
if coordinator.initialized:
|
|
|
|
async_devices_discovered(coordinator.appliance_apis.values())
|
|
|
|
else:
|
|
|
|
# add the ready signal and register the remove callback
|
|
|
|
coordinator.add_signal_remove_callback(
|
|
|
|
async_dispatcher_connect(hass, coordinator.signal_ready, async_devices_discovered))
|