Smartstrip: return on_since state information only when the socket is on (#161)

* Smartstrip: return on_since state information only when the socket is on

Fixes #160

* add proper cli printout for hs300 child sockets

* iterate over range, not an integer
This commit is contained in:
Teemu R 2019-03-16 21:32:59 +01:00 committed by GitHub
parent 8046c96b54
commit 960ec6a346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -129,6 +129,15 @@ def state(ctx, dev):
click.echo(click.style("Device state: %s" % "ON" if dev.is_on else "OFF",
fg="green" if dev.is_on else "red"))
if dev.num_children > 0:
is_on = dev.is_on()
aliases = dev.get_alias()
for child in range(dev.num_children):
click.echo(
click.style(" * %s state: %s" %
(aliases[child],
"ON" if is_on[child] else "OFF"),
fg="green" if is_on[child] else "red"))
click.echo("Host/IP: %s" % dev.host)
for k, v in dev.state_information.items():
click.echo("%s: %s" % (k, v))

View File

@ -88,6 +88,7 @@ class SmartDevice(object):
self.protocol = protocol
self.emeter_type = "emeter" # type: str
self.context = context
self.num_children = 0
def _query_helper(self,
target: str,

View File

@ -204,8 +204,12 @@ class SmartStrip(SmartPlug):
"""
state = {'LED state': self.led}
on_since = self.on_since()
is_on = self.is_on()
for plug_index in range(self.num_children):
state['Plug %d on since' % (plug_index + 1)] = on_since[plug_index]
plug_number = plug_index + 1
if is_on[plug_index]:
state['Plug %d on since' % plug_number] = on_since[plug_index]
return state
def get_emeter_realtime(self, *, index: int = -1) -> Optional[Any]: