several fixes

This commit is contained in:
2024-12-11 08:58:29 +01:00
parent 383f8dc893
commit b875102d34
6 changed files with 22 additions and 14 deletions
+3 -3
View File
@@ -3,8 +3,8 @@ from config import Config
class AppClass: class AppClass:
def __init__(self, _config: Config, testmode: bool = False) -> None: def __init__(self, _config: Config) -> None:
self.testmode = testmode
self._config = _config self._config = _config
self.log = getLogger(self.__class__.__name__, loglevel=_config.loglevel.upper()) self.log = getLogger(self.__class__.__name__, loglevel=_config.loglevel.upper())
self.log.info(f'initializing {self.__class__.__name__}') self.log.info(f'initializing {self.__class__.__name__}')
+4 -1
View File
@@ -1,8 +1,9 @@
#!/usr/bin/python3 #!/usr/bin/env python3
from pathlib import Path from pathlib import Path
from logger import getLogger from logger import getLogger
from mapping import trigger_mapping from mapping import trigger_mapping
from config import Config from config import Config
from governor import Governor
def main() -> None: def main() -> None:
@@ -16,6 +17,8 @@ def main() -> None:
triggers.append( triggers.append(
trigger_mapping[triggertuple.name](triggertuple.name, config) trigger_mapping[triggertuple.name](triggertuple.name, config)
) )
gov = Governor(config)
gov.cpufreq
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+9 -5
View File
@@ -5,18 +5,22 @@ from functools import cached_property
class Governor(AppClass): class Governor(AppClass):
def __init__(self, _config: Config, testmode: bool = False) -> None: def __init__(self, _config: Config) -> None:
super().__init__(_config, testmode) super().__init__(_config)
@cached_property @cached_property
def cpufreq(self) -> cpuFreq: def cpufreq(self) -> cpuFreq:
if self.testmode:
self.log.info("setting up governor in testmode")
return cpuFreq() return cpuFreq()
def set_governor(self, governor_name: str) -> None: 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) self.log.debug("setting governor to %s by using command self.cpufreq.set_governors(%s)", governor_name)
if self.testmode:
if self._config.testmode:
self.log.warning("application is running in testmode, governor not set") self.log.warning("application is running in testmode, governor not set")
return None return None
if governor_name not in self.cpufreq.available_governors:
self.log.error("governor %s not supported by cpu", governor_name)
return None
self.cpufreq.set_governors(governor_name) self.cpufreq.set_governors(governor_name)
+2 -1
View File
@@ -1 +1,2 @@
cpufreq==0.3.5
lxml==5.3.0
+2 -2
View File
@@ -2,8 +2,8 @@ from app_class import AppClass
from config import Config, TriggerTuple, MissingConfig from config import Config, TriggerTuple, MissingConfig
class Trigger(AppClass): class Trigger(AppClass):
def __init__(self, name: str, _config: Config, testmode: bool = False) -> None: def __init__(self, name: str, _config: Config) -> None:
super().__init__(_config, testmode) super().__init__(_config)
self.name = name self.name = name
@property @property
+2 -2
View File
@@ -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, testmode: bool = False) -> None: def __init__(self, name: str, _config: Config) -> None:
super().__init__(name, _config, testmode) super().__init__(name, _config)