home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.11k stars 29.79k forks source link

Error while setting up tradfri platform for light #114553

Closed 12xx12 closed 1 week ago

12xx12 commented 5 months ago

The problem

The tradfri Integration fails to load the light entities.

The error seems to be fixed in the pytradfri lib.

https://github.com/home-assistant-libs/pytradfri/issues/810

What version of Home Assistant Core has the issue?

core-2024.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tradfri

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tradfri/

Diagnostics information

config_entry-tradfri-757103ec9cbf17fefa7602fd67d65c74.json

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 609, in async_add_entities
    for entity in new_entities:
  File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 40, in <genexpr>
    TradfriLight(
  File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 64, in __init__
    super().__init__(
  File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 64, in __init__
    sw_version=info.firmware_version,
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pytradfri/device/__init__.py", line 177, in firmware_version
    return self.raw[ATTR_DEVICE_FIRMWARE_VERSION]
           ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '3'

Additional information

No response

home-assistant[bot] commented 5 months ago

tradfri documentation tradfri source

sldewit commented 5 months ago

Hello, I seem to have this same issue now after updating to 2024.4.1. However, if I restart the integration after some time it does seem to work. It seems to relate to my reported issue: #111821

sldewit commented 5 months ago

Today I did some additional checks and the problem for me seems to be caused by the fact that the firmware version is not known in the beginning in the Tradfri Gateway. And it seems that this integratrion fails if it doesn't report is.

For example my remotes don't show up as Sensors for the battery until the Tradfri app shows Firmware versions and I refresh the integration.

Before I also had issues when I had disconnected/offline devices when I tried to reconnect my Tradfri integration. I had to remove those devices from the gateway and then reload the integration.

sldewit commented 4 months ago

@frenck, I see there are some issues regarding Tradri integration that do not have an assignee. Also in the manifest file I see there is no code owner anymore. Is someone still monitoring these issues in the code?

dylaninbcky commented 4 months ago

Im having this issue as well. Like OP said they fixed it in the pytradfri lib. Can someone update the Home Assistant Core tradfri integration so that the device firmware is optional? after every reboot of home assistant my integration doesnt work for about a day

fraimondo commented 3 months ago

I guess that's is not that easy to update the pytradfri lib in Home Assistant Core, as this issue has been around for quite some time now.

The pytradfri guys just allowed the firmware version to be None.

My workaround was to open the terminal (add-on), connect to the docker container:

docker exec -it homeassistant /bin/bash

And the edit the file of the error:

vi /usr/local/lib/python3.12/site-packages/pytradfri/device/__init__.py

Go to line 177 and replace:

    return self.raw[ATTR_DEVICE_FIRMWARE_VERSION]

for :

    return self.raw.get(ATTR_DEVICE_FIRMWARE_VERSION, None)
issue-triage-workflows[bot] commented 2 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.