Skip to content

Commit

Permalink
Get program name
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed May 29, 2023
1 parent a081ef1 commit 31c03fa
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 36 deletions.
6 changes: 5 additions & 1 deletion pyhon/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ async def _add_favourites(self):
command_name = command.get("commandName")
program_name = command.get("programName", "").split(".")[-1].lower()
base = copy(self._commands[command_name].categories[program_name])
for param, data in command.items():
for data in command.values():
if isinstance(data, str):
continue
for key, value in data.items():
if parameter := base.parameters.get(key):
with suppress(ValueError):
parameter.value = value
extra_param = HonParameterFixed("favourite", {"fixedValue": "1"}, "custom")
base.parameters.update(favourite=extra_param)
base.parameters["program"].set_value(name)
self._commands[command_name].categories[name] = base

Expand Down Expand Up @@ -296,6 +298,8 @@ def diagnose(self, whitespace=" ", command_only=False):
"statistics": self.statistics,
"additional_data": self._additional_data,
}
if self._extra and data.get("attributes"):
data = self._extra.data(data)
if command_only:
data.pop("attributes")
data.pop("appliance")
Expand Down
13 changes: 13 additions & 0 deletions pyhon/appliances/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ApplianceBase:
def __init__(self, appliance):
self.parent = appliance

def data(self, data):
program_name = "No Program"
if program := int(data["attributes"]["parameters"].get("prCode", "0")):
if ids := self.parent.settings["startProgram.program"].ids:
program_name = ids.get(program, program_name)
data["programName"] = program_name

def settings(self, settings):
return settings
10 changes: 4 additions & 6 deletions pyhon/appliances/dw.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class Appliance:
def __init__(self, appliance):
self.parent = appliance
from pyhon.appliances.base import ApplianceBase


class Appliance(ApplianceBase):
def data(self, data):
super().data(data)
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
return data

def settings(self, settings):
return settings
10 changes: 4 additions & 6 deletions pyhon/appliances/ov.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Appliance:
def __init__(self, appliance):
self.parent = appliance
from pyhon.appliances.base import ApplianceBase


class Appliance(ApplianceBase):
def data(self, data):
super().data(data)
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["temp"] = "0"
data["attributes"]["parameters"]["onOffStatus"] = "0"
Expand All @@ -16,6 +17,3 @@ def data(self, data):
data["programName"] = ids.get(program, "")

return data

def settings(self, settings):
return settings
11 changes: 3 additions & 8 deletions pyhon/appliances/ref.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from pyhon.parameter.fixed import HonParameterFixed
from pyhon.appliances.base import ApplianceBase


class Appliance:
def __init__(self, appliance):
self.parent = appliance

class Appliance(ApplianceBase):
def data(self, data):
super().data(data)
if data["attributes"]["parameters"]["holidayMode"] == "1":
data["modeZ1"] = "holiday"
elif data["attributes"]["parameters"]["intelligenceMode"] == "1":
Expand All @@ -23,6 +21,3 @@ def data(self, data):
data["modeZ2"] = "no_mode"

return data

def settings(self, settings):
return settings
10 changes: 3 additions & 7 deletions pyhon/appliances/td.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from pyhon.appliances.base import ApplianceBase
from pyhon.parameter.fixed import HonParameterFixed


class Appliance:
def __init__(self, appliance):
self.parent = appliance

class Appliance(ApplianceBase):
def data(self, data):
super().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"
if program := int(data["attributes"]["parameters"]["prCode"]):
ids = self.parent.settings["startProgram.program"].ids
data["programName"] = ids.get(program, "")
return data

def settings(self, settings):
Expand Down
7 changes: 4 additions & 3 deletions pyhon/appliances/wd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Appliance:
def __init__(self, appliance):
self.parent = appliance
from pyhon.appliances.base import ApplianceBase


class Appliance(ApplianceBase):
def data(self, data):
super().data(data)
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
Expand Down
7 changes: 4 additions & 3 deletions pyhon/appliances/wm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Appliance:
def __init__(self, appliance):
self.parent = appliance
from pyhon.appliances.base import ApplianceBase


class Appliance(ApplianceBase):
def data(self, data):
super().data(data)
if data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED":
data["attributes"]["parameters"]["machMode"] = "0"
data["active"] = bool(data.get("attributes", {}).get("activity"))
Expand Down
4 changes: 3 additions & 1 deletion pyhon/parameter/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def ids(self) -> Dict[int, str]:
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")
if "iot_" not in n
and p.parameters.get("prCode")
and not ((fav := p.parameters.get("favourite")) and fav.value == "1")
}
return dict(sorted(values.items()))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.11.3",
version="0.12.0",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand Down

0 comments on commit 31c03fa

Please sign in to comment.