Skip to content

Commit

Permalink
Improve info output (command to use, miot support)
Browse files Browse the repository at this point in the history
This will make it easier for users to find out which miiocli command is suitable
for their devices, as well as informing if miot is supported for genericmiot use.
  • Loading branch information
rytilahti committed Jan 8, 2023
1 parent 771b295 commit aefd7d6
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ class UpdateState(Enum):
Idle = "idle"


def _info_output(result):
"""Format the output for info command."""
s = f"Model: {result.model}\n"
s += f"Hardware version: {result.hardware_version}\n"
s += f"Firmware version: {result.firmware_version}\n"

from .devicefactory import DeviceFactory

cls = DeviceFactory.class_for_model(result.model)
dev = DeviceFactory.create(result.ip_address, result.token, force_generic_miot=True)
s += f"Supported using: {cls.__name__}\n"
s += f"Command: miiocli {cls.__name__.lower()} --ip {result.ip_address} --token {result.token}\n"
s += f"Supported by genericmiot: {dev.supports_miot()}"

return s


class Device(metaclass=DeviceGroupMeta):
"""Base class for all device implementations.
Expand Down Expand Up @@ -121,12 +138,7 @@ def raw_command(self, command, parameters):
return self.send(command, parameters)

@command(
default_output=format_output(
"",
"Model: {result.model}\n"
"Hardware version: {result.hardware_version}\n"
"Firmware version: {result.firmware_version}\n",
),
default_output=format_output(result_msg_fmt=_info_output),
skip_autodetect=True,
)
def info(self, *, skip_cache=False) -> DeviceInfo:
Expand Down

0 comments on commit aefd7d6

Please sign in to comment.