42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from app_class import AppClass
|
|
from config import Config, TriggerTuple
|
|
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:
|
|
if self.__module__ == 'trigger':
|
|
raise TriggerImportError(
|
|
"the Trigger class can't used directly, but must be inherited in a trigger specific class"
|
|
)
|
|
_ , _name = self.__module__.split('.')
|
|
return _name
|
|
|
|
@property
|
|
def config(self) -> TriggerTuple:
|
|
_config = self._config.get_trigger_by_name(self.name)
|
|
if _config is None:
|
|
raise MissingConfig(f"Trigger {self.name} hasn't been properly configured")
|
|
return _config
|
|
|
|
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"
|
|
)
|
|
|