31 lines
1.0 KiB
Python
31 lines
1.0 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)
|
|
|
|
@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) -> 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"
|
|
)
|