{"record":{"id":"006e171c54296f76","repo":"home-assistant/core","slug":"the-bond-api-returned-an-error-calling-set-speed-b","errorCode":null,"errorMessage":"The bond API returned an error calling set_speed_belief for {self.entity_id}.  Code: {ex.code}  Message: {ex.message}","messagePattern":"The bond API returned an error calling set_speed_belief for (.+?)\\.  Code: (.+?)  Message: (.+?)","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/bond/fan.py","lineNumber":164,"sourceCode":"        _LOGGER.debug(\"async_set_speed_belief called with percentage %s\", speed)\n        if speed == 0:\n            await self.async_set_power_belief(False)\n            return\n\n        await self.async_set_power_belief(True)\n\n        bond_speed = math.ceil(percentage_to_ranged_value(self._speed_range, speed))\n        _LOGGER.debug(\n            \"async_set_percentage converted percentage %s to bond speed %s\",\n            speed,\n            bond_speed,\n        )\n        try:\n            await self._bond.action(\n                self._device_id, Action.set_speed_belief(bond_speed)\n            )\n        except ClientResponseError as ex:\n            raise HomeAssistantError(\n                \"The bond API returned an error calling set_speed_belief for\"\n                f\" {self.entity_id}.  Code: {ex.code}  Message: {ex.message}\"\n            ) from ex\n\n    @override\n    async def async_turn_on(\n        self,\n        percentage: int | None = None,\n        preset_mode: str | None = None,\n        **kwargs: Any,\n    ) -> None:\n        \"\"\"Turn on the fan.\"\"\"\n        _LOGGER.debug(\"Fan async_turn_on called with percentage %s\", percentage)\n\n        if preset_mode is not None:\n            await self.async_set_preset_mode(preset_mode)\n        elif percentage is not None:\n            await self.async_set_percentage(percentage)","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/bond/fan.py#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"Speed command during hub token mismatch (401), device unpaired (404), or any API error — then the bad ex.code reference corrupts the reported failure.","solutions":["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).","Decode the underlying status from logs: 401 → re-authenticate the integration; 404 → re-add the device; 5xx → retry after the hub recovers.","Update Home Assistant — if a newer release already corrects the ex.code typo, upgrade instead of patching locally."],"exampleFix":"// before\nraise HomeAssistantError(\n    \"The bond API returned an error calling set_speed_belief for\"\n    f\" {self.entity_id}.  Code: {ex.code}  Message: {ex.message}\"\n) from ex\n// after\nraise HomeAssistantError(\n    \"The bond API returned an error calling set_speed_belief for\"\n    f\" {self.entity_id}.  Code: {ex.status}  Message: {ex.message}\"\n) from ex","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    await fan.async_set_speed_belief(speed)\nexcept HomeAssistantError as err:\n    # note: handler formats ex.code (nonexistent); real status may be masked.\n    # check logs for the underlying ClientResponseError if the message looks broken\n    ...","preventionTips":["Patch or upgrade the integration so the handler uses ex.status (ex.code raises AttributeError).","Verify the requested percentage maps into the device's supported speed range before sending.","Watch logs for AttributeError inside this handler — it indicates error 465 fired."],"tags":["bond","fan","http","bug","home-assistant"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}