mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Limit shelly tests to single platform (#153681)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
"""Tests for the Shelly integration."""
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from contextlib import contextmanager
|
||||
from copy import deepcopy
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from aioshelly.const import MODEL_25
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
@@ -12,6 +13,11 @@ import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.components.shelly import (
|
||||
BLOCK_SLEEPING_PLATFORMS,
|
||||
PLATFORMS,
|
||||
RPC_SLEEPING_PLATFORMS,
|
||||
)
|
||||
from homeassistant.components.shelly.const import (
|
||||
CONF_GEN,
|
||||
CONF_SLEEP_PERIOD,
|
||||
@@ -20,7 +26,7 @@ from homeassistant.components.shelly.const import (
|
||||
RPC_SENSORS_POLLING_INTERVAL,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_MODEL
|
||||
from homeassistant.const import CONF_HOST, CONF_MODEL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.device_registry import (
|
||||
@@ -204,3 +210,23 @@ async def force_uptime_value(
|
||||
"""Force time to a specific point."""
|
||||
await hass.config.async_set_time_zone("UTC")
|
||||
freezer.move_to("2025-05-26 16:04:00+00:00")
|
||||
|
||||
|
||||
@contextmanager
|
||||
def patch_platforms(platforms: list[Platform]):
|
||||
"""Only allow given platforms to be loaded."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.shelly.PLATFORMS",
|
||||
list(set(PLATFORMS) & set(platforms)),
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.shelly.BLOCK_SLEEPING_PLATFORMS",
|
||||
list(set(BLOCK_SLEEPING_PLATFORMS) & set(platforms)),
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.shelly.RPC_SLEEPING_PLATFORMS",
|
||||
list(set(RPC_SLEEPING_PLATFORMS) & set(platforms)),
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
@@ -10,7 +10,13 @@ from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.shelly.const import UPDATE_PERIOD_MULTIPLIER
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
@@ -19,6 +25,7 @@ from . import (
|
||||
init_integration,
|
||||
mock_rest_update,
|
||||
mutate_rpc_device_status,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
register_sub_device,
|
||||
@@ -30,6 +37,13 @@ RELAY_BLOCK_ID = 0
|
||||
SENSOR_BLOCK_ID = 3
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.BINARY_SENSOR]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -11,13 +11,20 @@ from syrupy.assertion import SnapshotAssertion
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.components.shelly.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, register_device, register_entity
|
||||
from . import init_integration, patch_platforms, register_device, register_entity
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.BUTTON]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_button(
|
||||
|
||||
@@ -35,6 +35,7 @@ from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
@@ -43,7 +44,13 @@ from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import MOCK_MAC, init_integration, register_device, register_entity
|
||||
from . import (
|
||||
MOCK_MAC,
|
||||
init_integration,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
)
|
||||
from .conftest import MOCK_STATUS_COAP
|
||||
|
||||
from tests.common import mock_restore_cache, mock_restore_cache_with_extra_data
|
||||
@@ -55,6 +62,13 @@ GAS_VALVE_BLOCK_ID = 6
|
||||
ENTITY_ID = f"{CLIMATE_DOMAIN}.test_name"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.CLIMATE, Platform.SWITCH]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_climate_hvac_mode(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -23,15 +23,27 @@ from homeassistant.components.cover import (
|
||||
CoverState,
|
||||
)
|
||||
from homeassistant.components.shelly.const import RPC_COVER_UPDATE_TIME_SEC
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, mock_polling_rpc_update, mutate_rpc_device_status
|
||||
from . import (
|
||||
init_integration,
|
||||
mock_polling_rpc_update,
|
||||
mutate_rpc_device_status,
|
||||
patch_platforms,
|
||||
)
|
||||
|
||||
ROLLER_BLOCK_ID = 1
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.COVER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_device_services(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -14,15 +14,27 @@ from homeassistant.components.event import (
|
||||
DOMAIN as EVENT_DOMAIN,
|
||||
EventDeviceClass,
|
||||
)
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, inject_rpc_device_event, register_entity
|
||||
from . import (
|
||||
init_integration,
|
||||
inject_rpc_device_event,
|
||||
patch_platforms,
|
||||
register_entity,
|
||||
)
|
||||
|
||||
DEVICE_BLOCK_ID = 4
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.EVENT]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_rpc_button(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
|
||||
@@ -38,6 +38,7 @@ from homeassistant.const import (
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
@@ -47,6 +48,7 @@ from . import (
|
||||
get_entity,
|
||||
init_integration,
|
||||
mutate_rpc_device_status,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
)
|
||||
@@ -57,6 +59,13 @@ LIGHT_BLOCK_ID = 2
|
||||
SHELLY_PLUS_RGBW_CHANNELS = 4
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.LIGHT]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_device_rgbw_bulb(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -20,19 +20,31 @@ from homeassistant.components.number import (
|
||||
)
|
||||
from homeassistant.components.shelly.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, STATE_UNKNOWN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, register_device, register_entity
|
||||
from . import init_integration, patch_platforms, register_device, register_entity
|
||||
|
||||
from tests.common import mock_restore_cache_with_extra_data
|
||||
|
||||
DEVICE_BLOCK_ID = 4
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.NUMBER]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_number_update(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -14,13 +14,20 @@ from homeassistant.components.select import (
|
||||
)
|
||||
from homeassistant.components.shelly.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, register_device, register_entity
|
||||
from . import init_integration, patch_platforms, register_device, register_entity
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.SELECT]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -28,6 +28,7 @@ from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
@@ -47,6 +48,7 @@ from . import (
|
||||
mock_polling_rpc_update,
|
||||
mock_rest_update,
|
||||
mutate_rpc_device_status,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
)
|
||||
@@ -58,6 +60,13 @@ SENSOR_BLOCK_ID = 3
|
||||
DEVICE_BLOCK_ID = 4
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.SENSOR]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_sensor(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
|
||||
@@ -25,6 +25,7 @@ from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -34,6 +35,7 @@ from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from . import (
|
||||
init_integration,
|
||||
inject_rpc_device_event,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
register_sub_device,
|
||||
@@ -48,6 +50,15 @@ GAS_VALVE_BLOCK_ID = 6
|
||||
MOTION_BLOCK_ID = 3
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms(
|
||||
[Platform.SWITCH, Platform.CLIMATE, Platform.VALVE, Platform.LIGHT]
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_device_services(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
|
||||
@@ -13,13 +13,20 @@ from homeassistant.components.text import (
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, register_device, register_entity
|
||||
from . import init_integration, patch_platforms, register_device, register_entity
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.TEXT]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -29,6 +29,7 @@ from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -39,6 +40,7 @@ from . import (
|
||||
init_integration,
|
||||
inject_rpc_device_event,
|
||||
mock_rest_update,
|
||||
patch_platforms,
|
||||
register_device,
|
||||
register_entity,
|
||||
)
|
||||
@@ -46,6 +48,13 @@ from . import (
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.UPDATE]):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_block_update(
|
||||
hass: HomeAssistant,
|
||||
|
||||
@@ -21,15 +21,23 @@ from homeassistant.const import (
|
||||
SERVICE_CLOSE_VALVE,
|
||||
SERVICE_OPEN_VALVE,
|
||||
SERVICE_SET_VALVE_POSITION,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration
|
||||
from . import init_integration, patch_platforms
|
||||
|
||||
GAS_VALVE_BLOCK_ID = 6
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fixture_platforms():
|
||||
"""Limit platforms under test."""
|
||||
with patch_platforms([Platform.VALVE]):
|
||||
yield
|
||||
|
||||
|
||||
async def test_block_device_gas_valve(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: EntityRegistry,
|
||||
|
||||
Reference in New Issue
Block a user