code optimizations
This commit is contained in:
@@ -14,6 +14,7 @@ async def main() -> None:
|
||||
log = getLogger('main', loglevel=config.loglevel.upper())
|
||||
if config.testmode:
|
||||
log.warning("starting in testmode, cpu adjustments have been disabled")
|
||||
|
||||
governor = Governor(config)
|
||||
scheduler = TriggerScheduler(config)
|
||||
for triggertuple in config.triggertuples:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<testMode>true</testMode>
|
||||
<triggers>
|
||||
<trigger>
|
||||
<name>Roon</name>
|
||||
<name>roon</name>
|
||||
<intervalInSeconds>2</intervalInSeconds>
|
||||
</trigger>
|
||||
</triggers>
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
from types import MappingProxyType
|
||||
from triggers.roon import RoonTrigger
|
||||
from triggers import RoonTrigger
|
||||
|
||||
_dict_mapping = {
|
||||
'Roon': RoonTrigger
|
||||
'roon': RoonTrigger
|
||||
}
|
||||
trigger_mapping = MappingProxyType(_dict_mapping)
|
||||
+2
-1
@@ -32,5 +32,6 @@ class TriggerScheduler(AppClass):
|
||||
try:
|
||||
while True:
|
||||
await asyncio.sleep(1) # Keep the main function alive
|
||||
except KeyboardInterrupt:
|
||||
except asyncio.exceptions.CancelledError:
|
||||
self.log.info("Exiting, stopping all triggers")
|
||||
await self.stop_triggers()
|
||||
|
||||
+15
-2
@@ -1,11 +1,24 @@
|
||||
from app_class import AppClass
|
||||
from config import Config, TriggerTuple, MissingConfig
|
||||
|
||||
|
||||
class TriggerImportError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Trigger(AppClass):
|
||||
def __init__(self, _config: Config) -> None:
|
||||
super().__init__(_config)
|
||||
self.name = "name has to be filled in inherited class and this name has to match the name from config file"
|
||||
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
if self.__module__ == 'trigger':
|
||||
raise TriggerImportError(
|
||||
"the Trigger class can't used directlty, but must be inhereted 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)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
__all__ = ["roon"]
|
||||
|
||||
from .roon import RoonTrigger
|
||||
@@ -4,7 +4,6 @@ from config import Config
|
||||
class RoonTrigger(Trigger):
|
||||
def __init__(self, _config: Config) -> None:
|
||||
super().__init__(_config)
|
||||
self.name = "Roon"
|
||||
|
||||
def run(self) -> bool:
|
||||
self.log.info("run check code")
|
||||
|
||||
Reference in New Issue
Block a user