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

Fixes an AttributeError: PlugStatus object has no attribute current #59

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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