home-assistant/core · error · HomeAssistantError

The bond API returned an error calling set_speed_belief for

Error message

The bond API returned an error calling set_speed_belief for {self.entity_id}.  Code: {ex.code}  Message: {ex.message}

What it means

Raised by BondFan.async_set_speed_belief when Action.set_speed_belief(bond_speed) fails with a ClientResponseError. Note: this handler formats ex.code, unlike every sibling handler which uses ex.status — aiohttp's ClientResponseError defines status (and message) but not code, so formatting this message may itself raise AttributeError and mask the real API error.

Source

Thrown at homeassistant/components/bond/fan.py:164

        _LOGGER.debug("async_set_speed_belief called with percentage %s", speed)
        if speed == 0:
            await self.async_set_power_belief(False)
            return

        await self.async_set_power_belief(True)

        bond_speed = math.ceil(percentage_to_ranged_value(self._speed_range, speed))
        _LOGGER.debug(
            "async_set_percentage converted percentage %s to bond speed %s",
            speed,
            bond_speed,
        )
        try:
            await self._bond.action(
                self._device_id, Action.set_speed_belief(bond_speed)
            )
        except ClientResponseError as ex:
            raise HomeAssistantError(
                "The bond API returned an error calling set_speed_belief for"
                f" {self.entity_id}.  Code: {ex.code}  Message: {ex.message}"
            ) from ex

    @override
    async def async_turn_on(
        self,
        percentage: int | None = None,
        preset_mode: str | None = None,
        **kwargs: Any,
    ) -> None:
        """Turn on the fan."""
        _LOGGER.debug("Fan async_turn_on called with percentage %s", percentage)

        if preset_mode is not None:
            await self.async_set_preset_mode(preset_mode)
        elif percentage is not None:
            await self.async_set_percentage(percentage)

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Fix the handler: use ex.status instead of ex.code so the real HTTP status is reported (this is a code defect in the integration).
  2. Decode the underlying status from logs: 401 → re-authenticate the integration; 404 → re-add the device; 5xx → retry after the hub recovers.
  3. Update Home Assistant — if a newer release already corrects the ex.code typo, upgrade instead of patching locally.

Example fix

// before
raise HomeAssistantError(
    "The bond API returned an error calling set_speed_belief for"
    f" {self.entity_id}.  Code: {ex.code}  Message: {ex.message}"
) from ex
// after
raise HomeAssistantError(
    "The bond API returned an error calling set_speed_belief for"
    f" {self.entity_id}.  Code: {ex.status}  Message: {ex.message}"
) from ex
Defensive patterns

Strategy: try-catch

Try / catch

try:
    await fan.async_set_speed_belief(speed)
except HomeAssistantError as err:
    # note: handler formats ex.code (nonexistent); real status may be masked.
    # check logs for the underlying ClientResponseError if the message looks broken
    ...

Prevention

When it happens

Trigger: Setting fan speed percentage (converted via percentage_to_ranged_value to a Bond speed 1..N) while the hub returns 4xx/5xx; also triggered whenever the exception handler runs, because ex.code does not exist on ClientResponseError.

Common situations: Speed command during hub token mismatch (401), device unpaired (404), or any API error — then the bad ex.code reference corrupts the reported failure.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/006e171c54296f76. Report an issue: GitHub.