mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 13:00:11 +00:00
Improve tracking of existing entities in deconz (#40265)
* Store all entities in dict * Use stored unique id to select if to create entity or not * Remove unnecessary init * Change so same physical sensor doesnt try to create multiple battery sensors Change so groups get created properly * Add controls in tests that entities are logged correctly
This commit is contained in:
@@ -8,6 +8,7 @@ from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_OPENING,
|
||||
DEVICE_CLASS_SMOKE,
|
||||
DEVICE_CLASS_VIBRATION,
|
||||
DOMAIN,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE
|
||||
@@ -39,17 +40,18 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the deCONZ binary sensor."""
|
||||
gateway = get_gateway_from_config_entry(hass, config_entry)
|
||||
gateway.entities[DOMAIN] = set()
|
||||
|
||||
@callback
|
||||
def async_add_sensor(sensors, new=True):
|
||||
def async_add_sensor(sensors):
|
||||
"""Add binary sensor from deCONZ."""
|
||||
entities = []
|
||||
|
||||
for sensor in sensors:
|
||||
|
||||
if (
|
||||
new
|
||||
and sensor.BINARY
|
||||
sensor.BINARY
|
||||
and sensor.uniqueid not in gateway.entities[DOMAIN]
|
||||
and (
|
||||
gateway.option_allow_clip_sensor
|
||||
or not sensor.type.startswith("CLIP")
|
||||
@@ -73,6 +75,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
|
||||
"""Representation of a deCONZ binary sensor."""
|
||||
|
||||
TYPE = DOMAIN
|
||||
|
||||
@callback
|
||||
def async_update_callback(self, force_update=False, ignore_update=False):
|
||||
"""Update the sensor's state."""
|
||||
|
||||
Reference in New Issue
Block a user