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

Problem execution zigbee2mqtt 1.40.2 #4

Open
jojeju9428 opened this issue Oct 27, 2024 · 2 comments
Open

Problem execution zigbee2mqtt 1.40.2 #4

jojeju9428 opened this issue Oct 27, 2024 · 2 comments

Comments

@jojeju9428
Copy link

Hello,

I am experiencing an issue running the script since version 1.40.2 of Zigbee2MQTT. Here are the errors encountered when launching the script:

Starting initialization
Looking for supported devices:
Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/etc/ansible/scripts/zigbee2mqtt_ota_updater/zigbee2mqtt-1/main.py", line 51, in on_message
    handle_devicelist(obj)
  File "/etc/ansible/scripts/zigbee2mqtt_ota_updater/zigbee2mqtt-1/main.py", line 84, in handle_devicelist
    if device["definition"]:
       ~~~~~~^^^^^^^^^^^^^^
KeyError: 'definition'

Thanks for help

@jojeju9428
Copy link
Author

jojeju9428 commented Oct 27, 2024

Resolved by modifying the code as follows.

def handle_devicelist(devicelist):
    print("Looking for supported devices:")
    global otadict, num_total
    for device in devicelist:
        # Vérifier si la clé "definition" est présente dans l'objet device
        if "definition" in device and device["definition"]:
            dev = OtaDevice(
                device["friendly_name"],
                device["ieee_address"],
                device["definition"]["supports_ota"],
                False,
                False,
                False,
            )
            otadict[dev.ieee_addr] = dev
            if dev.supports_ota:
                print(
                    f"  {dev.friendly_name} supports OTA Updates, checking for new updates"
                )
                num_total += 1
                check_for_update(dev)
        else:
            print(f"Device {device.get('friendly_name', 'unknown')} does not support OTA updates or lacks definition data.")

@svenalebrand
Copy link

Thank you, @jojeju9428! This helped me, too, especially the change from
if device["definition"]:
to
if "definition" in device and device["definition"]:

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

No branches or pull requests

2 participants