Skip to content

Commit 775d0d0

Browse files
Add test to listen for new sensor being labelled
1 parent e3bc328 commit 775d0d0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_binary_sensor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
(
3232
"state_1",
3333
"state_2",
34+
"state_3",
3435
"expected_state",
3536
),
3637
[
3738
(
3839
"unavailable",
3940
"on",
4041
"on",
42+
"on",
4143
),
4244
(
45+
"on",
4346
"on",
4447
"on",
4548
"off",
@@ -50,6 +53,7 @@ async def test_state_sensor(
5053
hass: HomeAssistant,
5154
state_1: str,
5255
state_2: str,
56+
state_3: str,
5357
expected_state: str,
5458
entity_registry: er.EntityRegistry,
5559
label_registry: lr.LabelRegistry,
@@ -106,6 +110,25 @@ async def test_state_sensor(
106110
assert state is not None
107111
assert state.state == expected_state
108112

113+
# Add a third sensor to test the listener change
114+
sensor3_entity_entry = entity_registry.async_get_or_create(
115+
"sensor", "test_3", "unique", suggested_object_id="test_3"
116+
)
117+
await hass.async_block_till_done()
118+
sensor3_entity_entry = entity_registry.async_update_entity(
119+
sensor3_entity_entry.entity_id, labels={test_label.label_id}
120+
)
121+
await hass.async_block_till_done()
122+
assert sensor3_entity_entry.entity_id == "sensor.test_3"
123+
124+
hass.states.async_set(sensor3_entity_entry.entity_id, state_3)
125+
await hass.async_block_till_done()
126+
127+
state = hass.states.get("binary_sensor.test_state")
128+
129+
assert state is not None
130+
assert state.state == expected_state
131+
109132

110133
@pytest.mark.parametrize(
111134
(

0 commit comments

Comments
 (0)