11"""The test for the label_state binary sensor platform."""
22
33import pytest
4+ from homeassistant .const import (
5+ CONF_ENTITY_ID ,
6+ CONF_NAME ,
7+ CONF_PLATFORM ,
8+ CONF_UNIQUE_ID ,
9+ EVENT_HOMEASSISTANT_STARTED ,
10+ STATE_ON ,
11+ )
412from homeassistant .core import HomeAssistant
513from homeassistant .helpers import entity_registry as er
614from homeassistant .helpers import label_registry as lr
@@ -117,38 +125,37 @@ async def test_numeric_state_sensor(
117125 """Test the numeric state sensor."""
118126
119127 test_label = label_registry .async_create (
120- "test " ,
128+ "test_numeric_state " ,
121129 )
122130
123131 sensor1_entity_entry = entity_registry .async_get_or_create (
124132 "sensor" , "test_1" , "unique" , suggested_object_id = "test_1"
125133 )
126134 sensor1_entity_entry .labels .add (test_label .label_id )
135+ await hass .async_block_till_done ()
127136 assert sensor1_entity_entry .entity_id == "sensor.test_1"
128137 assert test_label .label_id in sensor1_entity_entry .labels
129138
130139 sensor2_entity_entry = entity_registry .async_get_or_create (
131140 "sensor" , "test_2" , "unique" , suggested_object_id = "test_2"
132141 )
133142 sensor2_entity_entry .labels .add (test_label .label_id )
143+ await hass .async_block_till_done ()
134144 assert sensor2_entity_entry .entity_id == "sensor.test_2"
145+ assert test_label .label_id in sensor2_entity_entry .labels
135146
136- config = MockConfigEntry (
137- domain = "label_state" ,
138- data = {},
139- options = {
147+ config = {
148+ "binary_sensor" : {
149+ "platform" : "label_state" ,
140150 "name" : "test_numeric_state" ,
141151 "label" : test_label .label_id ,
142152 "state_type" : "numeric_state" ,
143153 "state_lower_limit" : state_lower_limit ,
144154 "state_upper_limit" : state_upper_limit ,
145- },
146- title = "test_numeric_state" ,
147- )
155+ }
156+ }
148157
149- # config.add_to_hass(hass)
150- await setup_integration (hass , config )
151- # assert await hass.config_entries.async_setup(config.entry_id)
158+ assert await async_setup_component (hass , "binary_sensor" , config )
152159 await hass .async_block_till_done ()
153160
154161 hass .states .async_set (sensor1_entity_entry .entity_id , state_1 )
@@ -157,6 +164,10 @@ async def test_numeric_state_sensor(
157164 hass .states .async_set (sensor2_entity_entry .entity_id , state_2 )
158165 await hass .async_block_till_done ()
159166
167+ state1 = hass .states .get (sensor1_entity_entry .entity_id )
168+ assert state1 is not None
169+ assert state1 .state == state_1
170+
160171 state = hass .states .get ("binary_sensor.test_numeric_state" )
161172
162173 assert state is not None
0 commit comments