-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from somakeit/239-have-a-missing-config-parser
239 have a missing config parser
- Loading branch information
Showing
7 changed files
with
129 additions
and
3 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
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,54 @@ | ||
from ulogging import uLogger | ||
import lib.config.config_template as config_template | ||
import config | ||
|
||
class ConfigManagement: | ||
""" | ||
Ensure config file contains all items in config_template and that the values are of the correct type. | ||
Apply defaults from config_template where values are missing in config. | ||
""" | ||
def __init__(self) -> None: | ||
self.log = uLogger("ConfigManagement") | ||
self.error_count = 0 | ||
|
||
def configure_error_handling(self) -> None: | ||
""" | ||
Register errors with the error handler for the configuration management module. | ||
""" | ||
from lib.error_handling import ErrorHandler | ||
self.error_handler = ErrorHandler("ConfigManagement") | ||
self.errors = { | ||
"CFG": "Config errors found, check logs" | ||
} | ||
|
||
for error_key, error_message in self.errors.items(): | ||
self.error_handler.register_error(error_key, error_message) | ||
|
||
return | ||
|
||
def check_config(self) -> int: | ||
self.log.info("Checking config file") | ||
|
||
for key in dir(config_template): | ||
if not hasattr(config, key): | ||
self.log.error(f"Missing config item in config.py: {key}, setting default value: {getattr(config_template, key)}") | ||
setattr(config, key, getattr(config_template, key)) | ||
self.error_count += 1 | ||
else: | ||
if not isinstance(getattr(config, key), type(getattr(config_template, key))) and getattr(config_template, key) is not None: | ||
self.log.error(f"Config item in config.py has incorrect type: {key}") | ||
setattr(config, key, getattr(config_template, key)) | ||
self.error_count += 1 | ||
|
||
self.log.info(f"Config file check complete. Errors encountered: {self.error_count}") | ||
|
||
if self.error_count > 0: | ||
self.log.error("Please correct the above errors in config.py and restart SMIBHID") | ||
return -1 | ||
|
||
return 0 | ||
|
||
def enable_error(self) -> None: | ||
self.error_handler.enable_error("CFG") | ||
|
||
return |
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,58 @@ | ||
## Logging | ||
# Level 0-4: 0 = Disabled, 1 = Critical, 2 = Error, 3 = Warning, 4 = Info | ||
LOG_LEVEL = 2 | ||
# Handlers: Populate list with zero or more of the following log output handlers (case sensitive): "Console", "File" | ||
LOG_HANDLERS = ["Console", "File"] | ||
# Max log file size in bytes, there will be a maximum of 2 files at this size created | ||
LOG_FILE_MAX_SIZE = 10240 | ||
|
||
## IO | ||
SPACE_OPEN_BUTTON = 12 | ||
SPACE_CLOSED_BUTTON = 13 | ||
SPACE_OPEN_LED = 15 | ||
SPACE_CLOSED_LED = 16 | ||
# Set to None if no relay/transistor is connected | ||
SPACE_OPEN_RELAY = None | ||
SPACE_OPEN_RELAY_ACTIVE_HIGH = True | ||
|
||
## WIFI | ||
WIFI_SSID = "" | ||
WIFI_PASSWORD = "" | ||
WIFI_COUNTRY = "GB" | ||
WIFI_CONNECT_TIMEOUT_SECONDS = 10 | ||
WIFI_CONNECT_RETRIES = 1 | ||
WIFI_RETRY_BACKOFF_SECONDS = 5 | ||
# Leave as none for MAC based unique hostname or specify a custom hostname string | ||
CUSTOM_HOSTNAME = None | ||
|
||
NTP_SYNC_INTERVAL_SECONDS = 86400 | ||
|
||
## Web host | ||
WEBSERVER_HOST = "" | ||
WEBSERVER_PORT = "80" | ||
|
||
## Space state | ||
# Set the space state poll frequency in seconds (>= 5), set to 0 to disable the state poll | ||
SPACE_STATE_POLL_FREQUENCY_S = 5 | ||
# How long to wait for button press to accept extra hours when opening space | ||
ADD_HOURS_INPUT_TIMEOUT = 3 | ||
|
||
## I2C | ||
SDA_PIN = 8 | ||
SCL_PIN = 9 | ||
I2C_ID = 0 | ||
|
||
## Displays - Populate driver list with connected displays from this supported list: ["LCD1602"] | ||
DISPLAY_DRIVERS = ["LCD1602"] | ||
# Scroll speed for text on displays in characters per second | ||
SCROLL_SPEED = 4 | ||
|
||
## RFID reader | ||
RFID_ENABLED = False | ||
RFID_SCK = 18 | ||
RFID_MOSI = 19 | ||
RFID_MISO = 16 | ||
RFID_RST = 21 | ||
RFID_CS = 17 | ||
|
||
ENABLE_UI_LOGGING_UPLOAD = False |
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