Show more command data

This commit is contained in:
Andre Basche 2023-03-06 19:45:46 +01:00
parent 79a121263f
commit 43d61ab853
6 changed files with 22 additions and 12 deletions

View file

@ -24,7 +24,7 @@ def get_arguments():
return vars(parser.parse_args()) 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): def pretty_print(data, key="", intend=0, is_list=False):
if type(data) is list: if type(data) is list:
if key: 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}") 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(): async def main():
args = get_arguments() args = get_arguments()
if not (user := args["user"]): if not (user := args["user"]):

View file

@ -92,8 +92,8 @@ class HonConnection:
} }
url = f"{const.API_URL}/commands/v1/context" url = f"{const.API_URL}/commands/v1/context"
async with self._session.get(url, params=params, headers=await self._headers) as response: async with self._session.get(url, params=params, headers=await self._headers) as response:
if response.status_code >= 400 and not loop: if response.status >= 400 and not loop:
_LOGGER.error("%s - Error %s - %s", url, response.status_code, await response.text) _LOGGER.error("%s - Error %s - %s", url, response.status, await response.text)
await self.setup() await self.setup()
return await self.load_attributes(device, loop=True) return await self.load_attributes(device, loop=True)
return (await response.json()).get("payload", {}) return (await response.json()).get("payload", {})

View file

@ -31,18 +31,15 @@ class HonCommand:
@property @property
def parameters(self): def parameters(self):
result = {key: parameter.value for key, parameter in self._parameters.items()} return self._parameters
if self._multi:
result |= {"program": self._category}
return result
@property @property
def ancillary_parameters(self): def ancillary_parameters(self):
return {key: parameter.value for key, parameter in self._ancillary_parameters.items()} return {key: parameter.value for key, parameter in self._ancillary_parameters.items()}
async def send(self): async def send(self):
return await self._connector.send_command(self._device, self._name, self.parameters, parameters = {name: parameter.value for name, parameter in self._parameters}
self.ancillary_parameters) return await self._connector.send_command(self._device, self._name, parameters, self.ancillary_parameters)
def get_programs(self): def get_programs(self):
return self._multi return self._multi

View file

@ -162,7 +162,7 @@ class HonDevice:
result = {} result = {}
for name, command in self._commands.items(): for name, command in self._commands.items():
for key, parameter in command.parameters.items(): for key, parameter in command.parameters.items():
result[f"{name}.{key}"] = parameter result[f"{name}.{key}"] = parameter.value
return result return result
async def load_attributes(self): async def load_attributes(self):

View file

@ -113,6 +113,7 @@ class HonParameterProgram(HonParameterEnum):
self._command = command self._command = command
self._value = command._category self._value = command._category
self._values = command._multi self._values = command._multi
self._typology = "enum"
@property @property
def value(self): def value(self):

View file

@ -7,7 +7,7 @@ with open("README.md", "r") as f:
setup( setup(
name="pyhOn", name="pyhOn",
version="0.2.5", version="0.2.6",
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,
@ -23,7 +23,7 @@ setup(
python_requires=">=3.10", python_requires=">=3.10",
install_requires=["aiohttp"], install_requires=["aiohttp"],
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 4 - Beta",
"Environment :: Console", "Environment :: Console",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Natural Language :: English", "Natural Language :: English",