1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Demo: remove deprecated switch entity properties (#52424)

* Demo: deprecate switch entity properties

* Fix emulated_kasa test
This commit is contained in:
Shay Levy
2021-07-02 18:50:57 +03:00
committed by GitHub
parent 5cd4471c67
commit 1eb27f7ccc
4 changed files with 116 additions and 3 deletions

View File

@@ -0,0 +1,88 @@
"""The tests for the demo switch component."""
import pytest
from homeassistant.components.demo import DOMAIN
from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.setup import async_setup_component
SWITCH_ENTITY_IDS = ["switch.decorative_lights", "switch.ac"]
@pytest.fixture(autouse=True)
async def setup_comp(hass):
"""Set up demo component."""
assert await async_setup_component(
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": DOMAIN}}
)
await hass.async_block_till_done()
@pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS)
async def test_turn_on(hass, switch_entity_id):
"""Test switch turn on method."""
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: switch_entity_id},
blocking=True,
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_OFF
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: switch_entity_id},
blocking=True,
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_ON
@pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS)
async def test_turn_off(hass, switch_entity_id):
"""Test switch turn off method."""
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: switch_entity_id},
blocking=True,
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_ON
await hass.services.async_call(
SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: switch_entity_id},
blocking=True,
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_OFF
@pytest.mark.parametrize("switch_entity_id", SWITCH_ENTITY_IDS)
async def test_turn_off_without_entity_id(hass, switch_entity_id):
"""Test switch turn off all switches."""
await hass.services.async_call(
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: "all"}, blocking=True
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_ON
await hass.services.async_call(
SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
)
state = hass.states.get(switch_entity_id)
assert state.state == STATE_OFF