88 lines
1.7 KiB
Python
88 lines
1.7 KiB
Python
class Device:
|
|
def __init__(self, device_id: str, home: "Home") -> None:
|
|
self.device_id: str = device_id
|
|
self.home: Home = home
|
|
|
|
def trigger_change(self):
|
|
self.home.trigger_device_change(self.device_id)
|
|
|
|
|
|
class Home:
|
|
automations: list["Automation"]
|
|
|
|
def _get_device_behaviours_(self, device_id: str) -> list["Automation"]:
|
|
return [b for a in self.automations]
|
|
|
|
def trigger_device_change(self, device_id: str):
|
|
pass
|
|
|
|
|
|
class Behaviour:
|
|
def __init__(self) -> None:
|
|
self.action: function = None
|
|
self.rule: function = None
|
|
self.devices: list[str] = []
|
|
|
|
|
|
class Automation:
|
|
def __init__(self) -> None:
|
|
self.behaviours: list[Behaviour] = []
|
|
|
|
def device(self, device_id: str) -> dict:
|
|
return {"contrast": 3}
|
|
|
|
def trigger(self):
|
|
def decorator(func):
|
|
|
|
return func
|
|
return decorator
|
|
|
|
|
|
class PeopleCountEngineV1(Automation):
|
|
@Automation.trigger(
|
|
devices=["matrixclock"],
|
|
rule=lambda h: h.device("matrixclock").contrast == 6
|
|
)
|
|
def turn_light_on_sometimes(self, home: Home):
|
|
home.room("max").lights().on = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Automation.trigger(
|
|
people=["max"],
|
|
rule=lambda h: h.person("max").athome()
|
|
)
|
|
def turn_light_on_sometimes(self, home: Home):
|
|
home.room("max").lights().on = h.person("max").athome()
|
|
|
|
|
|
|
|
|
|
|
|
@Automation.state(h.room("Max").lights())
|
|
def max_room_light():
|
|
if max.ishome():
|
|
return "off"
|
|
|
|
scene = "Daylight scene"
|
|
|
|
if nighttime:
|
|
scene = "nighttime"
|
|
|
|
if max.working:
|
|
scene.dim(0.5)
|
|
|
|
return scene
|
|
|
|
|
|
|
|
from mash.mash import MaSH
|
|
|
|
mash = MaSH()
|
|
|
|
mash.add_automation(PeopleCountEngineV1())
|