Add improved scene support to the counter integration (#28103)
* Add improved scene support to the counter integration * Remove comment
This commit is contained in:
1 parent
37bf577284
commit
c2c9213e9b
2 files changed
+142
No files matched your search
@@ -0,0 +1,71 @@
|
||||
"""Test reproduce state for Counter."""
|
||||
from homeassistant.core import State
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
|
||||
async def test_reproducing_states(hass, caplog):
|
||||
"""Test reproducing Counter states."""
|
||||
hass.states.async_set("counter.entity", "5", {})
|
||||
hass.states.async_set(
|
||||
"counter.entity_attr",
|
||||
"8",
|
||||
{"initial": 12, "minimum": 5, "maximum": 15, "step": 3},
|
||||
)
|
||||
|
||||
configure_calls = async_mock_service(hass, "counter", "configure")
|
||||
|
||||
# These calls should do nothing as entities already in desired state
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[
|
||||
State("counter.entity", "5"),
|
||||
State(
|
||||
"counter.entity_attr",
|
||||
"8",
|
||||
{"initial": 12, "minimum": 5, "maximum": 15, "step": 3},
|
||||
),
|
||||
],
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(configure_calls) == 0
|
||||
|
||||
# Test invalid state is handled
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State("counter.entity", "not_supported")], blocking=True
|
||||
)
|
||||
|
||||
assert "not_supported" in caplog.text
|
||||
assert len(configure_calls) == 0
|
||||
|
||||
# Make sure correct services are called
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[
|
||||
State("counter.entity", "2"),
|
||||
State(
|
||||
"counter.entity_attr",
|
||||
"7",
|
||||
{"initial": 10, "minimum": 3, "maximum": 21, "step": 5},
|
||||
),
|
||||
# Should not raise
|
||||
State("counter.non_existing", "6"),
|
||||
],
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
valid_calls = [
|
||||
{"entity_id": "counter.entity", "value": "2"},
|
||||
{
|
||||
"entity_id": "counter.entity_attr",
|
||||
"value": "7",
|
||||
"initial": 10,
|
||||
"minimum": 3,
|
||||
"maximum": 21,
|
||||
"step": 5,
|
||||
},
|
||||
]
|
||||
assert len(configure_calls) == 2
|
||||
for call in configure_calls:
|
||||
assert call.domain == "counter"
|
||||
assert call.data in valid_calls
|
||||
valid_calls.remove(call.data)
|
||||
Reference in new issue
Block a user