From 2597cbd8830e8011513d26f23ed0f111b9c2719a Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 9 Apr 2023 21:29:29 +0200 Subject: [PATCH] Use regex oven filters #9 --- pyhon/appliances/ov.py | 13 ++++++++++--- pyhon/parameter.py | 9 ++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pyhon/appliances/ov.py b/pyhon/appliances/ov.py index 0d3fe18..2fc63d7 100644 --- a/pyhon/appliances/ov.py +++ b/pyhon/appliances/ov.py @@ -2,9 +2,15 @@ from pyhon.parameter import HonParameterEnum class Appliance: + _FILTERS = { + "default": "^(?!iot_(?:recipe|guided))\\S+$", + "recipe": "iot_recipe_", + "guided": "iot_guided_", + } + def __init__(self): - filters = ["receipt", "standard, special"] - data = {'defaultValue': filters[0], 'enumValues': filters} + filters = list(self._FILTERS.values()) + data = {"defaultValue": filters[0], "enumValues": filters} self._program_filter = HonParameterEnum("program_filter", data) def data(self, data): @@ -12,5 +18,6 @@ class Appliance: def settings(self, settings): settings["program_filter"] = self._program_filter - settings["startProgram.program"].filter = self._program_filter.value + value = self._FILTERS[self._program_filter.value] + settings["startProgram.program"].filter = value return settings diff --git a/pyhon/parameter.py b/pyhon/parameter.py index 647fb5d..2e2d25b 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -1,3 +1,6 @@ +import re + + class HonParameter: def __init__(self, key, attributes): self._key = key @@ -138,4 +141,8 @@ class HonParameterProgram(HonParameterEnum): @property def values(self): - return sorted([str(value) for value in self._values if not self._filter or self._filter in str(value)]) + values = [] + for value in self._values: + if not self._filter or re.findall(self._filter, str(value)): + values.append(str(value)) + return sorted(values)