From b9c831427a2a43f5194c4d78d55c50bbc3619d52 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Tue, 5 Sep 2017 19:57:41 +0200 Subject: [PATCH] plug_cli updated. Fixes an AttributeError: 'PlugStatus' object has no attribute 'current'. --- mirobo/plug.py | 18 ++++++++++++++++-- mirobo/plug_cli.py | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mirobo/plug.py b/mirobo/plug.py index 5b8607ca7..0baf5c933 100644 --- a/mirobo/plug.py +++ b/mirobo/plug.py @@ -1,5 +1,9 @@ -from .device import Device +import logging from typing import Dict, Any, Optional +from collections import defaultdict +from .device import Device + +_LOGGER = logging.getLogger(__name__) class PlugStatus: @@ -53,4 +57,14 @@ def status(self): "get_prop", properties ) - return PlugStatus(dict(zip(properties, values))) + + properties_count = len(properties) + values_count = len(values) + if properties_count != values_count: + _LOGGER.debug( + "Count (%s) of requested properties does not match the " + "count (%s) of received values.", + properties_count, values_count) + + return PlugStatus( + defaultdict(lambda: None, zip(properties, values))) diff --git a/mirobo/plug_cli.py b/mirobo/plug_cli.py index 707ac3ea3..4f274acec 100644 --- a/mirobo/plug_cli.py +++ b/mirobo/plug_cli.py @@ -77,8 +77,8 @@ def status(dev: mirobo.Plug): return # bail out click.echo(click.style("Power: %s" % res.power, bold=True)) - click.echo("Temperature: %s %%" % res.temperature) - click.echo("Current: %s %%" % res.current) + click.echo("Temperature: %s" % res.temperature) + click.echo("Load (W): %s" % res.load_power) @cli.command()