Skip to content

Commit

Permalink
Prettier settings and status for genericmiot
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Jan 9, 2023
1 parent 74577e4 commit 407afaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions miio/device.py
Expand Up @@ -88,6 +88,7 @@ def __init__(
self._info: Optional[DeviceInfo] = None
self._actions: Optional[Dict[str, ActionDescriptor]] = None
timeout = timeout if timeout is not None else self.timeout
self._debug = debug
self._protocol = MiIOProtocol(
ip, token, start_id, debug, lazy_discover, timeout
)
Expand Down
35 changes: 19 additions & 16 deletions miio/integrations/genericmiot/genericmiot.py
@@ -1,7 +1,7 @@
import logging
from enum import Enum
from functools import partial
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional, Union, cast

import click

Expand Down Expand Up @@ -47,17 +47,10 @@ def pretty_status(result: "GenericMiotStatus"):
out += f", {prop.pretty_input_constraints}"
out += ")"

if prop.choices is not None: # TODO: hide behind verbose flag?
out += (
" (from: "
+ ", ".join([f"{c.description} ({c.value})" for c in prop.choices])
+ ")"
)

if prop.range is not None: # TODO: hide behind verbose flag?
out += (
f" (min: {prop.range[0]}, max: {prop.range[1]}, step: {prop.range[2]})"
)
if result.device._debug > 1:
out += "\n\t[bold]Extras[/bold]\n"
for extra_key, extra_value in prop.extras.items():
out += f"\t\t{extra_key} = {extra_value}\n"

out += "\n"

Expand All @@ -76,11 +69,21 @@ def pretty_actions(result: Dict[str, ActionDescriptor]):
def pretty_settings(result: Dict[str, SettingDescriptor]):
"""Pretty print settings."""
out = ""
verbose = False
service = None
for _, desc in result.items():
out += f"# {desc.id} ({desc.name})"
out += f' urn: {repr(desc.extras["urn"])}\n'
out += f' siid: {desc.extras["siid"]}\n'
out += f' piid: {desc.extras["piid"]}\n'
miot_prop: MiotProperty = desc.extras["miot_property"]
# service is marked as optional due pydantic backrefs..
serv = cast(MiotService, miot_prop.service)
if service is None or service.siid != serv.siid:
service = serv
out += f"[bold]{service.name}[/bold] ({service.description})\n"

out += f"\t{desc.name} ({desc.id}, access: {miot_prop.pretty_access})\n"
if verbose:
out += f' urn: {repr(desc.extras["urn"])}\n'
out += f' siid: {desc.extras["siid"]}\n'
out += f' piid: {desc.extras["piid"]}\n'

return out

Expand Down

0 comments on commit 407afaf

Please sign in to comment.