2022-09-26 01:55:58 +00:00
|
|
|
"""The tests for Netatmo switch."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant.components.switch import (
|
|
|
|
DOMAIN as SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
)
|
|
|
|
from homeassistant.const import ATTR_ENTITY_ID
|
2023-02-15 09:00:49 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2022-09-26 01:55:58 +00:00
|
|
|
|
|
|
|
from .common import selected_platforms
|
|
|
|
|
|
|
|
|
2023-02-15 09:00:49 +00:00
|
|
|
async def test_switch_setup_and_services(
|
|
|
|
hass: HomeAssistant, config_entry, netatmo_auth
|
|
|
|
) -> None:
|
2022-09-26 01:55:58 +00:00
|
|
|
"""Test setup and services."""
|
|
|
|
with selected_platforms(["switch"]):
|
2022-10-02 01:11:54 +00:00
|
|
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
2022-09-26 01:55:58 +00:00
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
switch_entity = "switch.prise"
|
|
|
|
|
|
|
|
assert hass.states.get(switch_entity).state == "on"
|
|
|
|
|
|
|
|
# Test turning switch off
|
|
|
|
with patch("pyatmo.home.Home.async_set_state") as mock_set_state:
|
|
|
|
await hass.services.async_call(
|
|
|
|
SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_OFF,
|
|
|
|
{ATTR_ENTITY_ID: switch_entity},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
mock_set_state.assert_called_once_with(
|
|
|
|
{
|
|
|
|
"modules": [
|
|
|
|
{
|
|
|
|
"id": "12:34:56:80:00:12:ac:f2",
|
|
|
|
"on": False,
|
|
|
|
"bridge": "12:34:56:80:60:40",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Test turning switch on
|
|
|
|
with patch("pyatmo.home.Home.async_set_state") as mock_set_state:
|
|
|
|
await hass.services.async_call(
|
|
|
|
SWITCH_DOMAIN,
|
|
|
|
SERVICE_TURN_ON,
|
|
|
|
{ATTR_ENTITY_ID: switch_entity},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
mock_set_state.assert_called_once_with(
|
|
|
|
{
|
|
|
|
"modules": [
|
|
|
|
{
|
|
|
|
"id": "12:34:56:80:00:12:ac:f2",
|
|
|
|
"on": True,
|
|
|
|
"bridge": "12:34:56:80:60:40",
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|