Remove filters, filter out recies #9

This commit is contained in:
Andre Basche 2023-04-16 00:11:50 +02:00
parent 46ff9be4a2
commit 834f25a639
4 changed files with 17 additions and 42 deletions

View file

@ -148,7 +148,14 @@ class HonAppliance:
multi = {} multi = {}
for program, attr2 in attr.items(): for program, attr2 in attr.items():
program = program.split(".")[-1].lower() 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 multi[program] = cmd
commands[command] = cmd commands[command] = cmd
self._commands = commands self._commands = commands

View file

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

View file

@ -7,7 +7,9 @@ from pyhon.parameter import (
class HonCommand: 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._connector = connector
self._device = device self._device = device
self._name = name self._name = name
@ -84,7 +86,9 @@ class HonCommand:
if not self._programs: if not self._programs:
return self._get_settings_keys() return self._get_settings_keys()
result = [ 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"])) return list(set(result + ["program"]))

View file

@ -1,6 +1,3 @@
import re
def str_to_float(string): def str_to_float(string):
try: try:
return int(string) return int(string)
@ -14,7 +11,6 @@ class HonParameter:
self._category = attributes.get("category") self._category = attributes.get("category")
self._typology = attributes.get("typology") self._typology = attributes.get("typology")
self._mandatory = attributes.get("mandatory") self._mandatory = attributes.get("mandatory")
self._value = ""
@property @property
def key(self): def key(self):
@ -121,6 +117,8 @@ class HonParameterEnum(HonParameter):
class HonParameterProgram(HonParameterEnum): class HonParameterProgram(HonParameterEnum):
_FILTER = ["iot_recipe", "iot_guided"]
def __init__(self, key, command): def __init__(self, key, command):
super().__init__(key, {}) super().__init__(key, {})
self._command = command self._command = command
@ -140,18 +138,7 @@ class HonParameterProgram(HonParameterEnum):
else: else:
raise ValueError(f"Allowed values {self._values}") raise ValueError(f"Allowed values {self._values}")
@property
def filter(self):
return self._filter
@filter.setter
def filter(self, filter):
self._filter = filter
@property @property
def values(self): def values(self):
values = [] values = [v for v in self._values if all(f not in v for f in self._FILTER)]
for value in self._values:
if not self._filter or re.findall(self._filter, str(value)):
values.append(str(value))
return sorted(values) return sorted(values)