1 """Helpers to deal with bayesian observations."""
3 from __future__
import annotations
5 from dataclasses
import dataclass, field
17 from .const
import CONF_P_GIVEN_F, CONF_P_GIVEN_T, CONF_TO_STATE
22 """Representation of a sensor or template observation.
24 Either entity_id or value_template should be non-None.
29 prob_given_true: float
30 prob_given_false: float
34 value_template: Template |
None
35 observed: bool |
None =
None
37 id: uuid.UUID = field(default_factory=uuid.uuid4)
39 def to_dict(self) -> dict[str, str | float | bool | None]:
40 """Represent Class as a Dict for easier serialization."""
44 CONF_PLATFORM: self.
platformplatform,
45 CONF_ENTITY_ID: self.entity_id,
46 CONF_VALUE_TEMPLATE: self.
templatetemplate,
47 CONF_TO_STATE: self.to_state,
48 CONF_ABOVE: self.above,
49 CONF_BELOW: self.below,
50 CONF_P_GIVEN_T: self.prob_given_true,
51 CONF_P_GIVEN_F: self.prob_given_false,
52 "observed": self.observed,
55 for key, value
in dic.copy().items():
62 """Dectects whether given observation is a mirror of this one."""
65 and round(self.prob_given_true + other.prob_given_true, 1) == 1
66 and round(self.prob_given_false + other.prob_given_false, 1) == 1
71 """Not all observations have templates and we want to get template strings."""
72 if self.value_template
is not None:
73 return self.value_template.template
dict[str, str|float|bool|None] to_dict(self)
bool is_mirror(self, Observation other)