8000 KeyError: 'emeter' when discovering · Issue #302 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

KeyError: 'emeter' when discovering #302

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

Closed
greg713 opened this issue Jan 31, 2022 · 5 comments · Fixed by #303
Closed

KeyError: 'emeter' when discovering #302

greg713 opened this issue Jan 31, 2022 · 5 comments · Fixed by #303

Comments

@greg713
Copy link
greg713 commented Jan 31, 2022

Hello,

I have installed this on several machines, and all of them seem to be returning the same error when scanning for devices:

No host name given, trying discovery..
Discovering devices on 255.255.255.255 for 3 seconds
== Living Room Floor Lamp - HS110(US) ==
        Host: 192.168.88.187
        Device state: ON

        == Generic information ==
        Time:         2022-01-31 17:14:11
        Hardware:     1.0
        Software:     1.2.6 Build 200727 Rel.121701
        MAC (rssi):   50:C7:BF:4D:44:DF (-48)
        Location:     {'latitude': 29.931202, 'longitude': -95.263188}

        == Device specific information ==
        LED state: True
        On since: 2022-01-31 22:54:54.048137


        == Current State ==
Traceback (most recent call last):
  File "/usr/local/bin/kasa", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/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.9/dist-packages/anyio/_core/_eventloop.py", line 56, in run
    return asynclib.run(func, *args, **backend_options)
  File "/usr/local/lib/python3.9/dist-packages/anyio/_backends/_asyncio.py", line 233, in run
    return native_run(wrapper(), debug=debug)
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/anyio/_backends/_asyncio.py", line 228, in wrapper
    return await func(*args)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 1153, in _main
    return await main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 1074, in main
    rv = await self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 1662, in invoke
    await super().invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 1420, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 774, in invoke
    rv = await rv
  File "/usr/local/lib/python3.9/dist-packages/kasa/cli.py", line 82, in cli
    await ctx.invoke(discover)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 774, in invoke
    rv = await rv
  File "/usr/local/lib/python3.9/dist-packages/kasa/cli.py", line 162, in discover
    await ctx.invoke(state)
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 774, in invoke
    rv = await rv
  File "/usr/local/lib/python3.9/dist-packages/asyncclick/core.py", line 774, in invoke
    rv = await rv
  File "/usr/local/lib/python3.9/dist-packages/kasa/cli.py", line 231, in state
    emeter_status = dev.emeter_realtime
  File "/usr/local/lib/python3.9/dist-packages/kasa/smartdevice.py", line 87, in wrapped
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/kasa/smartdevice.py", line 432, in emeter_realtime
    return EmeterStatus(self._last_update[self.emeter_type]["get_realtime"])
KeyError: 'emeter'

It does partially return the information for one device and if I directly specify that device I can turn it on / off. Does not seem to matter if I run it under my name or root. Package installed with pip on all machines.

@LitBomb
Copy link
LitBomb commented Jan 31, 2022

Are you on Windows? I see this on as well when I run kasa discover. I reported this in issue 294 https://github.com/python-kasa/python-kasa/issues/294

@greg713
Copy link
Author
greg713 commented Jan 31, 2022

Are you on Windows? I see this on as well when I run kasa discover. I reported this in issue 294 https://github.com/python-kasa/python-kasa/issues/294

Error is from a Debian 11 VM, but have also tried it on Ubuntu 21 and WSL. Same error.

@LitBomb
Copy link
LitBomb commented Jan 31, 2022

Great. Good to know this is not Windows-specific. Thanks.

@apassemard
Copy link
apassemard commented Feb 1, 2022

Getting the same error on Mac just now.
Python 2.7.18
on Monterey

@rytilahti
Copy link
Member

This is a regression caused by #132. I'll create a patch to the cli tool to perform a full update, but the emeter accesses should likely be guarded by a check to raise an exception if the information is not available.

rytilahti added a commit to rytilahti/python-kasa that referenced this issue Mar 21, 2022
This is the last release prior restructuring the code to enable easier extendability by moving towards more modular architecture.
The most prominent change in this release is the support for effects on light strips.

[Full Changelog](python-kasa/python-kasa@0.4.1...0.4.2)

**Implemented enhancements:**

