From 43d61ab8530126c57a339e73f8cecc5a65666d6a Mon Sep 17 00:00:00 2001 From: Andre Basche Date: Mon, 6 Mar 2023 19:45:46 +0100 Subject: [PATCH] Show more command data --- pyhon/__main__.py | 14 +++++++++++++- pyhon/api.py | 4 ++-- pyhon/commands.py | 9 +++------ pyhon/device.py | 2 +- pyhon/parameter.py | 1 + setup.py | 4 ++-- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pyhon/__main__.py b/pyhon/__main__.py index 65cefb8..ac8971d 100755 --- a/pyhon/__main__.py +++ b/pyhon/__main__.py @@ -24,7 +24,7 @@ def get_arguments(): return vars(parser.parse_args()) -# yaml.dump() would be done the same, but needs an additional import... +# yaml.dump() would be done the same, but needs an additional dependency... def pretty_print(data, key="", intend=0, is_list=False): if type(data) is list: if key: @@ -47,6 +47,18 @@ def pretty_print(data, key="", intend=0, is_list=False): print(f"{' ' * intend}{'- ' if is_list else ''}{key}{': ' if key else ''}{data}") +def create_command(commands): + result = {} + for name, command in commands.items(): + result[name] = {} + for parameter, data in command.parameters.items(): + if data.typology == "enum": + result[name][parameter] = data.values + if data.typology == "range": + result[name][parameter] = {"min": data.min, "max": data.max, "step": data.step} + return result + + async def main(): args = get_arguments() if not (user := args["user"]): diff --git a/pyhon/api.py b/pyhon/api.py index 8979344..28d77cb 100644 --- a/pyhon/api.py +++ b/pyhon/api.py @@ -92,8 +92,8 @@ class HonConnection: } url = f"{const.API_URL}/commands/v1/context" async with self._session.get(url, params=params, headers=await self._headers) as response: - if response.status_code >= 400 and not loop: - _LOGGER.error("%s - Error %s - %s", url, response.status_code, await response.text) + if response.status >= 400 and not loop: + _LOGGER.error("%s - Error %s - %s", url, response.status, await response.text) await self.setup() return await self.load_attributes(device, loop=True) return (await response.json()).get("payload", {}) diff --git a/pyhon/commands.py b/pyhon/commands.py index 3ae90f3..4fda746 100644 --- a/pyhon/commands.py +++ b/pyhon/commands.py @@ -31,18 +31,15 @@ class HonCommand: @property def parameters(self): - result = {key: parameter.value for key, parameter in self._parameters.items()} - if self._multi: - result |= {"program": self._category} - return result + return self._parameters @property def ancillary_parameters(self): return {key: parameter.value for key, parameter in self._ancillary_parameters.items()} async def send(self): - return await self._connector.send_command(self._device, self._name, self.parameters, - self.ancillary_parameters) + parameters = {name: parameter.value for name, parameter in self._parameters} + return await self._connector.send_command(self._device, self._name, parameters, self.ancillary_parameters) def get_programs(self): return self._multi diff --git a/pyhon/device.py b/pyhon/device.py index 4966c63..bfdb3f5 100644 --- a/pyhon/device.py +++ b/pyhon/device.py @@ -162,7 +162,7 @@ class HonDevice: result = {} for name, command in self._commands.items(): for key, parameter in command.parameters.items(): - result[f"{name}.{key}"] = parameter + result[f"{name}.{key}"] = parameter.value return result async def load_attributes(self): diff --git a/pyhon/parameter.py b/pyhon/parameter.py index f1dcb36..ca14b43 100644 --- a/pyhon/parameter.py +++ b/pyhon/parameter.py @@ -113,6 +113,7 @@ class HonParameterProgram(HonParameterEnum): self._command = command self._value = command._category self._values = command._multi + self._typology = "enum" @property def value(self): diff --git a/setup.py b/setup.py index c5cfc0c..6eb2f9d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as f: setup( name="pyhOn", - version="0.2.5", + version="0.2.6", author="Andre Basche", description="Control hOn devices with python", long_description=long_description, @@ -23,7 +23,7 @@ setup( python_requires=">=3.10", install_requires=["aiohttp"], classifiers=[ - "Development Status :: 3 - Alpha", + "Development Status :: 4 - Beta", "Environment :: Console", "License :: OSI Approved :: MIT License", "Natural Language :: English",