Files
sillyhome-future/app/core/handoff.py

33 lines
1.1 KiB
Python

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": [],
}
)