Skip to content

[BUG] Reloading the config entry unloads the whole integration when any product is missing #208

Description

@peshmann

Describe the bug

async_unload_entry unloads all six platforms unconditionally, but async_setup_entry only forwards the platforms that actually had devices. So whenever the Hive API returns fewer product types than PLATFORMS lists, unloading raises ValueError: Config entry was never loaded!, the unload fails, and the reload aborts leaving the integration completely unloaded — including the entities that were working perfectly.

The practical effect is that a config-entry reload only succeeds when the integration is already fully healthy, i.e. exactly when you don't need one. During any partial outage — which is when a user will reach for "Reload" — it takes the whole integration down instead.

custom_components/hive/__init__.py:

# setup: only the platforms that have devices
await hass.config_entries.async_forward_entry_setups(
    entry,
    [
        ha_type
        for ha_type, hive_type in PLATFORM_LOOKUP.items()
        if devices.get(hive_type)
    ],
)

# unload: all six, unconditionally
async def async_unload_entry(hass: HomeAssistant, entry: HiveConfigEntry) -> bool:
    return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

To Reproduce

  1. Have a setup where at least one product is not returned with valid state. In my case Hive's API returned both the heating and hot-water product nodes carrying error: MALFORMED_NODE_DESCRIPTOR, so createDevices() skipped them (session.py, if "error" in p: ... continue) and deviceList["climate"] / ["water_heater"] were empty.
  2. Restart HA. The sensor and binary_sensor platforms load fine; climate/water_heater/switch are never forwarded.
  3. Call homeassistant.reload_config_entry on the Hive entry.
  4. Every Hive entity disappears — including ones that were working.

Log:

ERROR (MainThread) [homeassistant.config_entries] Error unloading entry <account> for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1036, in async_unload
    result = await component.async_unload_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line ..., in async_unload_entry
    return await hass.data[DATA_COMPONENT].async_unload_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 201, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!

Same traceback repeated for switch and water_heater.

Expected behaviour

Unloading should only unload the platforms that were actually forwarded, so a reload is a no-op-or-better rather than a way to lose the integration. A failed unload of a never-loaded platform should not abort the reload.

Additional context

Before the reload, binary_sensor.hive_hub_status was on and sensor.<thermostat>_availability was reporting normally — those are built from the device node, which still parsed. After the reload both were restored: true / unavailable, i.e. the reload destroyed working entities. Recovery required a full Home Assistant restart; no amount of reloading helps.

A possible fix is to record what was forwarded and unload only that, e.g.:

entry.runtime_data.loaded_platforms = [...]           # what setup forwarded
...
async def async_unload_entry(hass, entry):
    return await hass.config_entries.async_unload_platforms(
        entry, entry.runtime_data.loaded_platforms
    )

Storing it on hass.data[DOMAIN][entry.entry_id] would work equally well. Happy to open a PR if you'd like it in a particular shape.

Versions

  • Home Assistant Core 2026.8.2 (HAOS)
  • Hive-Custom-Component 2026.8.0
  • pyhive-integration 1.0.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions