-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AppSettings, set update interval (#104)
* AppSettings, set update interval * Add retry interval setting --------- Co-authored-by: Riccardo Briccola <riccardo.briccola.dev@gmail.com>
- Loading branch information
1 parent
f78d741
commit 3e77042
Showing
13 changed files
with
251 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# Class keys: | ||
KEY_ENTITY = "entity" | ||
KEY_WAREHOUSE = "warehouse" | ||
KEY_SETTINGS = "settings" | ||
|
||
CLASS_PATH = { | ||
KEY_ENTITY: "Entity/Deployments", | ||
KEY_WAREHOUSE: "Warehouse/Deployments" | ||
KEY_WAREHOUSE: "Warehouse/Deployments", | ||
KEY_SETTINGS: "Settings/Deployments" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from IoTuring.Configurator.MenuPreset import MenuPreset | ||
from IoTuring.Settings.Settings import Settings | ||
|
||
|
||
CONFIG_KEY_UPDATE_INTERVAL = "update_interval" | ||
CONFIG_KEY_RETRY_INTERVAL = "retry_interval" | ||
# CONFIG_KEY_SLOW_INTERVAL = "slow_interval" | ||
|
||
|
||
class AppSettings(Settings): | ||
"""Class that stores AppSettings, not related to a specifuc Entity or Warehouse """ | ||
NAME = "App" | ||
|
||
@classmethod | ||
def ConfigurationPreset(cls): | ||
preset = MenuPreset() | ||
|
||
preset.AddEntry(name="Main update interval in seconds", | ||
key=CONFIG_KEY_UPDATE_INTERVAL, mandatory=True, | ||
question_type="integer", default=10) | ||
|
||
preset.AddEntry(name="Connection retry interval in seconds", | ||
instruction="If broker is not available retry after this amount of time passed", | ||
key=CONFIG_KEY_RETRY_INTERVAL, mandatory=True, | ||
question_type="integer", default=1) | ||
|
||
|
||
# preset.AddEntry(name="Secondary update interval in minutes", | ||
# key=CONFIG_KEY_SLOW_INTERVAL, mandatory=True, | ||
# question_type="integer", default=10) | ||
|
||
return preset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from IoTuring.Configurator.ConfiguratorObject import ConfiguratorObject | ||
from IoTuring.Settings.SettingsManager import SettingsManager | ||
from IoTuring.Configurator.MenuPreset import BooleanAnswers | ||
|
||
|
||
class Settings(ConfiguratorObject): | ||
"""Base class for settings""" | ||
NAME = "Settings" | ||
|
||
@classmethod | ||
def GetFromSettingsConfigurations(cls, key: str): | ||
"""Get value from settings' saved configurations from SettingsManager | ||
Args: | ||
key (str): The CONFIG_KEY of the configuration | ||
Raises: | ||
Exception: If the key not found | ||
Returns: | ||
Any: The config value | ||
""" | ||
|
||
sM = SettingsManager() | ||
saved_config = sM.GetConfigOfType(cls) | ||
|
||
if saved_config.HasConfigKey(key): | ||
return saved_config.GetConfigValue(key) | ||
else: | ||
raise Exception( | ||
f"Can't find key {key} in SettingsManager configurations") | ||
|
||
@classmethod | ||
def GetTrueOrFalseFromSettingsConfigurations(cls, key: str) -> bool: | ||
"""Get boolean value from settings' saved configurations from SettingsManager | ||
Args: | ||
key (str): The CONFIG_KEY of the configuration | ||
Returns: | ||
bool: The config value | ||
""" | ||
|
||
value = cls.GetFromSettingsConfigurations(key).lower() | ||
return bool(value in BooleanAnswers.TRUE_ANSWERS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from IoTuring.Settings.Settings import Settings | ||
from IoTuring.Configurator.Configuration import SingleConfiguration | ||
|
||
from IoTuring.Logger.Logger import Singleton | ||
from IoTuring.Logger.LogObject import LogObject | ||
|
||
|
||
class SettingsManager(LogObject, metaclass=Singleton): | ||
"""Singleton for storing configurations of Settings""" | ||
|
||
def __init__(self) -> None: | ||
self.setting_configs = {} | ||
|
||
def AddSettings(self, setting_entities: list[Settings]) -> None: | ||
"""Add settings configuration | ||
Args: | ||
setting_entities (list[Settings]): The loaded settings classes | ||
""" | ||
for setting_entity in setting_entities: | ||
self.setting_configs[setting_entity.NAME] = setting_entity.configurations | ||
|
||
def GetConfigOfType(self, setting_class) -> SingleConfiguration: | ||
"""Get the configuration of a saved class. Raises exception if not found""" | ||
|
||
if setting_class.NAME in self.setting_configs: | ||
return self.setting_configs[setting_class.NAME] | ||
else: | ||
raise Exception(f"No settings config for {setting_class.NAME}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.