From 834f25a6392279da43c51a88910864c564437b8d Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 16 Apr 2023 00:11:50 +0200 Subject: [PATCH] Remove filters, filter out recies #9 --- pyhon/appliance.py | 9 ++++++++- pyhon/appliances/ov.py | 23 ----------------------- pyhon/commands.py | 8 ++++++-- pyhon/parameter.py | 19 +++---------------- 4 files changed, 17 insertions(+), 42 deletions(-) delete mode 100644 pyhon/appliances/ov.py diff --git a/pyhon/appliance.py b/pyhon/appliance.py index bf070ff..00e9716 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -148,7 +148,14 @@ class HonAppliance: multi = {} for program, attr2 in attr.items(): program = program.split(".")[-1].lower() - cmd = HonCommand(command, attr2, self._api, self, programs=multi, program_name=program) + cmd = HonCommand( + command, + attr2, + self._api, + self, + programs=multi, + program_name=program, + ) multi[program] = cmd commands[command] = cmd self._commands = commands diff --git a/pyhon/appliances/ov.py b/pyhon/appliances/ov.py deleted file mode 100644 index 2fc63d7..0000000 --- a/pyhon/appliances/ov.py +++ /dev/null @@ -1,23 +0,0 @@ -from pyhon.parameter import HonParameterEnum - - -class Appliance: - _FILTERS = { - "default": "^(?!iot_(?:recipe|guided))\\S+$", - "recipe": "iot_recipe_", - "guided": "iot_guided_", - } - - def __init__(self): - filters = list(self._FILTERS.values()) - data = {"defaultValue": filters[0], "enumValues": filters} - self._program_filter = HonParameterEnum("program_filter", data) - - def data(self, data): - return data - - def settings(self, settings): - settings["program_filter"] = self._program_filter - value = self._FILTERS[self._program_filter.value] - settings["startProgram.program"].filter = value - return settings diff --git a/pyhon/commands.py b/pyhon/commands.py index f9c47f2..06e7c2c 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -7,7 +7,9 @@ from pyhon.parameter import ( class HonCommand: - def __init__(self, name:str, attributes, connector, device, programs=None, program_name=""): + def __init__( + self, name: str, attributes, connector, device, programs=None, program_name="" + ): self._connector = connector self._device = device self._name = name @@ -84,7 +86,9 @@ class HonCommand: if not self._programs: return self._get_settings_keys() result = [ - key for cmd in self._programs.values() for key in self._get_settings_keys(cmd) + key + for cmd in self._programs.values() + for key in self._get_settings_keys(cmd) ] return list(set(result + ["program"])) diff --git a/pyhon/parameter.py b/pyhon/parameter.py index 853c521..5944991 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -1,6 +1,3 @@ -import re - - def str_to_float(string): try: return int(string) @@ -14,7 +11,6 @@ class HonParameter: self._category = attributes.get("category") self._typology = attributes.get("typology") self._mandatory = attributes.get("mandatory") - self._value = "" @property def key(self): @@ -121,6 +117,8 @@ class HonParameterEnum(HonParameter): class HonParameterProgram(HonParameterEnum): + _FILTER = ["iot_recipe", "iot_guided"] + def __init__(self, key, command): super().__init__(key, {}) self._command = command @@ -140,18 +138,7 @@ class HonParameterProgram(HonParameterEnum): else: raise ValueError(f"Allowed values {self._values}") - @property - def filter(self): - return self._filter - - @filter.setter - def filter(self, filter): - self._filter = filter - @property def values(self): - values = [] - for value in self._values: - if not self._filter or re.findall(self._filter, str(value)): - values.append(str(value)) + values = [v for v in self._values if all(f not in v for f in self._FILTER)] return sorted(values)