improved trigger code

This commit is contained in:
2024-12-17 20:48:00 +01:00
parent 35c86ffbd3
commit 494ba80e88
6 changed files with 66 additions and 26 deletions
+17 -5
View File
@@ -6,6 +6,7 @@ from exceptions import MissingConfig, TriggerImportError
class Trigger(AppClass):
def __init__(self, _config: Config) -> None:
super().__init__(_config)
self.active: bool = False
@property
def name(self) -> str:
@@ -23,8 +24,19 @@ class Trigger(AppClass):
raise MissingConfig(f"Trigger {self.name} hasn't been properly configured")
return _config
def run(self) -> bool:
# return True if Trigger is valid
raise TriggerImportError(
"the Trigger class can't used directly, but must be inherited in a trigger specific class"
)
def run(self) -> None:
# this is the main function of the trigger class and has to stay active by using a while True loop
while True:
raise TriggerImportError(
"the Trigger class can't used directly, but must be inherited in a trigger specific class"
)
async def async_run(self) -> None:
# this is the main function of the trigger class and can be used to execute a callback function
while True:
raise TriggerImportError(
"the Trigger class can't used directly, but must be inherited in a trigger specific class"
)