1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-20 02:48:57 +00:00
Files
core/tests/components/actron_air/test_switch.py
2025-12-18 19:11:39 +01:00

91 lines
2.8 KiB
Python

"""Tests for the Actron Air switch platform."""
from unittest.mock import MagicMock, patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
async def test_switch_entities(
hass: HomeAssistant,
mock_actron_api: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test switch entities."""
with patch("homeassistant.components.actron_air.PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, mock_config_entry)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize(
("entity_id", "method"),
[
("switch.test_system_away_mode", "set_away_mode"),
("switch.test_system_continuous_fan", "set_continuous_mode"),
("switch.test_system_quiet_mode", "set_quiet_mode"),
("switch.test_system_turbo_mode", "set_turbo_mode"),
],
)
async def test_switch_toggles(
hass: HomeAssistant,
mock_actron_api: MagicMock,
mock_config_entry: MockConfigEntry,
entity_id: str,
method: str,
) -> None:
"""Test switch toggles."""
with patch("homeassistant.components.actron_air.PLATFORMS", [Platform.SWITCH]):
await setup_integration(hass, mock_config_entry)
status = mock_actron_api.state_manager.get_status.return_value
mock_method = getattr(status.user_aircon_settings, method)
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: [entity_id]},
blocking=True,
)
mock_method.assert_awaited_once_with(True)
mock_method.reset_mock()
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: [entity_id]},
blocking=True,
)
mock_method.assert_awaited_once_with(False)
async def test_turbo_mode_not_supported(
hass: HomeAssistant,
mock_actron_api: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test turbo mode switch is not created when not supported."""
status = mock_actron_api.state_manager.get_status.return_value
status.user_aircon_settings.turbo_supported = False
await setup_integration(hass, mock_config_entry)
entity_id = "switch.test_system_turbo_mode"
assert not hass.states.get(entity_id)
assert not entity_registry.async_get(entity_id)