Files
py-eagle-mqtt/Docker/src/python/tHome/eagle/config.py
Evan Richardson a35d0cbb58
All checks were successful
Build and publish Image / build-and-push (push) Successful in 8s
Refactor config.py
2024-02-10 05:29:27 +00:00

41 lines
1.1 KiB
Python

"""Config file parsing."""
from .. import util
from ..util import config as C
# Config file section name and defaults.
configEntries = [
# ( name, converter function, default value )
C.Entry("httpPort", int, 22042),
C.Entry("mqttEnergy", str),
C.Entry("mqttPower", str),
C.Entry("logFile", util.path.expand),
C.Entry("logLevel", int, 20), # INFO
]
def parse(configDir, configFile='eagle.py'):
"""
Parse the configuration file.
Args:
configDir (str): The directory containing the configuration file.
configFile (str): The name of the configuration file.
Returns:
dict: The parsed configuration.
"""
return C.readAndCheck(configDir, configFile, configEntries)
def log(config, logFile=None):
"""
Get the logger configuration.
Args:
config (dict): The configuration dictionary.
logFile (str): The log file path.
Returns:
logger: The logger object.
"""
logFile = logFile or config['logFile']
return util.log.get("eagle", config['logLevel'], logFile)