Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push real binary sensor states to state machine in tests #128894

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/components/google_pubsub/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def test_allowlist(hass: HomeAssistant, mock_client) -> None:
]

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()

was_called = publish_client.publish.call_count == 1
Expand Down Expand Up @@ -178,7 +178,7 @@ async def test_denylist(hass: HomeAssistant, mock_client) -> None:
]

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()

was_called = publish_client.publish.call_count == 1
Expand Down
17 changes: 9 additions & 8 deletions tests/components/homekit/test_type_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@
ATTR_UNIT_OF_MEASUREMENT,
EVENT_HOMEASSISTANT_START,
PERCENTAGE,
STATE_HOME,
STATE_NOT_HOME,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
UnitOfTemperature,
)
Expand Down Expand Up @@ -535,11 +534,11 @@ async def test_binary(hass: HomeAssistant, hk_driver) -> None:
await hass.async_block_till_done()
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()
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()
assert acc.char_detected.value == 0

Expand Down Expand Up @@ -579,13 +578,15 @@ async def test_motion_uses_bool(hass: HomeAssistant, hk_driver) -> None:
assert acc.char_detected.value is False

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()
assert acc.char_detected.value is True
assert acc.char_detected.value is False

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()
assert acc.char_detected.value is False
Expand Down
6 changes: 3 additions & 3 deletions tests/components/logbook/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "init")
hass.states.async_set("binary_sensor.is_light", "unavailable")
hass.states.async_set("binary_sensor.is_light", "unknown")
await async_wait_recording_done(hass)

@callback
Expand Down Expand Up @@ -3023,7 +3023,7 @@ def auto_off_listener(event):

# Make sure we get rows back in order
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": "off", "when": ANY},
]
Expand Down
18 changes: 9 additions & 9 deletions tests/components/template/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ async def test_setup_invalid_sensors(hass: HomeAssistant, count) -> None:
"value_template": "{{ states.sensor.xyz.state }}",
"icon_template": "{% if "
"states.binary_sensor.test_state.state == "
"'Works' %}"
"'on' %}"
"mdi:check"
"{% endif %}",
},
Expand All @@ -270,7 +270,7 @@ async def test_setup_invalid_sensors(hass: HomeAssistant, count) -> None:
"state": "{{ states.sensor.xyz.state }}",
"icon": "{% if "
"states.binary_sensor.test_state.state == "
"'Works' %}"
"'on' %}"
"mdi:check"
"{% endif %}",
},
Expand All @@ -287,7 +287,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
state = hass.states.get(entity_id)
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()
state = hass.states.get(entity_id)
assert state.attributes["icon"] == "mdi:check"
Expand All @@ -306,7 +306,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
"value_template": "{{ states.sensor.xyz.state }}",
"entity_picture_template": "{% if "
"states.binary_sensor.test_state.state == "
"'Works' %}"
"'on' %}"
"/local/sensor.png"
"{% endif %}",
},
Expand All @@ -323,7 +323,7 @@ async def test_icon_template(hass: HomeAssistant, entity_id) -> None:
"state": "{{ states.sensor.xyz.state }}",
"picture": "{% if "
"states.binary_sensor.test_state.state == "
"'Works' %}"
"'on' %}"
"/local/sensor.png"
"{% endif %}",
},
Expand All @@ -340,7 +340,7 @@ async def test_entity_picture_template(hass: HomeAssistant, entity_id) -> None:
state = hass.states.get(entity_id)
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()
state = hass.states.get(entity_id)
assert state.attributes["entity_picture"] == "/local/sensor.png"
Expand Down Expand Up @@ -737,7 +737,7 @@ async def test_invalid_attribute_template(
hass: HomeAssistant, caplog_setup_text
) -> None:
"""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 ("test_attribute") in caplog_setup_text
assert ("TemplateError") in caplog_setup_text
Expand Down Expand Up @@ -802,7 +802,7 @@ async def test_no_update_template_match_all(
},
)
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 hass.states.get("binary_sensor.all_state").state == STATE_UNKNOWN
Expand All @@ -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_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()

assert hass.states.get("binary_sensor.all_state").state == ON
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,10 +1892,10 @@ def specific_run_callback(
"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()
assert len(specific_runs) == 9
assert specific_runs[8] == "binary_sensor_on"
assert specific_runs[8] == "on"
assert info.listeners == {
"all": False,
"domains": set(),
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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()

info = render_to_info(hass, template_complex_str)
Expand All @@ -4559,7 +4559,7 @@ async def test_async_render_to_info_with_wildcard_matching_state(
assert info.all_states is True
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)

assert not info.domains
Expand Down
Loading