mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add test coverage for ESPHome switch platform (#95306)
This commit is contained in:
parent
dbe4252d34
commit
9fe24c54e9
@ -314,7 +314,6 @@ omit =
|
|||||||
homeassistant/components/esphome/domain_data.py
|
homeassistant/components/esphome/domain_data.py
|
||||||
homeassistant/components/esphome/entry_data.py
|
homeassistant/components/esphome/entry_data.py
|
||||||
homeassistant/components/esphome/light.py
|
homeassistant/components/esphome/light.py
|
||||||
homeassistant/components/esphome/switch.py
|
|
||||||
homeassistant/components/etherscan/sensor.py
|
homeassistant/components/etherscan/sensor.py
|
||||||
homeassistant/components/eufy/*
|
homeassistant/components/eufy/*
|
||||||
homeassistant/components/eufylife_ble/__init__.py
|
homeassistant/components/eufylife_ble/__init__.py
|
||||||
|
55
tests/components/esphome/test_switch.py
Normal file
55
tests/components/esphome/test_switch.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"""Test ESPHome switches."""
|
||||||
|
|
||||||
|
|
||||||
|
from unittest.mock import call
|
||||||
|
|
||||||
|
from aioesphomeapi import APIClient, SwitchInfo, SwitchState
|
||||||
|
|
||||||
|
from homeassistant.components.switch import (
|
||||||
|
DOMAIN as SWITCH_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
)
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def test_switch_generic_entity(
|
||||||
|
hass: HomeAssistant, mock_client: APIClient, mock_generic_device_entry
|
||||||
|
) -> None:
|
||||||
|
"""Test a generic switch entity."""
|
||||||
|
entity_info = [
|
||||||
|
SwitchInfo(
|
||||||
|
object_id="myswitch",
|
||||||
|
key=1,
|
||||||
|
name="my switch",
|
||||||
|
unique_id="my_switch",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
states = [SwitchState(key=1, state=True)]
|
||||||
|
user_service = []
|
||||||
|
await mock_generic_device_entry(
|
||||||
|
mock_client=mock_client,
|
||||||
|
entity_info=entity_info,
|
||||||
|
user_service=user_service,
|
||||||
|
states=states,
|
||||||
|
)
|
||||||
|
state = hass.states.get("switch.test_my_switch")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == STATE_ON
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
SWITCH_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{ATTR_ENTITY_ID: "switch.test_my_switch"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
mock_client.switch_command.assert_has_calls([call(1, True)])
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
SWITCH_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
{ATTR_ENTITY_ID: "switch.test_my_switch"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
mock_client.switch_command.assert_has_calls([call(1, False)])
|
Loading…
x
Reference in New Issue
Block a user