mirror of
https://github.com/home-assistant/core.git
synced 2025-11-04 16:39:28 +00:00
Bayesian - support unique_id: (#79879)
* support unique_id * adds test for unique_ids
This commit is contained in:
@@ -22,6 +22,7 @@ from homeassistant.const import (
|
||||
CONF_NAME,
|
||||
CONF_PLATFORM,
|
||||
CONF_STATE,
|
||||
CONF_UNIQUE_ID,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
@@ -100,6 +101,7 @@ TEMPLATE_SCHEMA = vol.Schema(
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_DEVICE_CLASS): cv.string,
|
||||
vol.Required(CONF_OBSERVATIONS): vol.Schema(
|
||||
vol.All(
|
||||
@@ -134,6 +136,7 @@ async def async_setup_platform(
|
||||
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
|
||||
|
||||
name: str = config[CONF_NAME]
|
||||
unique_id: str | None = config.get(CONF_UNIQUE_ID)
|
||||
observations: list[ConfigType] = config[CONF_OBSERVATIONS]
|
||||
prior: float = config[CONF_PRIOR]
|
||||
probability_threshold: float = config[CONF_PROBABILITY_THRESHOLD]
|
||||
@@ -152,7 +155,12 @@ async def async_setup_platform(
|
||||
async_add_entities(
|
||||
[
|
||||
BayesianBinarySensor(
|
||||
name, prior, observations, probability_threshold, device_class
|
||||
name,
|
||||
unique_id,
|
||||
prior,
|
||||
observations,
|
||||
probability_threshold,
|
||||
device_class,
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -166,6 +174,7 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
unique_id: str | None,
|
||||
prior: float,
|
||||
observations: list[ConfigType],
|
||||
probability_threshold: float,
|
||||
@@ -173,6 +182,7 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
) -> None:
|
||||
"""Initialize the Bayesian sensor."""
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = unique_id and f"bayesian-{unique_id}"
|
||||
self._observations = [
|
||||
Observation(
|
||||
entity_id=observation.get(CONF_ENTITY_ID),
|
||||
|
||||
Reference in New Issue
Block a user