Skip to content

Commit

Permalink
Show more command data
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre0512 committed Mar 6, 2023
1 parent 79a1212 commit 43d61ab
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
14 changes: 13 additions & 1 deletion pyhon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"]):
Expand Down
4 changes: 2 additions & 2 deletions pyhon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ async def load_attributes(self, device: HonDevice, loop=False):
}
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", {})
Expand Down
9 changes: 3 additions & 6 deletions pyhon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ def _create_parameters(self, parameters):

@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
Expand Down
2 changes: 1 addition & 1 deletion pyhon/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def parameters(self):
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):
Expand Down
1 change: 1 addition & 0 deletions pyhon/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(self, key, command):
self._command = command
self._value = command._category
self._values = command._multi
self._typology = "enum"

@property
def value(self):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="pyhOn",
version="0.2.5",
version="0.2.6",
author="Andre Basche",
description="Control hOn devices with python",
long_description=long_description,
Expand All @@ -23,7 +23,7 @@
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",
Expand Down

0 comments on commit 43d61ab

Please sign in to comment.