deCONZ - use entity registry disabled_by to control available entities (#26219)

* First draft

* Support enabling disabled entities

* Clean up

* Move import

* Local entity enabled replaced during rebase

* Add option flow test

* Mark options properties with option
This commit is contained in:
Robert Svensson 2019-09-06 01:38:00 +02:00 committed by Paulus Schoutsen
parent b1c2a5fa08
commit 518d2c31bb
19 changed files with 191 additions and 82 deletions

View file

@ -8,7 +8,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .const import ATTR_DARK, ATTR_ON, NEW_SENSOR
from .deconz_device import DeconzDevice
from .gateway import get_gateway_from_config_entry
from .gateway import get_gateway_from_config_entry, DeconzEntityHandler
ATTR_ORIENTATION = "orientation"
ATTR_TILTANGLE = "tiltangle"
@ -24,6 +24,8 @@ 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)
entity_handler = DeconzEntityHandler(gateway)
@callback
def async_add_sensor(sensors):
"""Add binary sensor from deCONZ."""
@ -31,17 +33,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
for sensor in sensors:
if sensor.BINARY and not (
not gateway.allow_clip_sensor and sensor.type.startswith("CLIP")
):
entities.append(DeconzBinarySensor(sensor, gateway))
if sensor.BINARY:
new_sensor = DeconzBinarySensor(sensor, gateway)
entity_handler.add_entity(new_sensor)
entities.append(new_sensor)
async_add_entities(entities, True)
gateway.listeners.append(
async_dispatcher_connect(
hass, gateway.async_event_new_device(NEW_SENSOR), async_add_sensor
hass, gateway.async_signal_new_device(NEW_SENSOR), async_add_sensor
)
)