Skip to content

Commit

Permalink
plug_cli updated. Fixes an AttributeError: 'PlugStatus' object has no…
Browse files Browse the repository at this point in the history
… attribute 'current'.
  • Loading branch information
syssi committed Sep 5, 2017
1 parent 5b66b09 commit b9c8314
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions mirobo/plug.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)))
4 changes: 2 additions & 2 deletions mirobo/plug_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b9c8314

Please sign in to comment.