From 9ee5dbc956352f6f845c36899ba8dd0930852fd7 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Sun, 23 Apr 2023 21:42:44 +0200 Subject: [PATCH] Get program name by prcode --- pyhon/appliance.py | 2 +- pyhon/appliances/dw.py | 3 +++ pyhon/appliances/ov.py | 3 +++ pyhon/appliances/td.py | 5 +++++ pyhon/appliances/wd.py | 3 +++ pyhon/appliances/wm.py | 3 +++ pyhon/parameter/program.py | 9 +++++++++ 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pyhon/appliance.py b/pyhon/appliance.py index defcf69..81aa040 100644 --- a/pyhon/appliance.py +++ b/pyhon/appliance.py @@ -33,7 +33,7 @@ class HonAppliance: try: self._extra = importlib.import_module( f"pyhon.appliances.{self.appliance_type.lower()}" - ).Appliance() + ).Appliance(self) except ModuleNotFoundError: self._extra = None diff --git a/pyhon/appliances/dw.py b/pyhon/appliances/dw.py index 62311bd..6992e11 100644 --- a/pyhon/appliances/dw.py +++ b/pyhon/appliances/dw.py @@ -1,4 +1,7 @@ class Appliance: + def __init__(self, appliance): + self.parent = appliance + def data(self, data): if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": data["attributes"]["parameters"]["machMode"] = "0" diff --git a/pyhon/appliances/ov.py b/pyhon/appliances/ov.py index bd42630..c6df1c0 100644 --- a/pyhon/appliances/ov.py +++ b/pyhon/appliances/ov.py @@ -1,4 +1,7 @@ class Appliance: + def __init__(self, appliance): + self.parent = appliance + def data(self, data): if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": data["attributes"]["parameters"]["temp"] = "0" diff --git a/pyhon/appliances/td.py b/pyhon/appliances/td.py index 42e4ecb..3ab1385 100644 --- a/pyhon/appliances/td.py +++ b/pyhon/appliances/td.py @@ -2,11 +2,16 @@ from pyhon.parameter.fixed import HonParameterFixed class Appliance: + def __init__(self, appliance): + self.parent = appliance + def data(self, 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" + program = int(data["attributes"]["parameters"]["prCode"]) + data["programName"] = self.parent.settings["startProgram.program"].ids[program] return data def settings(self, settings): diff --git a/pyhon/appliances/wd.py b/pyhon/appliances/wd.py index 8aac4fd..a60875a 100644 --- a/pyhon/appliances/wd.py +++ b/pyhon/appliances/wd.py @@ -1,4 +1,7 @@ class Appliance: + def __init__(self, appliance): + self.parent = appliance + def data(self, data): if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": data["attributes"]["parameters"]["machMode"] = "0" diff --git a/pyhon/appliances/wm.py b/pyhon/appliances/wm.py index 8aac4fd..a60875a 100644 --- a/pyhon/appliances/wm.py +++ b/pyhon/appliances/wm.py @@ -1,4 +1,7 @@ class Appliance: + def __init__(self, appliance): + self.parent = appliance + def data(self, data): if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": data["attributes"]["parameters"]["machMode"] = "0" diff --git a/pyhon/parameter/program.py b/pyhon/parameter/program.py index 219b658..80ff38a 100644 --- a/pyhon/parameter/program.py +++ b/pyhon/parameter/program.py @@ -31,3 +31,12 @@ class HonParameterProgram(HonParameterEnum): def values(self) -> List[str]: values = [v for v in self._programs if all(f not in v for f in self._FILTER)] return sorted(values) + + @property + def ids(self): + values = { + int(p.parameters["prCode"].value): n + for i, (n, p) in enumerate(self._programs.items()) + if "iot_" not in n and p.parameters.get("prCode") + } + return dict(sorted(values.items()))