Allow patching Z-Wave platforms specifically in tests (#140987)

This commit is contained in:
Martin Hjelmare 2025-03-20 12:19:14 +01:00 committed by GitHub
parent a20601a1f0
commit d8a4a97ee0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -13,7 +13,9 @@ from zwave_js_server.model.node import Node
from zwave_js_server.model.node.data_model import NodeDataType from zwave_js_server.model.node.data_model import NodeDataType
from zwave_js_server.version import VersionInfo from zwave_js_server.version import VersionInfo
from homeassistant.components.zwave_js import PLATFORMS
from homeassistant.components.zwave_js.const import DOMAIN from homeassistant.components.zwave_js.const import DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.util.json import JsonArrayType from homeassistant.util.json import JsonArrayType
@ -828,10 +830,12 @@ def nortek_thermostat_removed_event_fixture(client) -> Node:
async def integration_fixture( async def integration_fixture(
hass: HomeAssistant, hass: HomeAssistant,
client: MagicMock, client: MagicMock,
platforms: list[Platform],
) -> MockConfigEntry: ) -> MockConfigEntry:
"""Set up the zwave_js integration.""" """Set up the zwave_js integration."""
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"}) entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"})
entry.add_to_hass(hass) entry.add_to_hass(hass)
with patch("homeassistant.components.zwave_js.PLATFORMS", platforms):
await hass.config_entries.async_setup(entry.entry_id) await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -840,6 +844,12 @@ async def integration_fixture(
return entry return entry
@pytest.fixture
def platforms() -> list[Platform]:
"""Fixture to specify platforms to test."""
return PLATFORMS
@pytest.fixture(name="chain_actuator_zws12") @pytest.fixture(name="chain_actuator_zws12")
def window_cover_fixture(client, chain_actuator_zws12_state) -> Node: def window_cover_fixture(client, chain_actuator_zws12_state) -> Node:
"""Mock a window cover node.""" """Mock a window cover node."""

View File

@ -1,5 +1,6 @@
"""Test the Z-Wave JS siren platform.""" """Test the Z-Wave JS siren platform."""
import pytest
from zwave_js_server.event import Event from zwave_js_server.event import Event
from homeassistant.components.siren import ( from homeassistant.components.siren import (
@ -7,7 +8,7 @@ from homeassistant.components.siren import (
ATTR_TONE, ATTR_TONE,
ATTR_VOLUME_LEVEL, ATTR_VOLUME_LEVEL,
) )
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
SIREN_ENTITY = "siren.indoor_siren_6_play_tone_2" SIREN_ENTITY = "siren.indoor_siren_6_play_tone_2"
@ -64,6 +65,12 @@ TONE_ID_VALUE_ID = {
} }
@pytest.fixture
def platforms() -> list[str]:
"""Fixture to specify platforms to test."""
return [Platform.SIREN]
async def test_siren( async def test_siren(
hass: HomeAssistant, client, aeotec_zw164_siren, integration hass: HomeAssistant, client, aeotec_zw164_siren, integration
) -> None: ) -> None: