Add oven and program filter

This commit is contained in:
Andre Basche 2023-04-08 04:06:36 +02:00
parent 6d40e73881
commit 36079c3c77
7 changed files with 59 additions and 28 deletions

16
pyhon/appliances/ov.py Normal file
View File

@ -0,0 +1,16 @@
from pyhon.parameter import HonParameterEnum
class Appliance:
def __init__(self):
filters = ["receipt", "standard, special"]
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
settings["startProgram.program"].filter = self._program_filter.value
return settings

View File

@ -1,10 +1,10 @@
class Appliance: class Appliance:
def __init__(self, data): def data(self, data):
self._data = data if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
return data
def get(self): def settings(self, settings):
if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": return settings
self._data["attributes"]["parameters"]["machMode"] = "0"
self._data["active"] = bool(self._data.get("attributes", {}).get("activity"))
self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3"
return self._data

View File

@ -1,10 +1,10 @@
class Appliance: class Appliance:
def __init__(self, data): def data(self, data):
self._data = data if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
return data
def get(self): def settings(self, settings):
if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": return settings
self._data["attributes"]["parameters"]["machMode"] = "0"
self._data["active"] = bool(self._data.get("attributes", {}).get("activity"))
self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3"
return self._data

View File

@ -1,10 +1,10 @@
class Appliance: class Appliance:
def __init__(self, data): def data(self, data):
self._data = data if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
data["pause"] = data["attributes"]["parameters"]["machMode"] == "3"
return data
def get(self): def settings(self, settings):
if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": return settings
self._data["attributes"]["parameters"]["machMode"] = "0"
self._data["active"] = bool(self._data.get("attributes", {}).get("activity"))
self._data["pause"] = self._data["attributes"]["parameters"]["machMode"] == "3"
return self._data

View File

@ -18,7 +18,7 @@ class HonDevice:
self._attributes = {} self._attributes = {}
try: try:
self._extra = importlib.import_module(f'pyhon.appliances.{self.appliance_type.lower()}') self._extra = importlib.import_module(f'pyhon.appliances.{self.appliance_type.lower()}').Appliance()
except ModuleNotFoundError: except ModuleNotFoundError:
self._extra = None self._extra = None
@ -124,6 +124,8 @@ class HonDevice:
for name, command in self._commands.items(): for name, command in self._commands.items():
for key, setting in command.settings.items(): for key, setting in command.settings.items():
result[f"{name}.{key}"] = setting result[f"{name}.{key}"] = setting
if self._extra:
return self._extra.settings(result)
return result return result
@property @property
@ -150,5 +152,5 @@ class HonDevice:
result = {"attributes": self.attributes, "appliance": self.appliance, "statistics": self.statistics, result = {"attributes": self.attributes, "appliance": self.appliance, "statistics": self.statistics,
**self.parameters} **self.parameters}
if self._extra: if self._extra:
return result | self._extra.Appliance(result).get() return self._extra.data(result)
return result return result

View File

@ -94,7 +94,7 @@ class HonParameterEnum(HonParameter):
@property @property
def values(self): def values(self):
return sorted([str(value) for value in self._values]) return [str(value) for value in self._values]
@property @property
def value(self): def value(self):
@ -115,6 +115,7 @@ class HonParameterProgram(HonParameterEnum):
self._value = command._program self._value = command._program
self._values = command._multi self._values = command._multi
self._typology = "enum" self._typology = "enum"
self._filter = ""
@property @property
def value(self): def value(self):
@ -126,3 +127,15 @@ class HonParameterProgram(HonParameterEnum):
self._command.set_program(value) self._command.set_program(value)
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
def values(self):
return sorted([str(value) for value in self._values if not self._filter or self._filter in str(value)])

View File

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup( setup(
name="pyhOn", name="pyhOn",
version="0.4.1", version="0.5.0",
author="Andre Basche", author="Andre Basche",
description="Control hOn devices with python", description="Control hOn devices with python",
long_description=long_description, long_description=long_description,