Use regex oven filters #9

This commit is contained in:
Andre Basche 2023-04-09 21:29:29 +02:00
parent 36079c3c77
commit 2597cbd883
2 changed files with 18 additions and 4 deletions

View file

@ -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

View file

@ -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)