Skip to content

Commit

Permalink
Support new style rules hon#112
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Oct 1, 2023
1 parent ca6e6e2 commit 6a93f52
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions pyhon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ def _create_parameters(
if name == "zoneMap" and self._appliance.zone:
data["default"] = self._appliance.zone
if data.get("category") == "rule":
if "fixedValue" not in data:
_LOGGER.info("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)
Expand Down
5 changes: 3 additions & 2 deletions pyhon/parameter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ def add_trigger(
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)

Expand Down
9 changes: 9 additions & 0 deletions pyhon/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def _parse_conditions(
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,
Expand Down Expand Up @@ -102,6 +107,10 @@ def _apply_fixed(self, param: Parameter, value: str | float) -> None:
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)
Expand Down

0 comments on commit 6a93f52

Please sign in to comment.