Remove filters, filter out recies #9
This commit is contained in:
parent
46ff9be4a2
commit
834f25a639
4 changed files with 17 additions and 42 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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"]))
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue