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 citadel.mqtt import Configuration
|
||||||
|
|
||||||
from . import Sleep
|
from .scene import Scene
|
||||||
|
|
||||||
def main(\
|
def main(\
|
||||||
mqtt_user: str = typer.Option(... , envvar="SCENE_MQTT_USER"),\
|
mqtt_user: str = typer.Option(... , envvar="SCENE_MQTT_USER"),\
|
||||||
@ -38,8 +38,7 @@ def main(\
|
|||||||
host = mqtt_host
|
host = mqtt_host
|
||||||
port = mqtt_port
|
port = mqtt_port
|
||||||
|
|
||||||
scene = Sleep(Config)
|
Scene.enable_all(Config)
|
||||||
scene.start()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
typer.run(main)
|
typer.run(main)
|
||||||
|
@ -35,6 +35,18 @@ class Scene(threading.Thread, mqtt.Client):
|
|||||||
STATE_ACTIVATE = 1
|
STATE_ACTIVATE = 1
|
||||||
STATE_ACTIVATING = 2
|
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):
|
def __init__(self, config: Configuration, logger: logging.Logger=None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
mqtt.Client.__init__(self)
|
mqtt.Client.__init__(self)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user