8000 Error connecting to L920-5 Smart LED Strip · Issue #1040 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Error connecting to L920-5 Smart LED Strip #1040

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
szabo-s-samuel opened this issue Jul 3, 2024 · 6 comments · Fixed by #1048
Closed

Error connecting to L920-5 Smart LED Strip #1040

szabo-s-samuel opened this issue Jul 3, 2024 · 6 comments · Fixed by #1048
Labels
bug Something isn't working
Milestone

Comments

@szabo-s-samuel
Copy link

I get an error when I try to connect to my TP-Link L920-5 Smart LED Strip with the kasa python CLI tool.
I first discovered the issue in Home Assistant's TP-Link Smart Home integration after upgrading to Core version 2024.7.0, so I started investigating, found the phython-kasa library, tried to use the kasa discover command and got exactly the same error as I got in Home Assistant.

Raised error: 'brightness'
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Python312\Scripts\kasa.exe\__main__.py", line 7, in <module>
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\anyio\_core\_eventloop.py", line 74, in run
    return async_backend.run(func, args, {}, backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\anyio\_backends\_asyncio.py", line 2034, in run
    return runner.run(wrapper())
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\anyio\_backends\_asyncio.py", line 2022, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 1120, in main
    rv = await self.invoke(ctx)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\kasa\cli.py", line 145, in invoke
    _handle_exception(self._debug, exc)
  File "C:\Python312\Lib\site-packages\kasa\cli.py", line 143, in invoke
    return await super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\asyncclick\core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "C:\Python312\Lib\site-packages\kasa\cli.py", line 515, in discover
    discovered_devices = await Discover.discover(
                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\kasa\discover.py", line 364, in discover
    await protocol.wait_for_discovery_to_complete()
  File "C:\Python312\Lib\site-packages\kasa\discover.py", line 190, in wait_for_discovery_to_complete
    await asyncio.gather(*self.callback_tasks)
  File "C:\Python312\Lib\site-packages\kasa\cli.py", line 503, in print_discovered
    await dev.update()
  File "C:\Python312\Lib\site-packages\kasa\smart\smartdevice.py", line 181, in update
    module._post_update_hook()
  File "C:\Python312\Lib\site-packages\kasa\smart\modules\lightpreset.py", line 45, in _post_update_hook
    brightness=preset_state["brightness"],
               ~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'brightness'
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001982F04A900>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001982F20E8D0>, 1165.781)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001982F075370>
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001982F17C6B0>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x000001982F20E930>, 1166.203)]']
connector: <aiohttp.connector.TCPConnector object at 0x000001982F28C3B0>

I already raised the issue at the Home Assistant side, but I thought I'll raise it here as well, I hope that is okay. Please let me know if you need any more information, I would gladly provide my help to resolve this issue! 😄

@sdb9696
Copy link
Collaborator
sdb9696 commented Jul 4, 2024

This is partially fixed in the current master branch but the light preset functionality will be disabled. To help with a full fix could you please run the dump_devinfo tool from the library checkout directory and upload the output?

python -m devtools.dump_devinfo --username YOUR_UN --password YOUR_PWD --host YOUR_IP inside the checkout directory

@szabo-s-samuel
Copy link
Author

Thanks! I am happy to help! 😄

Here is the result of the command:

