|
13 | 13 | DOMAIN as HA_DOMAIN, |
14 | 14 | SERVICE_UPDATE_ENTITY, |
15 | 15 | ) |
| 16 | +from homeassistant.config_entries import ConfigSubentryData |
16 | 17 | from homeassistant.const import ( |
17 | 18 | ATTR_ENTITY_ID, |
18 | 19 | SERVICE_RELOAD, |
|
26 | 27 | from homeassistant.helpers.event import async_track_state_change_event |
27 | 28 | from homeassistant.setup import async_setup_component |
28 | 29 |
|
29 | | -from tests.common import get_fixture_path |
| 30 | +from tests.common import MockConfigEntry, get_fixture_path |
30 | 31 |
|
31 | 32 |
|
32 | 33 | async def test_load_values_when_added_to_hass(hass: HomeAssistant) -> None: |
@@ -295,6 +296,44 @@ async def test_sensor_value_template(hass: HomeAssistant) -> None: |
295 | 296 | assert await async_setup_component(hass, "binary_sensor", config) |
296 | 297 | await hass.async_block_till_done() |
297 | 298 |
|
| 299 | + await _test_sensor_value_template(hass) |
| 300 | + |
| 301 | + |
| 302 | +async def test_sensor_value_template_config_entry(hass: HomeAssistant) -> None: |
| 303 | + """Test sensor on template platform observations.""" |
| 304 | + template_config_entry = MockConfigEntry( |
| 305 | + data={}, |
| 306 | + domain=DOMAIN, |
| 307 | + options={ |
| 308 | + "name": "Test_Binary", |
| 309 | + "prior": 0.2, |
| 310 | + "probability_threshold": 0.32, |
| 311 | + }, |
| 312 | + subentries_data=[ |
| 313 | + ConfigSubentryData( |
| 314 | + data={ |
| 315 | + "platform": "template", |
| 316 | + "value_template": "{{states('sensor.test_monitored') == 'off'}}", |
| 317 | + "prob_given_true": 0.8, |
| 318 | + "prob_given_false": 0.4, |
| 319 | + "name": "observation_1", |
| 320 | + }, |
| 321 | + subentry_type="observation", |
| 322 | + title="observation_1", |
| 323 | + unique_id=None, |
| 324 | + ) |
| 325 | + ], |
| 326 | + title="Test_Binary", |
| 327 | + ) |
| 328 | + template_config_entry.add_to_hass(hass) |
| 329 | + |
| 330 | + assert await hass.config_entries.async_setup(template_config_entry.entry_id) |
| 331 | + await hass.async_block_till_done() |
| 332 | + |
| 333 | + await _test_sensor_value_template(hass) |
| 334 | + |
| 335 | + |
| 336 | +async def _test_sensor_value_template(hass: HomeAssistant) -> None: |
298 | 337 | hass.states.async_set("sensor.test_monitored", "on") |
299 | 338 |
|
300 | 339 | state = hass.states.get("binary_sensor.test_binary") |
|
0 commit comments