Add the ability to reload bayesian platforms from yaml (#39771)
This commit is contained in:
1 parent
2a879afc7a
commit
c9ec533aa5
5 files changed
+77
-2
No files matched your search
@@ -1,15 +1,18 @@
|
||||
"""The test for the bayesian sensor platform."""
|
||||
import json
|
||||
from os import path
|
||||
import unittest
|
||||
|
||||
from homeassistant.components.bayesian import binary_sensor as bayesian
|
||||
from homeassistant import config as hass_config
|
||||
from homeassistant.components.bayesian import DOMAIN, binary_sensor as bayesian
|
||||
from homeassistant.components.homeassistant import (
|
||||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_RELOAD, STATE_UNKNOWN
|
||||
from homeassistant.setup import async_setup_component, setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
@@ -631,3 +634,55 @@ async def test_monitored_sensor_goes_away(hass):
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("binary_sensor.test_binary").state == "on"
|
||||
|
||||
|
||||
async def test_reload(hass):
|
||||
"""Verify we can reload bayesian sensors."""
|
||||
|
||||
config = {
|
||||
"binary_sensor": {
|
||||
"name": "test",
|
||||
"platform": "bayesian",
|
||||
"observations": [
|
||||
{
|
||||
"platform": "state",
|
||||
"entity_id": "sensor.test_monitored",
|
||||
"to_state": "on",
|
||||
"prob_given_true": 0.9,
|
||||
"prob_given_false": 0.4,
|
||||
},
|
||||
],
|
||||
"prior": 0.2,
|
||||
"probability_threshold": 0.32,
|
||||
}
|
||||
}
|
||||
|
||||
await async_setup_component(hass, "binary_sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
assert hass.states.get("binary_sensor.test")
|
||||
|
||||
yaml_path = path.join(
|
||||
_get_fixtures_base_path(),
|
||||
"fixtures",
|
||||
"bayesian/configuration.yaml",
|
||||
)
|
||||
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_RELOAD,
|
||||
{},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
assert hass.states.get("binary_sensor.test") is None
|
||||
assert hass.states.get("binary_sensor.test2")
|
||||
|
||||
|
||||
def _get_fixtures_base_path():
|
||||
return path.dirname(path.dirname(path.dirname(__file__)))
|
||||
Reference in new issue
Block a user