mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Add switch platform to eheimdigital (#142412)
* Add switch platform to eheimdigital * docstring fixes * Review * Review --------- Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
105
tests/components/eheimdigital/test_switch.py
Normal file
105
tests/components/eheimdigital/test_switch.py
Normal file
@@ -0,0 +1,105 @@
|
||||
"""Tests for the switch module."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from eheimdigital.types import EheimDeviceType
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import init_integration
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("classic_vario_mock")
|
||||
async def test_setup_classic_vario(
|
||||
hass: HomeAssistant,
|
||||
eheimdigital_hub_mock: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test switch platform setup for the filter."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
with (
|
||||
patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.SWITCH]),
|
||||
patch(
|
||||
"homeassistant.components.eheimdigital.coordinator.asyncio.Event",
|
||||
new=AsyncMock,
|
||||
),
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
|
||||
await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"](
|
||||
"00:00:00:00:00:03", EheimDeviceType.VERSION_EHEIM_CLASSIC_VARIO
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "active"), [(SERVICE_TURN_OFF, False), (SERVICE_TURN_ON, True)]
|
||||
)
|
||||
async def test_turn_on_off(
|
||||
hass: HomeAssistant,
|
||||
eheimdigital_hub_mock: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
classic_vario_mock: MagicMock,
|
||||
service: str,
|
||||
active: bool,
|
||||
) -> None:
|
||||
"""Test turning on/off the switch."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"](
|
||||
"00:00:00:00:00:03", EheimDeviceType.VERSION_EHEIM_CLASSIC_VARIO
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: "switch.mock_classicvario"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
classic_vario_mock.set_active.assert_awaited_once_with(active=active)
|
||||
|
||||
|
||||
async def test_state_update(
|
||||
hass: HomeAssistant,
|
||||
eheimdigital_hub_mock: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
classic_vario_mock: MagicMock,
|
||||
) -> None:
|
||||
"""Test the switch state update."""
|
||||
await init_integration(hass, mock_config_entry)
|
||||
|
||||
await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"](
|
||||
"00:00:00:00:00:03", EheimDeviceType.VERSION_EHEIM_CLASSIC_VARIO
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (state := hass.states.get("switch.mock_classicvario"))
|
||||
assert state.state == STATE_ON
|
||||
|
||||
classic_vario_mock.is_active = False
|
||||
|
||||
await eheimdigital_hub_mock.call_args.kwargs["receive_callback"]()
|
||||
|
||||
assert (state := hass.states.get("switch.mock_classicvario"))
|
||||
assert state.state == STATE_OFF
|
||||
Reference in New Issue
Block a user