Fix Insteon open issues with adding devices by address and missing events (#89305)
* Add missing events * Bump dependancies * Update for code reviewpull/89381/head
parent
74d3b2374b
commit
52cd2f9429
|
@ -17,8 +17,8 @@
|
|||
"iot_class": "local_push",
|
||||
"loggers": ["pyinsteon", "pypubsub"],
|
||||
"requirements": [
|
||||
"pyinsteon==1.3.3",
|
||||
"insteon-frontend-home-assistant==0.3.2"
|
||||
"pyinsteon==1.3.4",
|
||||
"insteon-frontend-home-assistant==0.3.3"
|
||||
],
|
||||
"usb": [
|
||||
{
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
"""Utilities used by insteon component."""
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
import logging
|
||||
|
||||
from pyinsteon import devices
|
||||
from pyinsteon.address import Address
|
||||
from pyinsteon.constants import ALDBStatus, DeviceAction
|
||||
from pyinsteon.events import OFF_EVENT, OFF_FAST_EVENT, ON_EVENT, ON_FAST_EVENT
|
||||
from pyinsteon.device_types.device_base import Device
|
||||
from pyinsteon.events import OFF_EVENT, OFF_FAST_EVENT, ON_EVENT, ON_FAST_EVENT, Event
|
||||
from pyinsteon.managers.link_manager import (
|
||||
async_enter_linking_mode,
|
||||
async_enter_unlinking_mode,
|
||||
|
@ -27,7 +29,7 @@ from homeassistant.const import (
|
|||
CONF_PLATFORM,
|
||||
ENTITY_MATCH_ALL,
|
||||
)
|
||||
from homeassistant.core import ServiceCall, callback
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
|
@ -89,49 +91,52 @@ from .schemas import (
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def add_on_off_event_device(hass, device):
|
||||
def _register_event(event: Event, listener: Callable) -> None:
|
||||
"""Register the events raised by a device."""
|
||||
_LOGGER.debug(
|
||||
"Registering on/off event for %s %d %s",
|
||||
str(event.address),
|
||||
event.group,
|
||||
event.name,
|
||||
)
|
||||
event.subscribe(listener, force_strong_ref=True)
|
||||
|
||||
|
||||
def add_on_off_event_device(hass: HomeAssistant, device: Device) -> None:
|
||||
"""Register an Insteon device as an on/off event device."""
|
||||
|
||||
@callback
|
||||
def async_fire_group_on_off_event(name, address, group, button):
|
||||
def async_fire_group_on_off_event(
|
||||
name: str, address: Address, group: int, button: str
|
||||
):
|
||||
# Firing an event when a button is pressed.
|
||||
if button and button[-2] == "_":
|
||||
button_id = button[-1].lower()
|
||||
else:
|
||||
button_id = None
|
||||
|
||||
schema = {CONF_ADDRESS: address}
|
||||
schema = {CONF_ADDRESS: address, "group": group}
|
||||
if button_id:
|
||||
schema[EVENT_CONF_BUTTON] = button_id
|
||||
if name == ON_EVENT:
|
||||
event = EVENT_GROUP_ON
|
||||
if name == OFF_EVENT:
|
||||
elif name == OFF_EVENT:
|
||||
event = EVENT_GROUP_OFF
|
||||
if name == ON_FAST_EVENT:
|
||||
elif name == ON_FAST_EVENT:
|
||||
event = EVENT_GROUP_ON_FAST
|
||||
if name == OFF_FAST_EVENT:
|
||||
elif name == OFF_FAST_EVENT:
|
||||
event = EVENT_GROUP_OFF_FAST
|
||||
else:
|
||||
event = f"insteon.{name}"
|
||||
_LOGGER.debug("Firing event %s with %s", event, schema)
|
||||
hass.bus.async_fire(event, schema)
|
||||
|
||||
for group in device.events:
|
||||
if isinstance(group, int):
|
||||
for event in device.events[group]:
|
||||
if event in [
|
||||
OFF_EVENT,
|
||||
ON_EVENT,
|
||||
OFF_FAST_EVENT,
|
||||
ON_FAST_EVENT,
|
||||
]:
|
||||
_LOGGER.debug(
|
||||
"Registering on/off event for %s %d %s",
|
||||
str(device.address),
|
||||
group,
|
||||
event,
|
||||
)
|
||||
device.events[group][event].subscribe(
|
||||
async_fire_group_on_off_event, force_strong_ref=True
|
||||
)
|
||||
for name_or_group, event in device.events.items():
|
||||
if isinstance(name_or_group, int):
|
||||
for _, event in device.events[name_or_group].items():
|
||||
_register_event(event, async_fire_group_on_off_event)
|
||||
else:
|
||||
_register_event(event, async_fire_group_on_off_event)
|
||||
|
||||
|
||||
def register_new_device_callback(hass):
|
||||
|
|
|
@ -979,7 +979,7 @@ influxdb==5.3.1
|
|||
inkbird-ble==0.5.6
|
||||
|
||||
# homeassistant.components.insteon
|
||||
insteon-frontend-home-assistant==0.3.2
|
||||
insteon-frontend-home-assistant==0.3.3
|
||||
|
||||
# homeassistant.components.intellifire
|
||||
intellifire4py==2.2.2
|
||||
|
@ -1687,7 +1687,7 @@ pyialarm==2.2.0
|
|||
pyicloud==1.0.0
|
||||
|
||||
# homeassistant.components.insteon
|
||||
pyinsteon==1.3.3
|
||||
pyinsteon==1.3.4
|
||||
|
||||
# homeassistant.components.intesishome
|
||||
pyintesishome==1.8.0
|
||||
|
|
|
@ -738,7 +738,7 @@ influxdb==5.3.1
|
|||
inkbird-ble==0.5.6
|
||||
|
||||
# homeassistant.components.insteon
|
||||
insteon-frontend-home-assistant==0.3.2
|
||||
insteon-frontend-home-assistant==0.3.3
|
||||
|
||||
# homeassistant.components.intellifire
|
||||
intellifire4py==2.2.2
|
||||
|
@ -1212,7 +1212,7 @@ pyialarm==2.2.0
|
|||
pyicloud==1.0.0
|
||||
|
||||
# homeassistant.components.insteon
|
||||
pyinsteon==1.3.3
|
||||
pyinsteon==1.3.4
|
||||
|
||||
# homeassistant.components.ipma
|
||||
pyipma==3.0.6
|
||||
|
|
Loading…
Reference in New Issue