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())
# 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"]):

View File

@ -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", {})

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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",