mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
Make sure command entities restore from state (#38038)
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
"""The tests for the Rfxtrx sensor platform."""
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx.const import ATTR_EVENT
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.common import async_fire_time_changed, mock_restore_cache
|
||||
|
||||
|
||||
async def test_one(hass, rfxtrx):
|
||||
@@ -59,6 +63,27 @@ async def test_one_pt2262(hass, rfxtrx):
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"state,event",
|
||||
[["on", "0b1100cd0213c7f230010f71"], ["off", "0b1100cd0213c7f230000f71"]],
|
||||
)
|
||||
async def test_state_restore(hass, rfxtrx, state, event):
|
||||
"""State restoration."""
|
||||
|
||||
entity_id = "binary_sensor.ac_213c7f2_48"
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f230010f71": {}}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_several(hass, rfxtrx):
|
||||
"""Test with 3."""
|
||||
assert await async_setup_component(
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
"""The tests for the Rfxtrx cover platform."""
|
||||
from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_one_cover(hass, rfxtrx):
|
||||
"""Test with 1 cover."""
|
||||
@@ -46,6 +51,24 @@ async def test_one_cover(hass, rfxtrx):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("state", ["open", "closed"])
|
||||
async def test_state_restore(hass, rfxtrx, state):
|
||||
"""State restoration."""
|
||||
|
||||
entity_id = "cover.lightwaverf_siemens_0213c7_242"
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state)])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1400cd0213c7f20d010f51": {}}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_several_covers(hass, rfxtrx):
|
||||
"""Test with 3 covers."""
|
||||
assert await async_setup_component(
|
||||
|
||||
@@ -3,10 +3,14 @@ from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_one_light(hass, rfxtrx):
|
||||
"""Test with 1 light."""
|
||||
@@ -83,6 +87,27 @@ async def test_one_light(hass, rfxtrx):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("state,brightness", [["on", 100], ["on", 50], ["off", None]])
|
||||
async def test_state_restore(hass, rfxtrx, state, brightness):
|
||||
"""State restoration."""
|
||||
|
||||
entity_id = "light.ac_213c7f2_16"
|
||||
|
||||
mock_restore_cache(
|
||||
hass, [State(entity_id, state, attributes={ATTR_BRIGHTNESS: brightness})]
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210020f51": {}}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
assert hass.states.get(entity_id).attributes.get(ATTR_BRIGHTNESS) == brightness
|
||||
|
||||
|
||||
async def test_several_lights(hass, rfxtrx):
|
||||
"""Test with 3 lights."""
|
||||
assert await async_setup_component(
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
"""The tests for the Rfxtrx sensor platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx.const import ATTR_EVENT
|
||||
from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_default_config(hass, rfxtrx):
|
||||
"""Test with 0 sensor."""
|
||||
@@ -34,6 +40,27 @@ async def test_one_sensor(hass, rfxtrx):
|
||||
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"state,event",
|
||||
[["18.4", "0a520801070100b81b0279"], ["17.9", "0a52085e070100b31b0279"]],
|
||||
)
|
||||
async def test_state_restore(hass, rfxtrx, state, event):
|
||||
"""State restoration."""
|
||||
|
||||
entity_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_07_01_temperature"
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0a520801070100b81b0279": {}}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
|
||||
@@ -3,10 +3,13 @@ from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
|
||||
|
||||
async def test_one_switch(hass, rfxtrx):
|
||||
"""Test with 1 switch."""
|
||||
@@ -42,6 +45,24 @@ async def test_one_switch(hass, rfxtrx):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("state", ["on", "off"])
|
||||
async def test_state_restore(hass, rfxtrx, state):
|
||||
"""State restoration."""
|
||||
|
||||
entity_id = "switch.ac_213c7f2_16"
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state)])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210010f51": {}}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_several_switches(hass, rfxtrx):
|
||||
"""Test with 3 switches."""
|
||||
assert await async_setup_component(
|
||||
|
||||
Reference in New Issue
Block a user