mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
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:
parent
8046c96b54
commit
960ec6a346
@ -129,6 +129,15 @@ def state(ctx, dev):
|
|||||||
|
|
||||||
click.echo(click.style("Device state: %s" % "ON" if dev.is_on else "OFF",
|
click.echo(click.style("Device state: %s" % "ON" if dev.is_on else "OFF",
|
||||||
fg="green" if dev.is_on else "red"))
|
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)
|
click.echo("Host/IP: %s" % dev.host)
|
||||||
for k, v in dev.state_information.items():
|
for k, v in dev.state_information.items():
|
||||||
click.echo("%s: %s" % (k, v))
|
click.echo("%s: %s" % (k, v))
|
||||||
|
@ -88,6 +88,7 @@ class SmartDevice(object):
|
|||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
self.emeter_type = "emeter" # type: str
|
self.emeter_type = "emeter" # type: str
|
||||||
self.context = context
|
self.context = context
|
||||||
|
self.num_children = 0
|
||||||
|
|
||||||
def _query_helper(self,
|
def _query_helper(self,
|
||||||
target: str,
|
target: str,
|
||||||
|
@ -204,8 +204,12 @@ class SmartStrip(SmartPlug):
|
|||||||
"""
|
"""
|
||||||
state = {'LED state': self.led}
|
state = {'LED state': self.led}
|
||||||
on_since = self.on_since()
|
on_since = self.on_since()
|
||||||
|
is_on = self.is_on()
|
||||||
for plug_index in range(self.num_children):
|
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
|
return state
|
||||||
|
|
||||||
def get_emeter_realtime(self, *, index: int = -1) -> Optional[Any]:
|
def get_emeter_realtime(self, *, index: int = -1) -> Optional[Any]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user