"""Wake-on-change switch.""" from __future__ import annotations from unittest.mock import MagicMock 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, ) from homeassistant.core import HomeAssistant from tests.helpers import entity_id_for async def test_switch_reads_and_writes( hass: HomeAssistant, init_integration, mock_client: MagicMock ) -> None: entity_id = entity_id_for(hass, "switch", "wake_on_change") assert hass.states.get(entity_id).state == STATE_ON await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True ) mock_client.set_state.assert_awaited_once_with(wake_on_change=False) assert hass.states.get(entity_id).state == STATE_OFF await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True ) mock_client.set_state.assert_awaited_with(wake_on_change=True)