Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve config handling of invalid conditionals #81

Merged
merged 1 commit into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Development

* **Added**
* Config parser now considers required sections with defaults for all options to be
valid and will populate the section in the returned configuration.

* **Fixed**
* Config parser was reporting valid configuration for optional conditional sections
containing invalid values. Fixes problem 1 in [#80](https://github.com/CrazyIvan359/mqttany/issues/80).

## 0.12.0

### Major Core Rewrite
Expand Down
17 changes: 6 additions & 11 deletions mqttany/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,13 @@ def process_option(name, value, option, config):
return False

if condition_matched != False:
if value == "**NO DATA**" and option.get("type", None) == "section":
if option.get("required", True):
log.error("Missing required section '%s'", name)
return False
elif condition_matched:
log.trace("Descending into section '%s'", name)
section_valid, config[name] = parse_dict({}, option)
return True

elif isinstance(value, dict):
if isinstance(value, dict) or (
value == "**NO DATA**" and option.get("type", None) == "section"
):
log.trace("Descending into section '%s'", name)
section_valid, section_config = parse_dict(value, option)
section_valid, section_config = parse_dict(
{} if value == "**NO DATA**" else value, option
)
if not section_valid and option.get("required", True):
log.error("Required section '%s' is not valid", name)
return False
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/gpio/pin/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Function(enum.Enum):
},
CONF_KEY_COUNTER: {
"type": "section",
"required": False,
"conditions": [(CONF_KEY_PIN_MODE, "COUNTER")],
CONF_KEY_INTERVAL: {"default": 60, "type": int},
CONF_KEY_INTERRUPT: {
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/gpio/pin/digital.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
},
CONF_KEY_DIGITAL: {
"type": "section",
"required": False,
"conditions": [
(CONF_KEY_PIN_MODE, PinMode.INPUT),
(CONF_KEY_PIN_MODE, PinMode.OUTPUT),
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/i2c/device/mcp230xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Resistor(Enum):
CONF_KEY_MCP: OrderedDict(
[
("type", "section"),
("required", True),
(
"conditions",
[(CONF_KEY_DEVICE, "mcp23008"), (CONF_KEY_DEVICE, "mcp23017")],
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/led/array/e131.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
CONF_KEY_OUTPUT: {"selection": {"sacn": "sacn", "sACN": "sacn"}},
CONF_KEY_SACN: {
"type": "section",
"required": False,
"conditions": [(CONF_KEY_OUTPUT, "sacn")],
CONF_KEY_UNIVERSE: {"type": int, "default": 1},
CONF_KEY_ADDRESS: {"type": str, "default": None},
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/led/array/rpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
CONF_KEY_OUTPUT: {"selection": {"rpi": "rpi", "RPi": "rpi"}},
CONF_KEY_RPI: {
"type": "section",
"required": True,
"conditions": [(CONF_KEY_OUTPUT, "rpi")],
CONF_KEY_GPIO: {"type": int},
CONF_KEY_CHIP: {
Expand Down
1 change: 0 additions & 1 deletion mqttany/modules/onewire/device/ds18x20.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
CONF_OPTIONS = { # will be added to device section of core CONF_OPTIONS
CONF_KEY_DS18X20: {
"type": "section",
"required": False,
CONF_KEY_UNIT: {
"default": "C",
"selection": ["C", "c", "F", "f"],
Expand Down