From aefd7d69ed7fd6b984a17659b2102ec2a0ee8167 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sun, 8 Jan 2023 20:25:38 +0100 Subject: [PATCH] Improve info output (command to use, miot support) 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. --- miio/device.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/miio/device.py b/miio/device.py index 855a2d2d8..8f2509a03 100644 --- a/miio/device.py +++ b/miio/device.py @@ -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. @@ -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: