Bootstrap SillyHome Future v2 core
This commit is contained in:
32
app/core/handoff.py
Normal file
32
app/core/handoff.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.core.models import ControlProfile, HandoffMode
|
||||
|
||||
|
||||
class HandoffMatrix:
|
||||
def classify(self, profile: ControlProfile) -> HandoffMode:
|
||||
active_related = set(profile.related_automation_ids) - set(profile.paused_automation_ids)
|
||||
if profile.handoff_mode is HandoffMode.CONTROLLED and active_related:
|
||||
return HandoffMode.CONFLICT
|
||||
if profile.paused_automation_ids:
|
||||
return HandoffMode.CONTROLLED
|
||||
if profile.related_automation_ids:
|
||||
return HandoffMode.CANDIDATE
|
||||
return profile.handoff_mode
|
||||
|
||||
def assume_control(self, profile: ControlProfile) -> ControlProfile:
|
||||
return profile.model_copy(
|
||||
update={
|
||||
"handoff_mode": HandoffMode.CONTROLLED,
|
||||
"paused_automation_ids": list(profile.related_automation_ids),
|
||||
}
|
||||
)
|
||||
|
||||
def rollback(self, profile: ControlProfile) -> ControlProfile:
|
||||
return profile.model_copy(
|
||||
update={
|
||||
"handoff_mode": HandoffMode.ROLLBACK,
|
||||
"paused_automation_ids": [],
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user