FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Divide by zero when HS300 powerstrip is discovered · Issue #292 · python-kasa/python-kasa · GitHub

Repository navigation

Divide by zero when HS300 powerstrip is discovered #292

Closed

Description

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

Activity

  1. rytilahti commented on Jan 24, 2022

    Member

    Could you try and see if #149 fixes this problem?

  2. sevendials commented on Jan 25, 2022

    Author

    @rytilahti thanks for answering so quickly. It got further but threw another error:

    ...
    	== Device specific information ==
    	LED state: True
    	Childs count: 6
    	On since: 2022-01-10 18:42:30.001431
    
    
    	== Current State ==
    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/kasa/smartstrip.py", line 230, in emeter_realtime
        emeter = merge_sums([plug.emeter_realtime for plug in self.children])
      File "/home/depot/.local/lib/python3.10/site-packages/kasa/smartstrip.py", line 230, in <listcomp>
        emeter = merge_sums([plug.emeter_realtime for plug in self.children])
      File "/home/depot/.local/lib/python3.10/site-packages/kasa/smartdevice.py", line 87, in wrapped
        return f(*args, **kwargs)
      File "/home/depot/.local/lib/python3.10/site-packages/kasa/smartdevice.py", line 432, in emeter_realtime
        return EmeterStatus(self._last_update[self.emeter_type]["get_realtime"])
    KeyError: 'emeter'
    
  3. alex-the-fifth commented on Jan 27, 2022

    I am also getting that last error but I do not have an HS300:

    root@plum:~# kasa
    No host name given, trying discovery..
    Discovering devices on 255.255.255.255 for 3 seconds
    == server - HS110(US) ==
    	Host: 192.168.0.21
    	Device state: ON
    
    	== Generic information ==
    	Time:         2022-01-27 01:57:33
    	Hardware:     1.0
    	Software:     1.2.6 Build 200727 Rel.121701
    	MAC (rssi):   xx:xx:xx:xx:xx:xx (-59)
    	Location:     {'latitude': xx, 'longitude': -xx}
    
    	== Device specific information ==
    	LED state: True
    	On since: 2022-01-11 06:17:54.689730
    
    
    	== Current State ==
    Traceback (most recent call last):
      File "/usr/local/bin/kasa", line 8, in <module>
        sys.exit(cli())
      File "/usr/local/lib/python3.8/dist-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 "/usr/local/lib/python3.8/dist-packages/anyio/_core/_eventloop.py", line 56, in run
        return asynclib.run(func, *args, **backend_options)
      File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 233, in run
        return native_run(wrapper(), debug=debug)
      File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
        return future.result()
      File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 228, in wrapper
        return await func(*args)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 1153, in _main
        return await main(*args, **kwargs)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 1074, in main
        rv = await self.invoke(ctx)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 1662, in invoke
        await super().invoke(ctx)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 1420, in invoke
        return await ctx.invoke(self.callback, **ctx.params)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/usr/local/lib/python3.8/dist-packages/kasa/cli.py", line 82, in cli
        await ctx.invoke(discover)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/usr/local/lib/python3.8/dist-packages/kasa/cli.py", line 162, in discover
        await ctx.invoke(state)
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/usr/local/lib/python3.8/dist-packages/kasa/cli.py", line 231, in state
        emeter_status = dev.emeter_realtime
      File "/usr/local/lib/python3.8/dist-packages/kasa/smartdevice.py", line 87, in wrapped
        return f(*args, **kwargs)
      File "/usr/local/lib/python3.8/dist-packages/kasa/smartdevice.py", line 432, in emeter_realtime
        return EmeterStatus(self._last_update[self.emeter_type]["get_realtime"])
    KeyError: 'emeter'
    

    interestingly when I target the device individually it works fine:

    root@plum:~# kasa --host 192.168.0.21
    No --type defined, discovering..
    == server - HS110(US) ==
    	Host: 192.168.0.21
    	Device state: ON
    
    	== Generic information ==
    	Time:         2022-01-27 02:00:08
    	Hardware:     1.0
    	Software:     1.2.6 Build 200727 Rel.121701
    	MAC (rssi):   xx:xx:xx:xx:xx:xx (-63)
    	Location:     {'latitude': xx, 'longitude': xx}
    
    	== Device specific information ==
    	LED state: True
    	On since: 2022-01-11 06:17:51.949765
    
    
    	== Current State ==
    	<EmeterStatus power=121.211448 voltage=124.456682 current=0.980383 total=18.876>
    
  4. rytilahti commented on Feb 2, 2022

    Member

    The KeyError: 'emeter' will be fixed by #303, that is not directly related to this issue.

  5. fredg3 commented on Mar 9, 2022

    Any progress on this? I'm also experiencing this problem with my HS300. Here are my logs. Hopefully they're helpful, otherwise sorry about adding an unnecessary comment.

    Without targeting:

    fred@fred-server:~/.local$ kasa discover
    Discovering devices on 255.255.255.255 for 3 seconds
    == TP-LINK_Power Strip_7A2B - HS300(US) ==
            Host: 192.168.1.64
            Device state: OFF
    
            == Plugs ==
    
            == Generic information ==
            Time:         2022-03-09 11:28:51
            Hardware:     1.0
            Software:     1.0.19 Build 200224 Rel.090814
            MAC (rssi):   [REDACTED]
            Location:     [REDACTED]
    
            == Device specific information ==
            LED state: True
            Childs count: 0
            On since: None
    
    
            == Current State ==
    Traceback (most recent call last):
      File "/home/fred/.local/bin/kasa", line 8, in <module>
        sys.exit(cli())
      File "/home/fred/.local/lib/python3.8/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/fred/.local/lib/python3.8/site-packages/anyio/_core/_eventloop.py", line 56, in run
        return asynclib.run(func, *args, **backend_options)
      File "/home/fred/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 233, in run
        return native_run(wrapper(), debug=debug)
      File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
        return loop.run_until_complete(main)
      File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
        return future.result()
      File "/home/fred/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 228, in wrapper
        return await func(*args)
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 1153, in _main
        return await main(*args, **kwargs)
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 1074, in main
        rv = await self.invoke(ctx)
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 1684, in invoke
        return await _process_result(await sub_ctx.command.invoke(sub_ctx))
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 1420, in invoke
        return await ctx.invoke(self.callback, **ctx.params)
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/home/fred/.local/lib/python3.8/site-packages/kasa/cli.py", line 162, in discover
        await ctx.invoke(state)
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/home/fred/.local/lib/python3.8/site-packages/asyncclick/core.py", line 774, in invoke
        rv = await rv
      File "/home/fred/.local/lib/python3.8/site-packages/kasa/cli.py", line 231, in state
        emeter_status = dev.emeter_realtime
      File "/home/fred/.local/lib/python3.8/site-packages/kasa/smartdevice.py", line 87, in wrapped
        return f(*args, **kwargs)
      File "/home/fred/.local/lib/python3.8/site-packages/kasa/smartstrip.py", line 223, in emeter_realtime
        emeter["voltage_mv"] = int(emeter["voltage_mv"] / len(self.children))
    ZeroDivisionError: float division by zero
    

    Curiously, the "Device state" incorrectly shows 'OFF' when discovering without a target. Here it is working correctly when directly targeting the HS300:

    fred@fred-server:~/.local$ kasa --host 192.168.1.64
    No --type defined, discovering..
    == TP-LINK_Power Strip_7A2B - HS300(US) ==
            Host: 192.168.1.64
            Device state: ON
    
            == Plugs ==
            * Socket 'Plug 1' state: ON on_since: 2022-03-06 19:41:18.425558
            * Socket 'Plug 2' state: ON on_since: 2022-03-06 19:41:18.425739
            * Socket 'Plug 3' state: ON on_since: 2022-03-06 19:41:18.425891
            * Socket 'Plug 4' state: ON on_since: 2022-03-06 19:41:18.426042
            * Socket 'FRED-SERVER' state: ON on_since: 2022-03-06 19:41:18.426189
            * Socket 'Network Switch' state: ON on_since: 2022-03-06 19:41:18.426346
    
            == Generic information ==
            Time:         2022-03-09 11:42:35
            Hardware:     1.0
            Software:     1.0.19 Build 200224 Rel.090814
            MAC (rssi):   [REDACTED]
            Location:     [REDACTED]
    
            == Device specific information ==
            LED state: True
            Childs count: 6
            On since: 2022-03-06 19:41:18.430897
    
    
            == Current State ==
            <EmeterStatus power=39.8 voltage=122.908 current=0.378 total=96.5>
    
    
  6. rytilahti commented on Mar 9, 2022

    Member

    Did you already try it with the current master? The problem is that the device is not yet updated (on that first case, see Childs count: 0) which causes the divided by zero, but I thought that was already fixed as per my last comment..

  7. fredg3 commented on Mar 10, 2022

    Yes, my understanding is that I'm on the current master:

    fred@fred-server:~/.local$ kasa --version
    kasa, version 0.4.1
    
  8. fredg3 commented on Mar 23, 2022

    Since I last posted, version 0.4.2 has come out. I've updated to that version and the issue appears to be resolved! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL