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: class Appliance:
_FILTERS = {
"default": "^(?!iot_(?:recipe|guided))\\S+$",
"recipe": "iot_recipe_",
"guided": "iot_guided_",
}
def __init__(self): def __init__(self):
filters = ["receipt", "standard, special"] filters = list(self._FILTERS.values())
data = {'defaultValue': filters[0], 'enumValues': filters} data = {"defaultValue": filters[0], "enumValues": filters}
self._program_filter = HonParameterEnum("program_filter", data) self._program_filter = HonParameterEnum("program_filter", data)
def data(self, data): def data(self, data):
@ -12,5 +18,6 @@ class Appliance:
def settings(self, settings): def settings(self, settings):
settings["program_filter"] = self._program_filter 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 return settings

View File

@ -1,3 +1,6 @@
import re
class HonParameter: class HonParameter:
def __init__(self, key, attributes): def __init__(self, key, attributes):
self._key = key self._key = key
@ -138,4 +141,8 @@ class HonParameterProgram(HonParameterEnum):
@property @property
def values(self): 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)