Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve info output (command to use, miot support) #1660

Merged
merged 1 commit into from
Jan 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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