Skip to content
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

[Bug]: Exception in unpacking sub_devices_states #244

Closed
3 tasks
Lurker00 opened this issue May 20, 2024 · 1 comment
Closed
3 tasks

[Bug]: Exception in unpacking sub_devices_states #244

Lurker00 opened this issue May 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Lurker00
Copy link

Lurker00 commented May 20, 2024

LocalTuya Version

2024.5.0b2

Home Assistant Version

2024.5.3

Environment

  • Does the device work using the Home Assistant Tuya Cloud component?
  • Is this device connected to another local integration, including Home Assistant and any other tools?
  • The devices are within the same HA subnet, and they get discovered automatically when I add them

What happened?

After more than a day of running 2024.5.0b2, this exception happened 3 times in a row. I logged such an event, its output at the bottom.

I must have said before, BLE capable gateways have not only "offline" and "online" lists. But, from my understanding, it should not matter in the way you parse the replies. On the other hand, all my Python experience is a few lines in LocalTuya. Now I see I was wrong!

I just wonder why it didn't happen before, and is happening very often right now. I have 2 BLE-capable gateways!

The fix is:

            self.sub_devices_states["online"]  = list(set(cached_on_devs + on_devs))
            self.sub_devices_states["offline"] = list(set(cached_off_devs + off_devs))

without modifying data. But your current code:

if (data := decoded_message.get("data")) and isinstance(data, dict):
self.sub_devices_states.update(data)
listener = self.listener and self.listener()
if listener is None:
return
on_devices = data.get("online", [])
off_devices = data.get("offline", [])

looks safe, though does not take multiple replies into account yet. Nevertheless, I report this for your knowledge!

Steps to reproduce.

Have a BLE capable gateway, and Tuya BLE devices nearby.

Relevant log output

2024-05-20 20:07:27.817 ERROR (SyncWorker_10) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 831, in _action
on_devs, off_devs = self.sub_devices_states.values()
^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
2024-05-20 20:07:27.827 ERROR (SyncWorker_10) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 831, in _action
on_devs, off_devs = self.sub_devices_states.values()
^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
2024-05-20 20:07:28.078 ERROR (SyncWorker_10) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/localtuya/core/pytuya/__init__.py", line 831, in _action
on_devs, off_devs = self.sub_devices_states.values()
^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

2024-05-20 20:46:07.258 WARNING (MainThread) [custom_components.localtuya.core.pytuya] [bf8...m91] Sub-Devices States Update: {'online': ['uuid6e31ed40a28d', 'dc234fa888f2', 'dc234fa87afe', 'dc234fa884d6', '1b32dcd419e33784'], 'offline': [], 'nearby': ['1b32dcd419e33784', 'uuid6e31ed40a28d']}

2024-05-20 20:46:07.704 WARNING (MainThread) [custom_components.localtuya.core.pytuya] [bff...hco] Sub-Devices States Update: {'online': ['uuid03a62e05881c', 'a4c138f27b386d9f', 'a4c13831f2186b11', 'dc234fabe373', 'a4c138b123b8e31b', 'dc234f7258f6', '6c5cb1fffe9a6175', 'dc234f7bcd8e', 'a4c138a6806b370a'], 'offline': [], 'nearby': ['uuid03a62e05881c']}

Diagnostics information.

No response

@Lurker00 Lurker00 added the bug Something isn't working label May 20, 2024
@xZetsubou xZetsubou added the master/next-release Fixed in master branch, Will be ready in the next release label May 20, 2024
Copy link

This issue was closed because it was resolved on the release: 2024.5.0

@github-actions github-actions bot added stale and removed master/next-release Fixed in master branch, Will be ready in the next release stale labels May 26, 2024
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

No branches or pull requests

2 participants