Created
December 27, 2018 18:19
-
-
Save PeWu/8c146df8fbe94306f1ebcd362117960d to your computer and use it in GitHub Desktop.
Draft rewrite of https://github.com/danobot/appdaemon-motion-lights using https://github.com/PeWu/appdaemon-machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import appdaemon.plugins.hass.hassapi as hass | |
from enum import Enum | |
from machine import Machine, ANY, StateOn, StateOff, Timeout | |
class States(Enum): | |
DISABLED = 1 | |
IDLE = 2 | |
ACTIVE = 3 | |
globals().update(States.__members__) | |
DEFAULT_DELAY = 180 # seconds | |
class LightingSM(hass.Hass): | |
def initialize(self): | |
machine = Machine(self, States) | |
for e in self.args.get("overrides", []): | |
machine.add_transitions(ANY, StateOn(e), DISABLED) | |
machine.add_transition(DISABLED, StateOff(e), IDLE) | |
for e in self.args.get('sensors', []): | |
machine.add_transition( | |
IDLE, StateOn(e), ACTIVE, on_transition=self.on_enter_active) | |
# Self-transition resets the timer. | |
machine.add_transition(ACTIVE, StateOn(e), ACTIVE) | |
machine.add_transition( | |
ACTIVE, Timeout(DEFAULT_DELAY), IDLE, on_transition=self.on_exit_active) | |
def on_enter_active(self): | |
# TODO: Turn on lights | |
def on_exit_active(self): | |
# TODO: Turn off lights |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment