mirror of
https://github.com/Andre0512/pyhOn.git
synced 2024-11-28 00:10:50 +01:00
Support new style rules hon#112
This commit is contained in:
parent
61dd470588
commit
10c8d961c4
2
.github/workflows/python-check.yml
vendored
2
.github/workflows/python-check.yml
vendored
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user