Add reproduce state support to text
platform (#82772)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
f869ce9d06
commit
1453308bc4
2 changed files with 110 additions and 0 deletions
53
tests/components/text/test_reproduce_state.py
Normal file
53
tests/components/text/test_reproduce_state.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
"""Test reproduce state for Text entities."""
|
||||
from homeassistant.components.text.const import (
|
||||
ATTR_MAX,
|
||||
ATTR_MIN,
|
||||
ATTR_MODE,
|
||||
ATTR_PATTERN,
|
||||
DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
from homeassistant.helpers.state import async_reproduce_state
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
VALID_TEXT1 = "Hello"
|
||||
VALID_TEXT2 = "World"
|
||||
|
||||
|
||||
async def test_reproducing_states(hass, caplog):
|
||||
"""Test reproducing Text states."""
|
||||
|
||||
hass.states.async_set(
|
||||
"text.test_text",
|
||||
VALID_TEXT1,
|
||||
{ATTR_MIN: 1, ATTR_MAX: 5, ATTR_MODE: "text", ATTR_PATTERN: None},
|
||||
)
|
||||
|
||||
# These calls should do nothing as entities already in desired state
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[
|
||||
State("text.test_text", VALID_TEXT1),
|
||||
# Should not raise
|
||||
State("text.non_existing", "234"),
|
||||
],
|
||||
)
|
||||
|
||||
assert hass.states.get("text.test_text").state == VALID_TEXT1
|
||||
|
||||
# Test reproducing with different state
|
||||
calls = async_mock_service(hass, DOMAIN, SERVICE_SET_VALUE)
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[
|
||||
State("text.test_text", VALID_TEXT2),
|
||||
# Should not raise
|
||||
State("text.non_existing", "234"),
|
||||
],
|
||||
)
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].domain == DOMAIN
|
||||
assert calls[0].data == {"entity_id": "text.test_text", "value": VALID_TEXT2}
|
Loading…
Add table
Add a link
Reference in a new issue