2023-12-21 05:34:52 +00:00
|
|
|
"""Test the Tessie switch platform."""
|
2024-03-08 13:44:56 +00:00
|
|
|
|
2023-12-21 05:34:52 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
from syrupy import SnapshotAssertion
|
|
|
|
|
2023-12-21 05:34:52 +00:00
|
|
|
from homeassistant.components.switch import (
|
|
|
|
DOMAIN as SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
)
|
2024-01-27 12:43:55 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
2023-12-21 05:34:52 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2024-01-27 12:43:55 +00:00
|
|
|
from homeassistant.helpers import entity_registry as er
|
2023-12-21 05:34:52 +00:00
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
from .common import assert_entities, setup_platform
|
2023-12-21 05:34:52 +00:00
|
|
|
|
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
async def test_switches(
|
|
|
|
hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry
|
|
|
|
) -> None:
|
2023-12-22 09:11:18 +00:00
|
|
|
"""Tests that the switche entities are correct."""
|
2023-12-21 05:34:52 +00:00
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
entry = await setup_platform(hass, [Platform.SWITCH])
|
2023-12-21 05:34:52 +00:00
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
assert_entities(hass, entry.entry_id, entity_registry, snapshot)
|
2023-12-21 05:34:52 +00:00
|
|
|
|
2024-01-27 12:43:55 +00:00
|
|
|
entity_id = "switch.test_charge"
|
2023-12-21 05:34:52 +00:00
|
|
|
with patch(
|
2023-12-23 12:45:06 +00:00
|
|
|
"homeassistant.components.tessie.switch.start_charging",
|
|
|
|
) as mock_start_charging:
|
2023-12-21 05:34:52 +00:00
|
|
|
# Test Switch On
|
|
|
|
await hass.services.async_call(
|
|
|
|
SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
2024-01-27 12:43:55 +00:00
|
|
|
{ATTR_ENTITY_ID: [entity_id]},
|
2023-12-21 05:34:52 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
2023-12-23 12:45:06 +00:00
|
|
|
mock_start_charging.assert_called_once()
|
2024-01-27 12:43:55 +00:00
|
|
|
assert hass.states.get(entity_id) == snapshot(name=SERVICE_TURN_ON)
|
|
|
|
|
2023-12-23 12:45:06 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.tessie.switch.stop_charging",
|
|
|
|
) as mock_stop_charging:
|
2023-12-21 05:34:52 +00:00
|
|
|
# Test Switch Off
|
|
|
|
await hass.services.async_call(
|
|
|
|
SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
2024-01-27 12:43:55 +00:00
|
|
|
{ATTR_ENTITY_ID: [entity_id]},
|
2023-12-21 05:34:52 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
2023-12-23 12:45:06 +00:00
|
|
|
mock_stop_charging.assert_called_once()
|
2024-01-27 12:43:55 +00:00
|
|
|
|
|
|
|
assert hass.states.get(entity_id) == snapshot(name=SERVICE_TURN_OFF)
|