Skip to content

Commit 5ea6cb3

Browse files
MartinHjelmarefrenck
authored andcommitted
Disable Z-Wave indidator CC entities by default (home-assistant#147018)
* Update discovery tests * Disable Z-Wave indidator CC entities by default
1 parent 912c480 commit 5ea6cb3

File tree

2 files changed

+69
-52
lines changed

2 files changed

+69
-52
lines changed

homeassistant/components/zwave_js/discovery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ class ZWaveDiscoverySchema:
896896
writeable=False,
897897
),
898898
entity_category=EntityCategory.DIAGNOSTIC,
899+
entity_registry_enabled_default=False,
899900
),
900901
# generic text sensors
901902
ZWaveDiscoverySchema(
@@ -932,6 +933,7 @@ class ZWaveDiscoverySchema:
932933
),
933934
data_template=NumericSensorDataTemplate(),
934935
entity_category=EntityCategory.DIAGNOSTIC,
936+
entity_registry_enabled_default=False,
935937
),
936938
# Meter sensors for Meter CC
937939
ZWaveDiscoverySchema(
@@ -957,6 +959,7 @@ class ZWaveDiscoverySchema:
957959
writeable=True,
958960
),
959961
entity_category=EntityCategory.CONFIG,
962+
entity_registry_enabled_default=False,
960963
),
961964
# button for Indicator CC
962965
ZWaveDiscoverySchema(
@@ -980,6 +983,7 @@ class ZWaveDiscoverySchema:
980983
writeable=True,
981984
),
982985
entity_category=EntityCategory.CONFIG,
986+
entity_registry_enabled_default=False,
983987
),
984988
# binary switch
985989
# barrier operator signaling states

