Skip to content

fix: register ikea_bulb_device_set with registry_entry and handle connection errors with ConfigEntryNotReady#196

Open
pablotoledo wants to merge 6 commits intosanjoyg:mainfrom
pablotoledo:fix/ikea-bulb-device-set-and-config-entry-not-ready
Open

fix: register ikea_bulb_device_set with registry_entry and handle connection errors with ConfigEntryNotReady#196
pablotoledo wants to merge 6 commits intosanjoyg:mainfrom
pablotoledo:fix/ikea-bulb-device-set-and-config-entry-not-ready

Conversation

@pablotoledo
Copy link
Copy Markdown

Summary

Two related bugs that together caused the Dirigera integration to require multiple manual reloads before successfully loading after a Home Assistant restart. Both issues were reproduced and verified on a production HA 2025.10.3 instance with the integration running inside a Docker bridge network.


Bug 1: ikea_bulb_device_set crashes the hub event listener immediately after setup

Root cause

In light.py, ikea_bulb_device_set registers itself directly into the hub_event_listener device registry:

# Before (line 397)
hub_event_listener.register(self.unique_id, self)

All other entities (via base_classes.py) register a registry_entry wrapper:

hub_event_listener.register(id, registry_entry(self))

When sync_all_device_areas() iterates the device registry and calls registry_entry.entity, it works for all normal entities (because their registry value is a registry_entry object with an .entity property). But for ikea_bulb_device_set, the registry value is the entity itself — a LightEntity subclass with no .entity attribute — causing an immediate AttributeError.

Observed log errors

ERROR [custom_components.dirigera_platform.hub_event_listener] Failed to sync area for device 992c7af5-...: 'ikea_bulb_device_set' object has no attribute 'entity'
WARNING [custom_components.dirigera_platform.hub_event_listener] Failed to create listener or listener exited, will sleep 10 seconds before retrying

This crash happens on every startup that has bulbs grouped in a device set. Once the listener dies, the integration enters a broken state and all subsequent device polling fails.

Fix

# After (light.py line 397)
hub_event_listener.register(self.unique_id, registry_entry(self))

registry_entry is already imported in light.py from .hub_event_listener, so no import changes are needed.


Bug 2: async_setup_entry does not handle connection failures gracefully

Root cause

async_setup_entry calls make_devices() with no exception handling. If the hub is temporarily unreachable during HA startup (e.g., brief network unavailability in Docker bridge environments, hub booting up, any transient OS-level network error), the ConnectionError or OSError propagates uncaught.

Home Assistant interprets this as a permanent failure and marks the entry as setup_error — which has no automatic retry. The correct HA pattern for transient connection failures is to raise ConfigEntryNotReady, which triggers HA's built-in exponential backoff retry mechanism.

Observed behaviour

  • Entry state: setup_error (permanent, no retry)
  • Error in logs: [Errno 101] Network unreachable during get_scenes / get_blinds / get_lights calls within make_devices
  • Manual reload required every time

Fix

from homeassistant.exceptions import ConfigEntryNotReady

# In async_setup_entry:
try:
    await platform.make_devices(hass, hass_data[CONF_IP_ADDRESS], hass_data[CONF_TOKEN])
except (ConnectionError, OSError) as err:
    raise ConfigEntryNotReady(
        f"Cannot connect to IKEA Dirigera hub at {hass_data[CONF_IP_ADDRESS]}: {err}"
    ) from err

Results after both fixes

Tested on HA 2025.10.3, dirigera_platform installed via HACS, Dirigera hub at 192.168.0.80, HA running in Docker bridge network:

Scenario Before After
Integration state after reload setup_error (no retry) loaded in ~10s
ikea_bulb_device_set AttributeError Present on every startup Gone
Failed to create listener Triggered every startup Gone
Manual reloads needed ~20 0

Files changed

  • custom_components/dirigera_platform/light.py — 1 line changed
  • custom_components/dirigera_platform/__init__.py — 6 lines added

This fix was previously submitted and accepted in the nrbrt fork: nrbrt#13

Xavi Esteve and others added 6 commits February 13, 2026 19:48
VALLHORN and MYGGSPRAY expose multiple sub-devices (motion + illuminance)
with different IDs but the same relation_id. Using the raw device ID as
the HA device identifier caused each sub-device to appear separately.

Use relation_id as the HA device identifier so sibling sub-devices are
grouped under one device. Falls back to id for standalone devices.

Also resolves sub-device naming: when a sub-device has no custom_name,
it inherits the name from a sibling that does, avoiding garbled IDs.

Fixes nrbrt#7

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 this pull request may close these issues.

2 participants