PS> python -m "devtools.dump_devinfo" --username "[email]" --password "[password]" --host "192.168.0.209"
Host given, performing discovery on 192.168.0.209.
Testing component_nego call ..OK
Testing  device..Testing SmartCall(module='device', request=SmartRequest(get_device_info), should_succeed=True, child_device_id='')..OK
Testing  device..Testing SmartCall(module='device', request=SmartRequest(get_device_usage), should_succeed=True, child_device_id='')..OK
Testing  device..Testing SmartCall(module='device', request=SmartRequest(get_auto_update_info), should_succeed=True, child_device_id='')..OK
Testing  light_strip_lighting_effect..Testing SmartCall(module='light_strip_lighting_effect', request=SmartRequest(get_lighting_effect), should_succeed=True, child_device_id='')..OK
Testing  firmware..Testing SmartCall(module='firmware', request=SmartRequest(get_fw_download_state), should_succeed=True, child_device_id='')..OK
Testing  firmware..Testing SmartCall(module='firmware', request=SmartRequest(get_latest_fw), should_succeed=True, child_device_id='')..OK
Testing  quick_setup..Testing SmartCall(module='quick_setup', request=SmartRequest(qs_component_nego), should_succeed=True, child_device_id='')..OK
Testing  inherit..Testing SmartCall(module='inherit', request=SmartRequest(get_inherit_info), should_succeed=True, child_device_id='')..OK
Testing  time..Testing SmartCall(module='time', request=SmartRequest(get_device_time), should_succeed=True, child_device_id='')..OK
Testing  wireless..Testing SmartCall(module='wireless', request=SmartRequest(get_wireless_scan_info), should_succeed=True, child_device_id='')..OK
Testing  schedule..Testing SmartCall(module='schedule', request=SmartRequest(get_schedule_rules), should_succeed=True, child_device_id='')..OK
Testing  schedule..Testing SmartCall(module='schedule', request=SmartRequest(get_next_event), should_succeed=True, child_device_id='')..OK
Testing  countdown..Testing SmartCall(module='countdown', request=SmartRequest(get_countdown_rules), should_succeed=True, child_device_id='')..OK
Testing  antitheft..Testing SmartCall(module='antitheft', request=SmartRequest(get_antitheft_rules), should_succeed=True, child_device_id='')..OK
Testing  cloud_connect..Testing SmartCall(module='cloud_connect', request=SmartRequest(get_connect_cloud_state), should_succeed=True, child_device_id='')..OK
Testing  preset..Testing SmartCall(module='preset', request=SmartRequest(get_preset_rules), should_succeed=True, child_device_id='')..OK
Testing  on_off_gradually..Testing SmartCall(module='on_off_gradually', request=SmartRequest(get_on_off_gradually_info), should_succeed=True, child_device_id='')..OK
Testing  segment..Testing SmartCall(module='segment', request=SmartRequest(get_device_segment), should_succeed=True, child_device_id='')..OK
Testing  segment_effect..Testing SmartCall(module='segment_effect', request=SmartRequest(get_segment_effect_rule), should_succeed=True, child_device_id='')..OK
Testing  temp_humidity_records..Testing SmartCall(module='temp_humidity_records', request=SmartRequest(get_temp_humidity_records), should_succeed=False, child_device_id='')..FAIL - EXPECTED
Testing  trigger_logs..Testing SmartCall(module='trigger_logs', request=SmartRequest(get_trigger_logs), should_succeed=False, child_device_id='')..FAIL - EXPECTED
Got 20 successes

And here is the device info file:
L920-5(EU)_1.0_1.1.3.json

@sdb9696
Copy link
Collaborator
sdb9696 commented Jul 4, 2024

Many thanks @szssamuel, that's really helpful.

I can see the issue is caused by some of your presets being "effects" rather than regular presets. Does the L920 let you save an effect as a preset somehow?

@szabo-s-samuel
Copy link
Author
szabo-s-samuel commented Jul 4, 2024

Yep! That's it! I can confirm that this is what causes the issue. 😁

I removed all effects from my presets in the Tapo application and tried running the kasa discover command again (with user, password and host params) and I could successfully connect to the device, with no error. I could even add back the device into Home Assistant without problems. 😄

To answer your question, yes, it is possible to set effects as presets in the Tapo application, it supports both the default ("Recommended") effects and custom ones. I have one custom effect that I named "Warm Aurora" (maybe you saw that in the device info file) that was also on my preset list, but removing that alone didn't resolve the issue, I had to remove all effects from the presets, and then the error no longer appeared.

@sdb9696 sdb9696 added the bug Something isn't working label Jul 4, 2024
@sdb9696 sdb9696 added this to the 0.7.1 milestone Jul 4, 2024
@sdb9696
Copy link
Collaborator
sdb9696 commented Jul 4, 2024

Ok that's great thanks @szssamuel. PR #1048 should fix the issue by excluding any of the lighting effects from the presets list (they should still be available as selectable effects via the CLI or the HA tile).

As the preset feature being disabled is not a major issue, we won't rush this fix into the next HA release. However as per the comment on home-assistant/core#121119 the fix we have put out will stop the whole device from failing like it currently is.

@szabo-s-samuel
Copy link
Author
szabo-s-samuel commented Jul 4, 2024

Awesome! Thank you @sdb9696 for the really fast fix and for the help! I'll keep my preset list without effects until the HA update is released.

rytilahti pushed a commit that referenced this issue Jul 4, 2024
Fixes the residual issues with the light preset module not handling
unexpected `lighting_effect` items in the presets list.

Completes the fixes started with PR
#1043 to fix
#1040, [HA
#121115](home-assistant/core#121115) and [HA
#121119](home-assistant/core#121119)

With this PR affected devices will no longer have the light preset
functionality disabled. As this is a new feature this does not warrant a
hotfix so will go into the next release.

Updated fixture for testing thanks to @szssamuel, many thanks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0