- Allow environment variables for discovery target, device type and debug [\python-kasa#313](python-kasa#313) (@rytilahti)
- Add 'internal\_state' to return the results from the last update query [\python-kasa#306](python-kasa#306) (@rytilahti)
- Drop microsecond precision for on\_since [\python-kasa#296](python-kasa#296) (@rytilahti)
- Add effect support for light strips [\python-kasa#293](python-kasa#293) (@bdraco)

**Fixed bugs:**

- TypeError: \_\_init\_\_\(\) got an unexpected keyword argument 'package\_name' [\python-kasa#311](python-kasa#311)
- RuntimeError: Event loop is closed on WSL [\python-kasa#294](python-kasa#294)
- Don't crash on devices not reporting features [\python-kasa#317](python-kasa#317) (@rytilahti)

**Closed issues:**

- SmartDeviceException: Communication error on system:set\_relay\_state [\python-kasa#309](python-kasa#309)
- Add Support: ES20M and KS200M motion/light switches [\python-kasa#308](python-kasa#308)
- New problem with installing on Ubuntu 20.04.3 LTS [\python-kasa#305](python-kasa#305)
- KeyError: 'emeter' when discovering [\python-kasa#302](python-kasa#302)
- RuntimeError: Event loop is closed  [\python-kasa#291](python-kasa#291)
- provisioning format [\python-kasa#290](python-kasa#290)
- Fix CI publishing on pypi [\python-kasa#222](python-kasa#222)
- LED strips effects are not supported \(was LEDs is not turning on after switching on\) [\python-kasa#191](python-kasa#191)

**Merged pull requests:**

- Add pyupgrade to CI runs [\python-kasa#314](python-kasa#314) (@rytilahti)
- Depend on asyncclick \>= 8 [\python-kasa#312](python-kasa#312) (@rytilahti)
- Guard emeter accesses to avoid keyerrors [\python-kasa#304](python-kasa#304) (@rytilahti)
- cli: cleanup discover, fetch update prior device access [\python-kasa#303](python-kasa#303) (@rytilahti)
- Fix unsafe \_\_del\_\_ in TPLinkSmartHomeProtocol [\python-kasa#300](python-kasa#300) (@bdraco)
- Improve typing for protocol class [\python-kasa#289](python-kasa#289) (@rytilahti)
- Added a fixture file for KS220M [\python-kasa#273](python-kasa#273) (@mrbetta)
rytilahti added a commit that referenced this issue Mar 21, 2022
This is the last release prior restructuring the code to enable easier extendability by moving towards more modular architecture.
The most prominent change in this release is the support for effects on light strips.

[Full Changelog](0.4.1...0.4.2)

**Implemented enhancements:**

- Allow environment variables for discovery target, device type and debug [\#313](#313) (@rytilahti)
- Add 'internal\_state' to return the results from the last update query [\#306](#306) (@rytilahti)
- Drop microsecond precision for on\_since [\#296](#296) (@rytilahti)
- Add effect support for light strips [\#293](#293) (@bdraco)

**Fixed bugs:**

- TypeError: \_\_init\_\_\(\) got an unexpected keyword argument 'package\_name' [\#311](#311)
- RuntimeError: Event loop is closed on WSL [\#294](#294)
- Don't crash on devices not reporting features [\#317](#317) (@rytilahti)

**Closed issues:**

- SmartDeviceException: Communication error on system:set\_relay\_state [\#309](#309)
- Add Support: ES20M and KS200M motion/light switches [\#308](#308)
- New problem with installing on Ubuntu 20.04.3 LTS [\#305](#305)
- KeyError: 'emeter' when discovering [\#302](#302)
- RuntimeError: Event loop is closed  [\#291](#291)
- provisioning format [\#290](#290)
- Fix CI publishing on pypi [\#222](#222)
- LED strips effects are not supported \(was LEDs is not turning on after switching on\) [\#191](#191)

**Merged pull requests:**

- Add pyupgrade to CI runs [\#314](#314) (@rytilahti)
- Depend on asyncclick \>= 8 [\#312](#312) (@rytilahti)
- Guard emeter accesses to avoid keyerrors [\#304](#304) (@rytilahti)
- cli: cleanup discover, fetch update prior device access [\#303](#303) (@rytilahti)
- Fix unsafe \_\_del\_\_ in TPLinkSmartHomeProtocol [\#300](#300) (@bdraco)
- Improve typing for protocol class [\#289](#289) (@rytilahti)
- Added a fixture file for KS220M [\#273](#273) (@mrbetta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0