@@ -102,6 +102,120 @@ async def test_invalid_default_entity_id(
102102 CONFIG_SECTION_SCHEMA (config )
103103
104104
105+ @pytest .mark .parametrize (
106+ ("config" , "expected_error" ),
107+ [
108+ (
109+ {
110+ "trigger" : {"trigger" : "event" , "event_type" : "my_event" },
111+ "binary_sensor" : {
112+ "state" : "{{ states('binary_sensor.test') }}" ,
113+ "unique_id" : "test" ,
114+ "name" : "test" ,
115+ "auto_off" : "00:00:01" ,
116+ },
117+ },
118+ None ,
119+ ),
120+ (
121+ {
122+ "binary_sensor" : {
123+ "state" : "{{ states('binary_sensor.test') }}" ,
124+ "name" : "test" ,
125+ },
126+ },
127+ None ,
128+ ),
129+ (
130+ {
131+ "binary_sensor" : {
132+ "state" : "{{ states('binary_sensor.test') }}" ,
133+ "auto_off" : "00:00:01" ,
134+ },
135+ },
136+ "The auto_off option for template binary sensor: name: Template Binary Sensor" ,
137+ ),
138+ (
139+ {
140+ "binary_sensor" : {
141+ "state" : "{{ states('binary_sensor.test') }}" ,
142+ "name" : "test" ,
143+ "auto_off" : "00:00:01" ,
144+ },
145+ },
146+ "The auto_off option for template binary sensor: name: test" ,
147+ ),
148+ (
149+ {
150+ "binary_sensor" : {
151+ "state" : "{{ states('binary_sensor.test') }}" ,
152+ "unique_id" : "test_unique_id" ,
153+ "auto_off" : "00:00:01" ,
154+ },
155+ },
156+ "The auto_off option for template binary sensor: unique_id: test_unique_id" ,
157+ ),
158+ (
159+ {
160+ "binary_sensor" : {
161+ "state" : "{{ states('binary_sensor.test') }}" ,
162+ "name" : "test" ,
163+ "unique_id" : "test_unique_id" ,
164+ "auto_off" : "00:00:01" ,
165+ },
166+ },
167+ "The auto_off option for template binary sensor: name: test" ,
168+ ),
169+ (
170+ {
171+ "binary_sensor" : {
172+ "state" : "{{ states('binary_sensor.test') }}" ,
173+ "default_entity_id" : "binary_sensor.test_entity_id" ,
174+ "auto_off" : "00:00:01" ,
175+ },
176+ },
177+ "The auto_off option for template binary sensor: default_entity_id: binary_sensor.test_entity_id" ,
178+ ),
179+ (
180+ {
181+ "binary_sensor" : {
182+ "state" : "{{ states('binary_sensor.test') }}" ,
183+ "name" : "test" ,
184+ "unique_id" : "test_unique_id" ,
185+ "default_entity_id" : "binary_sensor.test_entity_id" ,
186+ "auto_off" : "00:00:01" ,
187+ },
188+ },
189+ "The auto_off option for template binary sensor: name: test" ,
190+ ),
191+ (
192+ {
193+ "binary_sensor" : {
194+ "state" : "{{ states('binary_sensor.test') }}" ,
195+ "unique_id" : "test_unique_id" ,
196+ "default_entity_id" : "binary_sensor.test_entity_id" ,
197+ "auto_off" : "00:00:01" ,
198+ },
199+ },
200+ "The auto_off option for template binary sensor: default_entity_id: binary_sensor.test_entity_id" ,
201+ ),
202+ ],
203+ )
204+ async def test_invalid_binary_sensor_schema_with_auto_off (
205+ hass : HomeAssistant ,
206+ config : dict ,
207+ expected_error : str | None ,
208+ caplog : pytest .LogCaptureFixture ,
209+ ) -> None :
210+ """Test invalid config schemas create issue and log warning."""
211+
212+ await async_setup_component (hass , "template" , {"template" : [config ]})
213+
214+ assert (
215+ expected_error is None and "ERROR" not in caplog .text
216+ ) or expected_error in caplog .text
217+
218+
105219@pytest .mark .parametrize (
106220 ("config" , "expected" ),
107221 [
0 commit comments