Auto register scene
This commit is contained in:
parent
b9fd9c40ae
commit
1a697ec828
@ -5,7 +5,7 @@ import systemd.journal
|
||||
|
||||
from citadel.mqtt import Configuration
|
||||
|
||||
from . import Sleep
|
||||
from .scene import Scene
|
||||
|
||||
def main(\
|
||||
mqtt_user: str = typer.Option(... , envvar="SCENE_MQTT_USER"),\
|
||||
@ -38,8 +38,7 @@ def main(\
|
||||
host = mqtt_host
|
||||
port = mqtt_port
|
||||
|
||||
scene = Sleep(Config)
|
||||
scene.start()
|
||||
Scene.enable_all(Config)
|
||||
|
||||
if __name__ == "__main__":
|
||||
typer.run(main)
|
||||
|
@ -35,6 +35,18 @@ class Scene(threading.Thread, mqtt.Client):
|
||||
STATE_ACTIVATE = 1
|
||||
STATE_ACTIVATING = 2
|
||||
|
||||
__implemented_scenes = []
|
||||
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__(**kwargs)
|
||||
cls.__implemented_scenes.append(cls)
|
||||
|
||||
@classmethod
|
||||
def enable_all(cls, config: Configuration, logger: logging.Logger=None):
|
||||
for scene in cls.__implemented_scenes:
|
||||
s = scene(config, logger)
|
||||
s.start()
|
||||
|
||||
def __init__(self, config: Configuration, logger: logging.Logger=None):
|
||||
threading.Thread.__init__(self)
|
||||
mqtt.Client.__init__(self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user