Add config flow, use async loading, and restore brightness option to ISY994 (#35413)
* ISY994 Add Config and Options Flow Add tests for config flow Fix test Update Tests * Fix merge errors * Update homeassistant/components/isy994/strings.json Co-authored-by: J. Nick Koston <nick@koston.org> * Apply suggestions from code review Co-authored-by: J. Nick Koston <nick@koston.org> * Fix patching in tests to not actually start Home Assistant Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
d61bde6ae6
commit
d7f736ed6c
19 changed files with 847 additions and 149 deletions
|
@ -23,20 +23,24 @@ from homeassistant.components.binary_sensor import (
|
|||
DOMAIN as BINARY_SENSOR,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import ISY994_NODES, ISY994_PROGRAMS
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
BINARY_SENSOR_DEVICE_TYPES_ISY,
|
||||
BINARY_SENSOR_DEVICE_TYPES_ZWAVE,
|
||||
DOMAIN as ISY994_DOMAIN,
|
||||
ISY994_NODES,
|
||||
ISY994_PROGRAMS,
|
||||
TYPE_CATEGORY_CLIMATE,
|
||||
)
|
||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||
from .helpers import migrate_old_unique_ids
|
||||
|
||||
DEVICE_PARENT_REQUIRED = [
|
||||
DEVICE_CLASS_OPENING,
|
||||
|
@ -56,15 +60,18 @@ SUBNODE_MOTION_DISABLED = (13, 19) # Int->13 or Hex->0xD depending on firmware
|
|||
TYPE_INSTEON_MOTION = ("16.1.", "16.22.")
|
||||
|
||||
|
||||
def setup_platform(
|
||||
hass, config: ConfigType, add_entities: Callable[[list], None], discovery_info=None
|
||||
):
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistantType,
|
||||
entry: ConfigEntry,
|
||||
async_add_entities: Callable[[list], None],
|
||||
) -> bool:
|
||||
"""Set up the ISY994 binary sensor platform."""
|
||||
devices = []
|
||||
devices_by_address = {}
|
||||
child_nodes = []
|
||||
|
||||
for node in hass.data[ISY994_NODES][BINARY_SENSOR]:
|
||||
hass_isy_data = hass.data[ISY994_DOMAIN][entry.entry_id]
|
||||
for node in hass_isy_data[ISY994_NODES][BINARY_SENSOR]:
|
||||
device_class, device_type = _detect_device_type_and_class(node)
|
||||
if node.protocol == PROTO_INSTEON:
|
||||
if node.parent_node is not None:
|
||||
|
@ -162,10 +169,11 @@ def setup_platform(
|
|||
device = ISYBinarySensorEntity(node, device_class)
|
||||
devices.append(device)
|
||||
|
||||
for name, status, _ in hass.data[ISY994_PROGRAMS][BINARY_SENSOR]:
|
||||
for name, status, _ in hass_isy_data[ISY994_PROGRAMS][BINARY_SENSOR]:
|
||||
devices.append(ISYBinarySensorProgramEntity(name, status))
|
||||
|
||||
add_entities(devices)
|
||||
await migrate_old_unique_ids(hass, BINARY_SENSOR, devices)
|
||||
async_add_entities(devices)
|
||||
|
||||
|
||||
def _detect_device_type_and_class(node: Union[Group, Node]) -> (str, str):
|
||||
|
@ -235,7 +243,7 @@ class ISYInsteonBinarySensorEntity(ISYBinarySensorEntity):
|
|||
|
||||
Often times, a single device is represented by multiple nodes in the ISY,
|
||||
allowing for different nuances in how those devices report their on and
|
||||
off events. This class turns those multiple nodes in to a single Home
|
||||
off events. This class turns those multiple nodes into a single Home
|
||||
Assistant entity and handles both ways that ISY binary sensors can work.
|
||||
"""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue