From c4d21be3882e800e579afb44be3086faccc47486 Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Wed, 8 Mar 2023 21:53:53 +0100 Subject: [PATCH] Print all keys --- pyhon/__main__.py | 10 +++++++--- pyhon/appliances/wm.py | 1 + pyhon/device.py | 7 +++++++ setup.py | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pyhon/__main__.py b/pyhon/__main__.py index ba63ae6..2c60c90 100755 --- a/pyhon/__main__.py +++ b/pyhon/__main__.py @@ -24,6 +24,7 @@ def get_arguments(): subparser = parser.add_subparsers(title="commands", metavar="COMMAND") keys = subparser.add_parser("keys", help="print as key format") keys.add_argument("keys", help="print as key format", action="store_true") + keys.add_argument("--all", help="print also full keys", action="store_true") return vars(parser.parse_args()) @@ -90,9 +91,12 @@ async def main(): for device in hon.devices: print("=" * 10, device.appliance_type, "-", device.nick_name, "=" * 10) if args.get("keys"): - key_print(device.data["attributes"]["parameters"]) - key_print(device.data["appliance"]) - key_print(device.data) + data = device.data.copy() + attr = "get" if args.get("all") else "pop" + key_print(data["attributes"].__getattribute__(attr)("parameters")) + key_print(data.__getattribute__(attr)("appliance")) + key_print(data.__getattribute__(attr)("commands")) + key_print(data) pretty_print(create_command(device.commands, concat=True)) else: pretty_print({"data": device.data}) diff --git a/pyhon/appliances/wm.py b/pyhon/appliances/wm.py index 83300ec..259d808 100644 --- a/pyhon/appliances/wm.py +++ b/pyhon/appliances/wm.py @@ -5,4 +5,5 @@ class Appliance: def get(self): if self._data["attributes"]["lastConnEvent"]["category"] == "DISCONNECTED": self._data["attributes"]["parameters"]["machMode"] = "0" + self._data["active"] = bool(self._data.get("activity")) return self._data diff --git a/pyhon/device.py b/pyhon/device.py index e8e69d0..0836a98 100644 --- a/pyhon/device.py +++ b/pyhon/device.py @@ -33,6 +33,13 @@ class HonDevice: return self.data[item] return self.attributes["parameters"].get(item, self.appliance[item]) + def get(self, item, default=None): + try: + return self[item] + except KeyError | IndexError: + return default + + @property def appliance_model_id(self): return self._appliance.get("applianceModelId") diff --git a/setup.py b/setup.py index ad3106d..442e1c2 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.3.0", + version="0.3.1", author="Andre Basche", description="Control hOn devices with python", long_description=long_description,