Fix SwitchBot Blind Tilt KeyError on idle BLE advertisements#172816
Fix SwitchBot Blind Tilt KeyError on idle BLE advertisements#172816frenck wants to merge 1 commit into
Conversation
|
Hey there @Danielhiversen, @RenierM26, @murtas, @Eloston, @dsypniewski, @zerzhang, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Fixes a KeyError: 'motionDirection' raised on every BLE advertisement for idle SwitchBot Blind Tilt devices by replacing direct dict access with the device's is_opening() / is_closing() helpers, matching the pattern already used by other cover entities in the same module.
Changes:
- Replace
self.parsed_data["motionDirection"][...]withself._device.is_opening()/is_closing()inSwitchBotBlindTiltEntity._handle_coordinator_update. - Add a regression test that injects an idle advertisement (no
motionDirection) and asserts the entity remains available.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/switchbot/cover.py | Use device helpers instead of dict access to avoid KeyError on idle advertisements. |
| tests/components/switchbot/test_cover.py | New test verifying blind tilt entity survives BLE advertisement lacking motionDirection. |
| with patch( | ||
| "homeassistant.components.switchbot.cover.switchbot.SwitchbotBlindTilt.get_basic_info", | ||
| return_value=info_idle, | ||
| ): |
There was a problem hiding this comment.
Please correct me if I am wrong, but isn't this the same patch as on L405? Nothing really changed to info_idle so this statement doesn't really do much
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Proposed change
SwitchBotBlindTiltEntity._handle_coordinator_updatecrashes withKeyError: 'motionDirection'on every BLE advertisement when the blind tilt is idle, because idle devices don't include themotionDirectionkey in their parsed BLE data.Use
self._device.is_opening()/self._device.is_closing()instead of direct dict access, matching the pattern used by all other SwitchBot cover entities in the same file (SwitchBotCurtainEntity,SwitchBotRollerShadeEntity, etc.).Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: