Disable Z-Wave idle notification button (#147026)

* Update test

* Disable Z-Wave idle notification button

* Update tests
This commit is contained in:
Martin Hjelmare 2025-06-18 07:29:04 +02:00 committed by Franck Nijhof
parent 766ddfaacc
commit 96d6cacae4
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
4 changed files with 42 additions and 20 deletions

View File

@ -1188,6 +1188,7 @@ DISCOVERY_SCHEMAS = [
any_available_states={(0, "idle")}, any_available_states={(0, "idle")},
), ),
allow_multi=True, allow_multi=True,
entity_registry_enabled_default=False,
), ),
# event # event
# stateful = False # stateful = False

View File

@ -97,8 +97,8 @@
'value_id': '52-113-0-Home Security-Cover status', 'value_id': '52-113-0-Home Security-Cover status',
}), }),
dict({ dict({
'disabled': False, 'disabled': True,
'disabled_by': None, 'disabled_by': 'integration',
'domain': 'button', 'domain': 'button',
'entity_category': 'config', 'entity_category': 'config',
'entity_id': 'button.multisensor_6_idle_home_security_cover_status', 'entity_id': 'button.multisensor_6_idle_home_security_cover_status',
@ -120,8 +120,8 @@
'value_id': '52-113-0-Home Security-Cover status', 'value_id': '52-113-0-Home Security-Cover status',
}), }),
dict({ dict({
'disabled': False, 'disabled': True,
'disabled_by': None, 'disabled_by': 'integration',
'domain': 'button', 'domain': 'button',
'entity_category': 'config', 'entity_category': 'config',
'entity_id': 'button.multisensor_6_idle_home_security_motion_sensor_status', 'entity_id': 'button.multisensor_6_idle_home_security_motion_sensor_status',

View File

@ -1,13 +1,21 @@
"""Test the Z-Wave JS button entities.""" """Test the Z-Wave JS button entities."""
from datetime import timedelta
from unittest.mock import MagicMock
import pytest import pytest
from zwave_js_server.model.node import Node
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.components.zwave_js.const import DOMAIN, SERVICE_REFRESH_VALUE from homeassistant.components.zwave_js.const import DOMAIN, SERVICE_REFRESH_VALUE
from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_id from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_id
from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
from homeassistant.const import ATTR_ENTITY_ID, EntityCategory, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed
@pytest.fixture @pytest.fixture
@ -71,11 +79,32 @@ async def test_ping_entity(
async def test_notification_idle_button( async def test_notification_idle_button(
hass: HomeAssistant, client, multisensor_6, integration hass: HomeAssistant,
entity_registry: er.EntityRegistry,
client: MagicMock,
multisensor_6: Node,
integration: MockConfigEntry,
) -> None: ) -> None:
"""Test Notification idle button.""" """Test Notification idle button."""
node = multisensor_6 node = multisensor_6
state = hass.states.get("button.multisensor_6_idle_home_security_cover_status") entity_id = "button.multisensor_6_idle_home_security_cover_status"
entity_entry = entity_registry.async_get(entity_id)
assert entity_entry
assert entity_entry.entity_category is EntityCategory.CONFIG
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
assert hass.states.get(entity_id) is None # disabled by default
entity_registry.async_update_entity(
entity_id,
disabled_by=None,
)
async_fire_time_changed(
hass,
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state assert state
assert state.state == "unknown" assert state.state == "unknown"
assert ( assert (
@ -88,13 +117,13 @@ async def test_notification_idle_button(
BUTTON_DOMAIN, BUTTON_DOMAIN,
SERVICE_PRESS, SERVICE_PRESS,
{ {
ATTR_ENTITY_ID: "button.multisensor_6_idle_home_security_cover_status", ATTR_ENTITY_ID: entity_id,
}, },
blocking=True, blocking=True,
) )
assert len(client.async_send_command_no_wait.call_args_list) == 1 assert client.async_send_command_no_wait.call_count == 1
args = client.async_send_command_no_wait.call_args_list[0][0][0] args = client.async_send_command_no_wait.call_args[0][0]
assert args["command"] == "node.manually_idle_notification_value" assert args["command"] == "node.manually_idle_notification_value"
assert args["nodeId"] == node.node_id assert args["nodeId"] == node.node_id
assert args["valueId"] == { assert args["valueId"] == {

View File

@ -1812,7 +1812,8 @@ async def test_disabled_node_status_entity_on_node_replaced(
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
async def test_disabled_entity_on_value_removed( @pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_remove_entity_on_value_removed(
hass: HomeAssistant, hass: HomeAssistant,
zp3111: Node, zp3111: Node,
client: MagicMock, client: MagicMock,
@ -1823,15 +1824,6 @@ async def test_disabled_entity_on_value_removed(
"button.4_in_1_sensor_idle_home_security_cover_status" "button.4_in_1_sensor_idle_home_security_cover_status"
) )
# must reload the integration when enabling an entity
await hass.config_entries.async_unload(integration.entry_id)
await hass.async_block_till_done()
assert integration.state is ConfigEntryState.NOT_LOADED
integration.add_to_hass(hass)
await hass.config_entries.async_setup(integration.entry_id)
await hass.async_block_till_done()
assert integration.state is ConfigEntryState.LOADED
state = hass.states.get(idle_cover_status_button_entity) state = hass.states.get(idle_cover_status_button_entity)
assert state assert state
assert state.state != STATE_UNAVAILABLE assert state.state != STATE_UNAVAILABLE