added app_class and governor
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
from logger import getLogger
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
|
class AppClass:
|
||||||
|
def __init__(self, _config: Config, testmode: bool = False) -> None:
|
||||||
|
self.testmode = testmode
|
||||||
|
self._config = _config
|
||||||
|
self.log = getLogger(self.__class__.__name__, loglevel=_config.loglevel.upper())
|
||||||
|
self.log.info(f'initializing {self.__class__.__name__}')
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
from app_class import AppClass
|
||||||
|
from config import Config
|
||||||
|
from cpufreq import cpuFreq
|
||||||
|
from functools import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
class Governor(AppClass):
|
||||||
|
def __init__(self, _config: Config, testmode: bool = False) -> None:
|
||||||
|
super().__init__(_config, testmode)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def cpufreq(self) -> cpuFreq:
|
||||||
|
if self.testmode:
|
||||||
|
self.log.info("setting up governor in testmode")
|
||||||
|
return cpuFreq()
|
||||||
|
|
||||||
|
def set_governor(self, governor_name: str) -> None:
|
||||||
|
self.log.debug("setting governor to %s by using command self.cpufreq.set_governors(%s)", governor_name)
|
||||||
|
if self.testmode:
|
||||||
|
self.log.warning("application is running in testmode, governor not set")
|
||||||
|
return None
|
||||||
|
self.cpufreq.set_governors(governor_name)
|
||||||
+4
-8
@@ -1,12 +1,10 @@
|
|||||||
from logger import getLogger
|
from app_class import AppClass
|
||||||
from config import Config, TriggerTuple, MissingConfig
|
from config import Config, TriggerTuple, MissingConfig
|
||||||
|
|
||||||
class Trigger:
|
class Trigger(AppClass):
|
||||||
def __init__(self, name: str, _config: Config) -> None:
|
def __init__(self, name: str, _config: Config, testmode: bool = False) -> None:
|
||||||
|
super().__init__(_config, testmode)
|
||||||
self.name = name
|
self.name = name
|
||||||
self._config = _config
|
|
||||||
self.log = getLogger('trigger', loglevel=_config.loglevel.upper())
|
|
||||||
self.log.info(f'initializing {self.__class__.__name__}')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def config(self) -> TriggerTuple:
|
def config(self) -> TriggerTuple:
|
||||||
@@ -14,5 +12,3 @@ class Trigger:
|
|||||||
if _config is None:
|
if _config is None:
|
||||||
raise MissingConfig(f"Trigger {self.name} hasn't been properly configured")
|
raise MissingConfig(f"Trigger {self.name} hasn't been properly configured")
|
||||||
return _config
|
return _config
|
||||||
|
|
||||||
|
|
||||||
+2
-2
@@ -2,6 +2,6 @@ from trigger import Trigger
|
|||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
class RoonTrigger(Trigger):
|
class RoonTrigger(Trigger):
|
||||||
def __init__(self, name: str, _config: Config) -> None:
|
def __init__(self, name: str, _config: Config, testmode: bool = False) -> None:
|
||||||
super().__init__(name, _config)
|
super().__init__(name, _config, testmode)
|
||||||
|
|
||||||
Reference in New Issue
Block a user