cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1789: full source
This commit is contained in:
1 parent
94f46db8f8
commit
b24675fe9c
25 files changed
+766
-40
No files matched your search
@@ -172,10 +172,11 @@ class Guard:
|
||||
if entity not in tr.commanded:
|
||||
tr.commanded[entity] = (self.clock() - self.settle, value)
|
||||
|
||||
def observe(self, control_id: str, entity: str, value, now: float | None = None):
|
||||
def observe(self, control_id: str, entity: str, value, now: float | None = None, by: str = ""):
|
||||
"""A state change of a control's entity: if it differs from what the
|
||||
agent set, and not right after the agent set it, the owner changed
|
||||
it by hand."""
|
||||
it by hand. by: who changed it (changed_by), reported with the
|
||||
override."""
|
||||
now = self.clock() if now is None else now
|
||||
tr = self._t(control_id)
|
||||
cmd = tr.commanded.get(entity)
|
||||
@@ -191,7 +192,7 @@ class Guard:
|
||||
tr.override_entity = entity
|
||||
tr.commanded.pop(entity, None)
|
||||
self.events.append({"control": control_id, "entity": entity, "value": value, "agent_set": want,
|
||||
"until": int(tr.override_until), "at": int(now)})
|
||||
"until": int(tr.override_until), "at": int(now), "by": by})
|
||||
|
||||
def last_change(self, control_id: str, kind: str) -> float | None:
|
||||
"""When the agent last changed a control's mode or setpoint (kind
|
||||
@@ -202,6 +203,30 @@ class Guard:
|
||||
return self.clock() < self._t(control_id).override_until
|
||||
|
||||
|
||||
def changed_by(ctx) -> str:
|
||||
"""Who changed an entity, from Home Assistant's context of the new state
|
||||
(subscribe_entities sends it as "c": the context's id alone when it has
|
||||
no user and no parent, else {"id", "user_id", "parent_id"}):
|
||||
resident a person signed in to HA (its app or dashboard, the box's
|
||||
panel through HA): the context has a user
|
||||
automation an automation or script in HA: a parent context, no user
|
||||
device neither: the device or its integration reported the change
|
||||
itself (a button or dial on the device, its own app, its
|
||||
manual mode)
|
||||
"" no context reported (an older HA, a test)
|
||||
The agent's own calls never reach here as overrides: the guard skips a
|
||||
value it set itself."""
|
||||
if isinstance(ctx, str) and ctx:
|
||||
return "device"
|
||||
if isinstance(ctx, dict):
|
||||
if ctx.get("user_id"):
|
||||
return "resident"
|
||||
if ctx.get("parent_id"):
|
||||
return "automation"
|
||||
return "device" if ctx.get("id") else ""
|
||||
return ""
|
||||
|
||||
|
||||
def _same(a, b, tol: float = 0.26) -> bool:
|
||||
try:
|
||||
return abs(float(a) - float(b)) < tol
|
||||
|
||||
Reference in new issue
Block a user