From 10c8d961c4a2fd4722a10f3bb722791f839a4e0a Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 2 Oct 2023 01:38:40 +0200 Subject: [PATCH] Support new style rules hon#112 --- .github/workflows/python-check.yml | 2 +- pyhon/commands.py | 8 +++++--- pyhon/parameter/base.py | 5 +++-- pyhon/rules.py | 9 +++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml index 3d6f17c..00027a2 100644 --- a/.github/workflows/python-check.yml +++ b/.github/workflows/python-check.yml @@ -34,7 +34,7 @@ jobs: mypy pyhon/ - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + pylint $(git ls-files '*.py') - name: Check black style run: | black . --check diff --git a/pyhon/commands.py b/pyhon/commands.py index b671e55..a305d78 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -102,10 +102,12 @@ class HonCommand: if name == "zoneMap" and self._appliance.zone: data["default"] = self._appliance.zone if data.get("category") == "rule": - if "fixedValue" not in data: - _LOGGER.error("Rule not supported: %s", data) - else: + if "fixedValue" in data: self._rules.append(HonRuleSet(self, data["fixedValue"])) + elif "enumValues" in data: + self._rules.append(HonRuleSet(self, data["enumValues"])) + else: + _LOGGER.warning("Rule not supported: %s", data) match data.get("typology"): case "range": self._parameters[name] = HonParameterRange(name, data, parameter) diff --git a/pyhon/parameter/base.py b/pyhon/parameter/base.py index 4d70051..5d93b29 100644 --- a/pyhon/parameter/base.py +++ b/pyhon/parameter/base.py @@ -68,8 +68,9 @@ class HonParameter: self._triggers.setdefault(value, []).append((func, data)) def check_trigger(self, value: str | float) -> None: - if str(value) in self._triggers: - for trigger in self._triggers[str(value)]: + triggers = {str(k).lower(): v for k, v in self._triggers.items()} + if str(value).lower() in triggers: + for trigger in triggers[str(value)]: func, args = trigger func(args) diff --git a/pyhon/rules.py b/pyhon/rules.py index 57d6de5..4a1a314 100644 --- a/pyhon/rules.py +++ b/pyhon/rules.py @@ -56,6 +56,11 @@ class HonRuleSet: extra[trigger_key] = trigger_value for extra_key, extra_data in param_data.items(): self._parse_conditions(param_key, extra_key, extra_data, extra) + else: + param_data = {"typology": "fixed", "fixedValue": param_data} + self._create_rule( + param_key, trigger_key, trigger_value, param_data, extra + ) def _create_rule( self, @@ -102,6 +107,10 @@ class HonRuleSet: param.values = [str(value)] param.value = str(value) elif isinstance(param, HonParameterRange): + if float(value) < param.min: + param.min = float(value) + elif float(value) > param.max: + param.max = float(value) param.value = float(value) return param.value = str(value)