mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Push real binary sensor states to state machine in tests (#128894)
This commit is contained in:
parent
e861cab727
commit
be4641b8f3
@ -148,7 +148,7 @@ async def test_allowlist(hass: HomeAssistant, mock_client) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
for test in tests:
|
for test in tests:
|
||||||
hass.states.async_set(test.id, "not blank")
|
hass.states.async_set(test.id, "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
was_called = publish_client.publish.call_count == 1
|
was_called = publish_client.publish.call_count == 1
|
||||||
@ -178,7 +178,7 @@ async def test_denylist(hass: HomeAssistant, mock_client) -> None:
|
|||||||
]
|
]
|
||||||
|
|
||||||
for test in tests:
|
for test in tests:
|
||||||
hass.states.async_set(test.id, "not blank")
|
hass.states.async_set(test.id, "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
was_called = publish_client.publish.call_count == 1
|
was_called = publish_client.publish.call_count == 1
|
||||||
|
@ -30,10 +30,9 @@ from homeassistant.const import (
|
|||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
STATE_HOME,
|
|
||||||
STATE_NOT_HOME,
|
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
@ -535,11 +534,11 @@ async def test_binary(hass: HomeAssistant, hk_driver) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_detected.value == 0
|
assert acc.char_detected.value == 0
|
||||||
|
|
||||||
hass.states.async_set(entity_id, STATE_HOME, {ATTR_DEVICE_CLASS: "opening"})
|
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_DEVICE_CLASS: "opening"})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_detected.value == 1
|
assert acc.char_detected.value == 0
|
||||||
|
|
||||||
hass.states.async_set(entity_id, STATE_NOT_HOME, {ATTR_DEVICE_CLASS: "opening"})
|
hass.states.async_set(entity_id, STATE_UNAVAILABLE, {ATTR_DEVICE_CLASS: "opening"})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_detected.value == 0
|
assert acc.char_detected.value == 0
|
||||||
|
|
||||||
@ -579,13 +578,15 @@ async def test_motion_uses_bool(hass: HomeAssistant, hk_driver) -> None:
|
|||||||
assert acc.char_detected.value is False
|
assert acc.char_detected.value is False
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
entity_id, STATE_HOME, {ATTR_DEVICE_CLASS: BinarySensorDeviceClass.MOTION}
|
entity_id, STATE_UNKNOWN, {ATTR_DEVICE_CLASS: BinarySensorDeviceClass.MOTION}
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_detected.value is True
|
assert acc.char_detected.value is False
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
entity_id, STATE_NOT_HOME, {ATTR_DEVICE_CLASS: BinarySensorDeviceClass.MOTION}
|
entity_id,
|
||||||
|
STATE_UNAVAILABLE,
|
||||||
|
{ATTR_DEVICE_CLASS: BinarySensorDeviceClass.MOTION},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_detected.value is False
|
assert acc.char_detected.value is False
|
||||||
|
@ -2985,8 +2985,8 @@ async def test_live_stream_with_changed_state_change(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.is_light", "ignored")
|
hass.states.async_set("binary_sensor.is_light", "unavailable")
|
||||||
hass.states.async_set("binary_sensor.is_light", "init")
|
hass.states.async_set("binary_sensor.is_light", "unknown")
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -3023,7 +3023,7 @@ async def test_live_stream_with_changed_state_change(
|
|||||||
|
|
||||||
# Make sure we get rows back in order
|
# Make sure we get rows back in order
|
||||||
assert recieved_rows == [
|
assert recieved_rows == [
|
||||||
{"entity_id": "binary_sensor.is_light", "state": "init", "when": ANY},
|
{"entity_id": "binary_sensor.is_light", "state": "unknown", "when": ANY},
|
||||||
{"entity_id": "binary_sensor.is_light", "state": "on", "when": ANY},
|
{"entity_id": "binary_sensor.is_light", "state": "on", "when": ANY},
|
||||||
{"entity_id": "binary_sensor.is_light", "state": "off", "when": ANY},
|
{"entity_id": "binary_sensor.is_light", "state": "off", "when": ANY},
|
||||||
]
|
]
|
||||||
|
@ -253,7 +253,7 @@ async def test_setup_invalid_sensors(hass: HomeAssistant, count) -> None:
|
|||||||
"value_template": "{{ states.sensor.xyz.state }}",
|
"value_template": "{{ states.sensor.xyz.state }}",
|
||||||
"icon_template": "{% if "
|
"icon_template": "{% if "
|
||||||
"states.binary_sensor.test_state.state == "
|
"states.binary_sensor.test_state.state == "
|
||||||
"'Works' %}"
|
"'on' %}"
|
||||||
"mdi:check"
|
"mdi:check"
|
||||||
"{% endif %}",
|
"{% endif %}",
|
||||||
},
|
},
|
||||||
@ -270,7 +270,7 @@ async def test_setup_invalid_sensors(hass: HomeAssistant, count) -> None:
|
|||||||
"state": "{{ states.sensor.xyz.state }}",
|
"state": "{{ states.sensor.xyz.state }}",
|
||||||
"icon": "{% if "
|
"icon": "{% if "
|
||||||
"states.binary_sensor.test_state.state == "
|
"states.binary_sensor.test_state.state == "
|
||||||
"'Works' %}"
|
"'on' %}"
|
||||||
"mdi:check"
|
"mdi:check"
|
||||||
"{% endif %}",
|
"{% endif %}",
|
||||||
},
|
},
|
||||||
@ -287,7 +287,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
|
|||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.attributes.get("icon") == ""
|
assert state.attributes.get("icon") == ""
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.test_state", "Works")
|
hass.states.async_set("binary_sensor.test_state", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.attributes["icon"] == "mdi:check"
|
assert state.attributes["icon"] == "mdi:check"
|
||||||
@ -306,7 +306,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
|
|||||||
"value_template": "{{ states.sensor.xyz.state }}",
|
"value_template": "{{ states.sensor.xyz.state }}",
|
||||||
"entity_picture_template": "{% if "
|
"entity_picture_template": "{% if "
|
||||||
"states.binary_sensor.test_state.state == "
|
"states.binary_sensor.test_state.state == "
|
||||||
"'Works' %}"
|
"'on' %}"
|
||||||
"/local/sensor.png"
|
"/local/sensor.png"
|
||||||
"{% endif %}",
|
"{% endif %}",
|
||||||
},
|
},
|
||||||
@ -323,7 +323,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
|
|||||||
"state": "{{ states.sensor.xyz.state }}",
|
"state": "{{ states.sensor.xyz.state }}",
|
||||||
"picture": "{% if "
|
"picture": "{% if "
|
||||||
"states.binary_sensor.test_state.state == "
|
"states.binary_sensor.test_state.state == "
|
||||||
"'Works' %}"
|
"'on' %}"
|
||||||
"/local/sensor.png"
|
"/local/sensor.png"
|
||||||
"{% endif %}",
|
"{% endif %}",
|
||||||
},
|
},
|
||||||
@ -340,7 +340,7 @@ async def test_entity_picture_template(hass: HomeAssistant, entity_id) -> None:
|
|||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.attributes.get("entity_picture") == ""
|
assert state.attributes.get("entity_picture") == ""
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.test_state", "Works")
|
hass.states.async_set("binary_sensor.test_state", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state.attributes["entity_picture"] == "/local/sensor.png"
|
assert state.attributes["entity_picture"] == "/local/sensor.png"
|
||||||
@ -737,7 +737,7 @@ async def test_invalid_attribute_template(
|
|||||||
hass: HomeAssistant, caplog_setup_text
|
hass: HomeAssistant, caplog_setup_text
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that errors are logged if rendering template fails."""
|
"""Test that errors are logged if rendering template fails."""
|
||||||
hass.states.async_set("binary_sensor.test_sensor", "true")
|
hass.states.async_set("binary_sensor.test_sensor", STATE_ON)
|
||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
assert ("test_attribute") in caplog_setup_text
|
assert ("test_attribute") in caplog_setup_text
|
||||||
assert ("TemplateError") in caplog_setup_text
|
assert ("TemplateError") in caplog_setup_text
|
||||||
@ -802,7 +802,7 @@ async def test_no_update_template_match_all(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
hass.states.async_set("binary_sensor.test_sensor", "true")
|
hass.states.async_set("binary_sensor.test_sensor", STATE_ON)
|
||||||
assert len(hass.states.async_all()) == 5
|
assert len(hass.states.async_all()) == 5
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.all_state").state == STATE_UNKNOWN
|
assert hass.states.get("binary_sensor.all_state").state == STATE_UNKNOWN
|
||||||
@ -818,7 +818,7 @@ async def test_no_update_template_match_all(
|
|||||||
assert hass.states.get("binary_sensor.all_entity_picture").state == ON
|
assert hass.states.get("binary_sensor.all_entity_picture").state == ON
|
||||||
assert hass.states.get("binary_sensor.all_attribute").state == ON
|
assert hass.states.get("binary_sensor.all_attribute").state == ON
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.test_sensor", "false")
|
hass.states.async_set("binary_sensor.test_sensor", STATE_OFF)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.all_state").state == ON
|
assert hass.states.get("binary_sensor.all_state").state == ON
|
||||||
|
@ -1892,10 +1892,10 @@ async def test_track_template_result_complex(hass: HomeAssistant) -> None:
|
|||||||
"time": False,
|
"time": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.single", "binary_sensor_on")
|
hass.states.async_set("binary_sensor.single", "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(specific_runs) == 9
|
assert len(specific_runs) == 9
|
||||||
assert specific_runs[8] == "binary_sensor_on"
|
assert specific_runs[8] == "on"
|
||||||
assert info.listeners == {
|
assert info.listeners == {
|
||||||
"all": False,
|
"all": False,
|
||||||
"domains": set(),
|
"domains": set(),
|
||||||
|
@ -4549,7 +4549,7 @@ async def test_async_render_to_info_with_wildcard_matching_state(
|
|||||||
hass.states.async_set("cover.office_window", "closed")
|
hass.states.async_set("cover.office_window", "closed")
|
||||||
hass.states.async_set("cover.office_skylight", "open")
|
hass.states.async_set("cover.office_skylight", "open")
|
||||||
hass.states.async_set("cover.x_skylight", "open")
|
hass.states.async_set("cover.x_skylight", "open")
|
||||||
hass.states.async_set("binary_sensor.door", "open")
|
hass.states.async_set("binary_sensor.door", "on")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
info = render_to_info(hass, template_complex_str)
|
info = render_to_info(hass, template_complex_str)
|
||||||
@ -4559,7 +4559,7 @@ async def test_async_render_to_info_with_wildcard_matching_state(
|
|||||||
assert info.all_states is True
|
assert info.all_states is True
|
||||||
assert info.rate_limit == template.ALL_STATES_RATE_LIMIT
|
assert info.rate_limit == template.ALL_STATES_RATE_LIMIT
|
||||||
|
|
||||||
hass.states.async_set("binary_sensor.door", "closed")
|
hass.states.async_set("binary_sensor.door", "off")
|
||||||
info = render_to_info(hass, template_complex_str)
|
info = render_to_info(hass, template_complex_str)
|
||||||
|
|
||||||
assert not info.domains
|
assert not info.domains
|
||||||
|
Loading…
x
Reference in New Issue
Block a user