tests/components/zwave_js/test_discovery.py

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""Test entity discovery for device-specific schemas for the Z-Wave JS integration."""
22

3+
from datetime import timedelta
4+
from unittest.mock import MagicMock
5+
36
import pytest
47
from zwave_js_server.event import Event
58
from zwave_js_server.model.node import Node
69

7-
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
810
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
911
from homeassistant.components.light import ATTR_SUPPORTED_COLOR_MODES, ColorMode
1012
from homeassistant.components.number import (
1113
ATTR_VALUE,
1214
DOMAIN as NUMBER_DOMAIN,
1315
SERVICE_SET_VALUE,
1416
)
15-
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
1617
from homeassistant.components.switch import (
1718
DOMAIN as SWITCH_DOMAIN,
1819
SERVICE_TURN_OFF,
@@ -26,12 +27,13 @@
2627
from homeassistant.components.zwave_js.discovery_data_template import (
2728
DynamicCurrentTempClimateDataTemplate,
2829
)
29-
from homeassistant.components.zwave_js.helpers import get_device_id
30+
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
3031
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_UNKNOWN, EntityCategory
3132
from homeassistant.core import HomeAssistant
3233
from homeassistant.helpers import device_registry as dr, entity_registry as er
34+
from homeassistant.util import dt as dt_util
3335

34-
from tests.common import MockConfigEntry
36+
from tests.common import MockConfigEntry, async_fire_time_changed
3537

3638

3739
async def test_aeon_smart_switch_6_state(
@@ -222,17 +224,24 @@ async def test_merten_507801_disabled_enitites(
222224
async def test_zooz_zen72(
223225
hass: HomeAssistant,
224226
entity_registry: er.EntityRegistry,
225-
client,
226-
switch_zooz_zen72,
227-
integration,
227+
client: MagicMock,
228+
switch_zooz_zen72: Node,
229+
integration: MockConfigEntry,
228230
) -> None:
229231
"""Test that Zooz ZEN72 Indicators are discovered as number entities."""
230-
assert len(hass.states.async_entity_ids(NUMBER_DOMAIN)) == 1
231-
assert len(hass.states.async_entity_ids(BUTTON_DOMAIN)) == 2 # includes ping
232232
entity_id = "number.z_wave_plus_700_series_dimmer_switch_indicator_value"
233-
entry = entity_registry.async_get(entity_id)
234-
assert entry
235-
assert entry.entity_category == EntityCategory.CONFIG
233+
entity_entry = entity_registry.async_get(entity_id)
234+
assert entity_entry
235+
assert entity_entry.entity_category == EntityCategory.CONFIG
236+
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
237+
assert hass.states.get(entity_id) is None # disabled by default
238+
entity_registry.async_update_entity(entity_id, disabled_by=None)
239+
async_fire_time_changed(
240+
hass,
241+
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
242+
)
243+
await hass.async_block_till_done()
244+
client.async_send_command.reset_mock()
236245
state = hass.states.get(entity_id)
237246
assert state
238247
assert state.state == STATE_UNKNOWN
@@ -246,7 +255,7 @@ async def test_zooz_zen72(
246255
},
247256
blocking=True,
248257
)
249-
assert len(client.async_send_command.call_args_list) == 1
258+
assert client.async_send_command.call_count == 1
250259
args = client.async_send_command.call_args[0][0]
251260
assert args["command"] == "node.set_value"
252261
assert args["nodeId"] == switch_zooz_zen72.node_id
@@ -260,16 +269,18 @@ async def test_zooz_zen72(
260269
client.async_send_command.reset_mock()
261270

262271
entity_id = "button.z_wave_plus_700_series_dimmer_switch_identify"
263-
entry = entity_registry.async_get(entity_id)
264-
assert entry
265-
assert entry.entity_category == EntityCategory.CONFIG
272+
entity_entry = entity_registry.async_get(entity_id)
273+
assert entity_entry
274+
assert entity_entry.entity_category == EntityCategory.CONFIG
275+
assert entity_entry.disabled_by is None
276+
assert hass.states.get(entity_id) is not None
266277
await hass.services.async_call(
267278
BUTTON_DOMAIN,
268279
SERVICE_PRESS,
269280
{ATTR_ENTITY_ID: entity_id},
270281
blocking=True,
271282
)
272-
assert len(client.async_send_command.call_args_list) == 1
283+
assert client.async_send_command.call_count == 1
273284
args = client.async_send_command.call_args[0][0]
274285
assert args["command"] == "node.set_value"
275286
assert args["nodeId"] == switch_zooz_zen72.node_id
@@ -285,53 +296,55 @@ async def test_indicator_test(
285296
hass: HomeAssistant,
286297
device_registry: dr.DeviceRegistry,
287298
entity_registry: er.EntityRegistry,
288-
client,
289-
indicator_test,
290-
integration,
299+
client: MagicMock,
300+
indicator_test: Node,
301+
integration: MockConfigEntry,
291302
) -> None:
292303
"""Test that Indicators are discovered properly.
293304
294305
This test covers indicators that we don't already have device fixtures for.
295306
"""
296-
device = device_registry.async_get_device(
297-
identifiers={get_device_id(client.driver, indicator_test)}
307+
binary_sensor_entity_id = "binary_sensor.this_is_a_fake_device_binary_sensor"
308+
sensor_entity_id = "sensor.this_is_a_fake_device_sensor"
309+
switch_entity_id = "switch.this_is_a_fake_device_switch"
310+
311+
for entity_id in (
312+
binary_sensor_entity_id,
313+
sensor_entity_id,
314+
):
315+
entity_entry = entity_registry.async_get(entity_id)
316+
assert entity_entry
317+
assert entity_entry.entity_category == EntityCategory.DIAGNOSTIC
318+
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
319+
assert hass.states.get(entity_id) is None # disabled by default
320+
entity_registry.async_update_entity(entity_id, disabled_by=None)
321+
322+
entity_id = switch_entity_id
323+
entity_entry = entity_registry.async_get(entity_id)
324+
assert entity_entry
325+
assert entity_entry.entity_category == EntityCategory.CONFIG
326+
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
327+
assert hass.states.get(entity_id) is None # disabled by default
328+
entity_registry.async_update_entity(entity_id, disabled_by=None)
329+
330+
async_fire_time_changed(
331+
hass,
332+
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
298333
)
299-
assert device
300-
entities = er.async_entries_for_device(entity_registry, device.id)
301-
302-
def len_domain(domain):
303-
return len([entity for entity in entities if entity.domain == domain])
304-
305-
assert len_domain(NUMBER_DOMAIN) == 0
306-
assert len_domain(BUTTON_DOMAIN) == 1 # only ping
307-
assert len_domain(BINARY_SENSOR_DOMAIN) == 1
308-
assert len_domain(SENSOR_DOMAIN) == 3 # include node status + last seen
309-
assert len_domain(SWITCH_DOMAIN) == 1
310-
311-
entity_id = "binary_sensor.this_is_a_fake_device_binary_sensor"
312-
entry = entity_registry.async_get(entity_id)
313-
assert entry
314-
assert entry.entity_category == EntityCategory.DIAGNOSTIC
334+
await hass.async_block_till_done()
335+
client.async_send_command.reset_mock()
336+
337+
entity_id = binary_sensor_entity_id
315338
state = hass.states.get(entity_id)
316339
assert state
317340
assert state.state == STATE_OFF
318341

319-
client.async_send_command.reset_mock()
320-
321-
entity_id = "sensor.this_is_a_fake_device_sensor"
322-
entry = entity_registry.async_get(entity_id)
323-
assert entry
324-
assert entry.entity_category == EntityCategory.DIAGNOSTIC
342+
entity_id = sensor_entity_id
325343
state = hass.states.get(entity_id)
326344
assert state
327345
assert state.state == "0.0"
328346

329-
client.async_send_command.reset_mock()
330-
331-
entity_id = "switch.this_is_a_fake_device_switch"
332-
entry = entity_registry.async_get(entity_id)
333-
assert entry
334-
assert entry.entity_category == EntityCategory.CONFIG
347+
entity_id = switch_entity_id
335348
state = hass.states.get(entity_id)
336349
assert state
337350
assert state.state == STATE_OFF
@@ -342,7 +355,7 @@ def len_domain(domain):
342355
{ATTR_ENTITY_ID: entity_id},
343356
blocking=True,
344357
)
345-
assert len(client.async_send_command.call_args_list) == 1
358+
assert client.async_send_command.call_count == 1
346359
args = client.async_send_command.call_args[0][0]
347360
assert args["command"] == "node.set_value"
348361
assert args["nodeId"] == indicator_test.node_id
@@ -362,7 +375,7 @@ def len_domain(domain):
362375
{ATTR_ENTITY_ID: entity_id},
363376
blocking=True,
364377
)
365-
assert len(client.async_send_command.call_args_list) == 1
378+
assert client.async_send_command.call_count == 1
366379
args = client.async_send_command.call_args[0][0]
367380
assert args["command"] == "node.set_value"
368381
assert args["nodeId"] == indicator_test.node_id

0 commit comments

Comments
 (0)