Skip to content

Commit 96d6cac

Browse files
MartinHjelmarefrenck
authored andcommitted
Disable Z-Wave idle notification button (home-assistant#147026)
* Update test * Disable Z-Wave idle notification button * Update tests
1 parent 766ddfa commit 96d6cac

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

homeassistant/components/zwave_js/discovery.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ class ZWaveDiscoverySchema:
11881188
any_available_states={(0, "idle")},
11891189
),
11901190
allow_multi=True,
1191+
entity_registry_enabled_default=False,
11911192
),
11921193
# event
11931194
# stateful = False

tests/components/zwave_js/snapshots/test_diagnostics.ambr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@
9797
'value_id': '52-113-0-Home Security-Cover status',
9898
}),
9999
dict({
100-
'disabled': False,
101-
'disabled_by': None,
100+
'disabled': True,
101+
'disabled_by': 'integration',
102102
'domain': 'button',
103103
'entity_category': 'config',
104104
'entity_id': 'button.multisensor_6_idle_home_security_cover_status',
@@ -120,8 +120,8 @@
120120
'value_id': '52-113-0-Home Security-Cover status',
121121
}),
122122
dict({
123-
'disabled': False,
124-
'disabled_by': None,
123+
'disabled': True,
124+
'disabled_by': 'integration',
125125
'domain': 'button',
126126
'entity_category': 'config',
127127
'entity_id': 'button.multisensor_6_idle_home_security_motion_sensor_status',

tests/components/zwave_js/test_button.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
"""Test the Z-Wave JS button entities."""
22

3+
from datetime import timedelta
4+
from unittest.mock import MagicMock
5+
36
import pytest
7+
from zwave_js_server.model.node import Node
48

59
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
610
from homeassistant.components.zwave_js.const import DOMAIN, SERVICE_REFRESH_VALUE
711
from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_id
8-
from homeassistant.const import ATTR_ENTITY_ID, Platform
12+
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
13+
from homeassistant.const import ATTR_ENTITY_ID, EntityCategory, Platform
914
from homeassistant.core import HomeAssistant
1015
from homeassistant.helpers import entity_registry as er
16+
from homeassistant.util import dt as dt_util
17+
18+
from tests.common import MockConfigEntry, async_fire_time_changed
1119

1220

1321
@pytest.fixture
@@ -71,11 +79,32 @@ async def test_ping_entity(
7179

7280

7381
async def test_notification_idle_button(
74-
hass: HomeAssistant, client, multisensor_6, integration
82+
hass: HomeAssistant,
83+
entity_registry: er.EntityRegistry,
84+
client: MagicMock,
85+
multisensor_6: Node,
86+
integration: MockConfigEntry,
7587
) -> None:
7688
"""Test Notification idle button."""
7789
node = multisensor_6
78-
state = hass.states.get("button.multisensor_6_idle_home_security_cover_status")
90+
entity_id = "button.multisensor_6_idle_home_security_cover_status"
91+
entity_entry = entity_registry.async_get(entity_id)
92+
assert entity_entry
93+
assert entity_entry.entity_category is EntityCategory.CONFIG
94+
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
95+
assert hass.states.get(entity_id) is None # disabled by default
96+
97+
entity_registry.async_update_entity(
98+
entity_id,
99+
disabled_by=None,
100+
)
101+
async_fire_time_changed(
102+
hass,
103+
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
104+
)
105+
await hass.async_block_till_done()
106+
107+
state = hass.states.get(entity_id)
79108
assert state
80109
assert state.state == "unknown"
81110
assert (
@@ -88,13 +117,13 @@ async def test_notification_idle_button(
88117
BUTTON_DOMAIN,
89118
SERVICE_PRESS,
90119
{
91-
ATTR_ENTITY_ID: "button.multisensor_6_idle_home_security_cover_status",
120+
ATTR_ENTITY_ID: entity_id,
92121
},
93122
blocking=True,
94123
)
95124

96-
assert len(client.async_send_command_no_wait.call_args_list) == 1
97-
args = client.async_send_command_no_wait.call_args_list[0][0][0]
125+
assert client.async_send_command_no_wait.call_count == 1
126+
args = client.async_send_command_no_wait.call_args[0][0]
98127
assert args["command"] == "node.manually_idle_notification_value"
99128
assert args["nodeId"] == node.node_id
100129
assert args["valueId"] == {

tests/components/zwave_js/test_init.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,8 @@ async def test_disabled_node_status_entity_on_node_replaced(
18121812
assert state.state == STATE_UNAVAILABLE
18131813

18141814

1815-
async def test_disabled_entity_on_value_removed(
1815+
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
1816+
async def test_remove_entity_on_value_removed(
18161817
hass: HomeAssistant,
18171818
zp3111: Node,
18181819
client: MagicMock,
@@ -1823,15 +1824,6 @@ async def test_disabled_entity_on_value_removed(
18231824
"button.4_in_1_sensor_idle_home_security_cover_status"
18241825
)
18251826

1826-
# must reload the integration when enabling an entity
1827-
await hass.config_entries.async_unload(integration.entry_id)
1828-
await hass.async_block_till_done()
1829-
assert integration.state is ConfigEntryState.NOT_LOADED
1830-
integration.add_to_hass(hass)
1831-
await hass.config_entries.async_setup(integration.entry_id)
1832-
await hass.async_block_till_done()
1833-
assert integration.state is ConfigEntryState.LOADED
1834-
18351827
state = hass.states.get(idle_cover_status_button_entity)
18361828
assert state
18371829
assert state.state != STATE_UNAVAILABLE

0 commit comments

Comments
 (0)