Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def async_add_sensor(sensors):
):
entities.append(DeconzBinarySensor(sensor, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def async_add_climate(sensors):
):
entities.append(DeconzThermostat(sensor, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def async_add_cover(lights):
):
entities.append(DeconzCover(light, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/deconz/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def async_add_light(lights):
):
entities.append(DeconzLight(light, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand All @@ -77,7 +78,8 @@ def async_add_group(groups):
if new_group.unique_id not in known_groups:
entities.append(new_group)

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def async_add_scene(scenes):
"""Add scene from deCONZ."""
entities = [DeconzScene(scene, gateway) for scene in scenes]

async_add_entities(entities)
if entities:
async_add_entities(entities)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ def async_add_sensor(sensors):
):
entities.append(DeconzSensor(sensor, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/deconz/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def async_add_switch(lights):
):
entities.append(DeconzSiren(light, gateway))

async_add_entities(entities, True)
if entities:
async_add_entities(entities, True)

gateway.listeners.append(
async_dispatcher_connect(
Expand Down
62 changes: 18 additions & 44 deletions tests/components/deconz/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ async def test_platform_manually_configured(hass):

async def test_no_binary_sensors(hass):
"""Test that no sensors in deconz results in no sensor entities."""
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 0
await setup_deconz_integration(hass)
assert len(hass.states.async_all()) == 0


Expand All @@ -76,22 +75,13 @@ async def test_binary_sensors(hass):
data = deepcopy(DECONZ_WEB_REQUEST)
data["sensors"] = deepcopy(SENSORS)
gateway = await setup_deconz_integration(hass, get_state_response=data)
Comment thread
Kane610 marked this conversation as resolved.
assert "binary_sensor.presence_sensor" in gateway.deconz_ids
assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids
assert "binary_sensor.clip_presence_sensor" not in gateway.deconz_ids
assert "binary_sensor.vibration_sensor" in gateway.deconz_ids
assert len(hass.states.async_all()) == 3

assert len(hass.states.async_all()) == 3
presence_sensor = hass.states.get("binary_sensor.presence_sensor")
assert presence_sensor.state == "off"
assert presence_sensor.attributes["device_class"] == DEVICE_CLASS_MOTION

temperature_sensor = hass.states.get("binary_sensor.temperature_sensor")
assert temperature_sensor is None

clip_presence_sensor = hass.states.get("binary_sensor.clip_presence_sensor")
assert clip_presence_sensor is None

assert hass.states.get("binary_sensor.temperature_sensor") is None
assert hass.states.get("binary_sensor.clip_presence_sensor") is None
vibration_sensor = hass.states.get("binary_sensor.vibration_sensor")
assert vibration_sensor.state == "on"
assert vibration_sensor.attributes["device_class"] == DEVICE_CLASS_VIBRATION
Expand All @@ -106,8 +96,7 @@ async def test_binary_sensors(hass):
gateway.api.event_handler(state_changed_event)
Comment thread
Kane610 marked this conversation as resolved.
await hass.async_block_till_done()

presence_sensor = hass.states.get("binary_sensor.presence_sensor")
assert presence_sensor.state == "on"
assert hass.states.get("binary_sensor.presence_sensor").state == "on"

await gateway.async_reset()
Comment thread
Kane610 marked this conversation as resolved.

Expand All @@ -123,51 +112,38 @@ async def test_allow_clip_sensor(hass):
options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True},
get_state_response=data,
)
assert "binary_sensor.presence_sensor" in gateway.deconz_ids
assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids
assert "binary_sensor.clip_presence_sensor" in gateway.deconz_ids
assert "binary_sensor.vibration_sensor" in gateway.deconz_ids
assert len(hass.states.async_all()) == 4

presence_sensor = hass.states.get("binary_sensor.presence_sensor")
assert presence_sensor.state == "off"

temperature_sensor = hass.states.get("binary_sensor.temperature_sensor")
assert temperature_sensor is None

clip_presence_sensor = hass.states.get("binary_sensor.clip_presence_sensor")
assert clip_presence_sensor.state == "off"
assert len(hass.states.async_all()) == 4
assert hass.states.get("binary_sensor.presence_sensor").state == "off"
assert hass.states.get("binary_sensor.temperature_sensor") is None
assert hass.states.get("binary_sensor.clip_presence_sensor").state == "off"
assert hass.states.get("binary_sensor.vibration_sensor").state == "on"

vibration_sensor = hass.states.get("binary_sensor.vibration_sensor")
assert vibration_sensor.state == "on"
# Disallow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: False}
)
await hass.async_block_till_done()

assert "binary_sensor.presence_sensor" in gateway.deconz_ids
assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids
assert "binary_sensor.clip_presence_sensor" not in gateway.deconz_ids
assert "binary_sensor.vibration_sensor" in gateway.deconz_ids
assert len(hass.states.async_all()) == 3
assert hass.states.get("binary_sensor.clip_presence_sensor") is None

# Allow clip sensors

hass.config_entries.async_update_entry(
gateway.config_entry, options={deconz.gateway.CONF_ALLOW_CLIP_SENSOR: True}
)
await hass.async_block_till_done()

assert "binary_sensor.presence_sensor" in gateway.deconz_ids
assert "binary_sensor.temperature_sensor" not in gateway.deconz_ids
assert "binary_sensor.clip_presence_sensor" in gateway.deconz_ids
assert "binary_sensor.vibration_sensor" in gateway.deconz_ids
assert len(hass.states.async_all()) == 4
assert hass.states.get("binary_sensor.clip_presence_sensor").state == "off"


async def test_add_new_binary_sensor(hass):
"""Test that adding a new binary sensor works."""
gateway = await setup_deconz_integration(hass)
assert len(gateway.deconz_ids) == 0
assert len(hass.states.async_all()) == 0

state_added_event = {
"t": "event",
Expand All @@ -179,10 +155,8 @@ async def test_add_new_binary_sensor(hass):
gateway.api.event_handler(state_added_event)
await hass.async_block_till_done()

assert "binary_sensor.presence_sensor" in gateway.deconz_ids

presence_sensor = hass.states.get("binary_sensor.presence_sensor")
assert presence_sensor.state == "off"
assert len(hass.states.async_all()) == 1
assert hass.states.get("binary_sensor.presence_sensor").state == "off"


async def test_add_new_binary_sensor_ignored(hass):
Expand Down
Loading