deCONZ - create deconz_events through sensor platform (#26592)
* Move event creation into sensor platform where it belongs * Fixed the weird failing test observed during device automation PR
This commit is contained in:
1 parent
357f2421c8
commit
fb1acfccc9
4 files changed
+70
-90
No files matched your search
@@ -3,7 +3,6 @@ import asyncio
|
||||
import async_timeout
|
||||
|
||||
from pydeconz import DeconzSession, errors
|
||||
from pydeconz.sensor import Switch
|
||||
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.const import CONF_HOST
|
||||
@@ -29,10 +28,9 @@ from .const import (
|
||||
DEFAULT_ALLOW_DECONZ_GROUPS,
|
||||
DOMAIN,
|
||||
NEW_DEVICE,
|
||||
NEW_SENSOR,
|
||||
SUPPORTED_PLATFORMS,
|
||||
)
|
||||
from .deconz_event import DeconzEvent
|
||||
|
||||
from .errors import AuthenticationRequired, CannotConnect
|
||||
|
||||
|
||||
@@ -119,14 +117,6 @@ class DeconzGateway:
|
||||
)
|
||||
)
|
||||
|
||||
self.listeners.append(
|
||||
async_dispatcher_connect(
|
||||
hass, self.async_signal_new_device(NEW_SENSOR), self.async_add_remote
|
||||
)
|
||||
)
|
||||
|
||||
self.async_add_remote(self.api.sensors.values())
|
||||
|
||||
self.api.start()
|
||||
|
||||
self.config_entry.add_update_listener(self.async_new_address)
|
||||
@@ -185,17 +175,6 @@ class DeconzGateway:
|
||||
self.hass, self.async_signal_new_device(device_type), device
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_add_remote(self, sensors):
|
||||
"""Set up remote from deCONZ."""
|
||||
for sensor in sensors:
|
||||
if sensor.type in Switch.ZHATYPE and not (
|
||||
not self.option_allow_clip_sensor and sensor.type.startswith("CLIP")
|
||||
):
|
||||
event = DeconzEvent(sensor, self)
|
||||
self.hass.async_create_task(event.async_update_device_registry())
|
||||
self.events.append(event)
|
||||
|
||||
@callback
|
||||
def shutdown(self, event):
|
||||
"""Wrap the call to deconz.close.
|
||||
|
||||
@@ -13,6 +13,7 @@ from homeassistant.util import slugify
|
||||
|
||||
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
|
||||
from .deconz_device import DeconzDevice
|
||||
from .deconz_event import DeconzEvent
|
||||
from .gateway import get_gateway_from_config_entry, DeconzEntityHandler
|
||||
|
||||
ATTR_CURRENT = "current"
|
||||
@@ -42,6 +43,14 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
if not sensor.BINARY:
|
||||
|
||||
if sensor.type in Switch.ZHATYPE:
|
||||
|
||||
if gateway.option_allow_clip_sensor or not sensor.type.startswith(
|
||||
"CLIP"
|
||||
):
|
||||
event = DeconzEvent(sensor, gateway)
|
||||
hass.async_create_task(event.async_update_device_registry())
|
||||
gateway.events.append(event)
|
||||
|
||||
if sensor.battery:
|
||||
entities.append(DeconzBattery(sensor, gateway))
|
||||
|
||||
|
||||
Reference in new issue
Block a user