Skip to content

Divide by zero when HS300 powerstrip is discovered #292

@sevendials

Description

@sevendials

kasa discover throws an error when discovering an HS300 smart strip however if kasa --host <ip address of HS300 smart strip> is run, no error is throw.

For debug, added print(self) to line 223 of smartstrip.py and found that self.children is empty when the device is discovered:

<DeviceType.Strip model HS300(US) at 192.168.1.118 (TP-LINK_Power Strip_DD06), is_on: False - dev specific: {'LED state': True, 'Childs count': 0, 'On since': None}>

but it is populated when an IP is specified:

<DeviceType.Strip model HS300(US) at 192.168.1.118 (TP-LINK_Power Strip_DD06), is_on: True - dev specific: {'LED state': True, 'Childs count': 6, 'On since': datetime.datetime(2022, 1, 10, 18, 40, 32, 272588)}>
	<EmeterStatus power=26.093 voltage=123.367 current=0.287 total=32.858>

Here is the start and end of the traceback:

Traceback (most recent call last):
  File "/home/depot/.local/bin/kasa", line 8, in <module>
    sys.exit(cli())
  File "/home/depot/.local/lib/python3.10/site-packages/asyncclick/core.py", line 1150, in __call__
    return anyio.run(self._main, main, args, kwargs, **({"backend":_anyio_backend} if _anyio_backend is not None else {}))
...
...
  File "/home/depot/.local/lib/python3.10/site-packages/kasa/smartstrip.py", line 229, in emeter_realtime
    emeter["voltage_mv"] = int(emeter["voltage_mv"] / len(self.children))
ZeroDivisionError: float division by zero

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions