Fix KeyError 'deviceType' in get_status for IR remote devices#44
Merged
SeraphicRav merged 1 commit intoApr 10, 2026
Conversation
The SwitchBot Cloud API returns an empty body for IR remote devices (the docstring on `get_status` already notes "No status for IR devices"), so the unwrapped response dict has no `deviceType` key. Since SeraphicCorp#42 introduced an unconditional `response["deviceType"]` lookup to detect Keypad devices, every coordinator backing an IR remote (and any other device whose status response omits `deviceType`) now raises `KeyError: 'deviceType'`. In Home Assistant this surfaces as the `switchbot_cloud` integration repeatedly failing to set up: File ".../switchbot_api/__init__.py", line 265, in get_status device_type = response["deviceType"] KeyError: 'deviceType' Use `dict.get` so the missing-key case falls through to the existing "return response as-is" path, matching the pre-SeraphicCorp#42 behavior for IR remotes while preserving the new keypad special-casing. Adds a regression test + fixture covering an empty status body.
Contributor
Author
|
Hello @SeraphicRav ? |
SeraphicRav
approved these changes
Apr 10, 2026
Contributor
SeraphicRav
left a comment
There was a problem hiding this comment.
Thanks for your contribution ! Sorry for the review delay !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #42 (released as 2.11.0)
SwitchBotAPI.get_statusdoes an unconditionalresponse["deviceType"]lookup to detect Keypad devices. The SwitchBot Cloud API returns an empty body for IR remote devices — the docstring onget_statusitself even notes "No status for IR devices" — so the unwrapped response dict has nodeviceTypekey, and every coordinator backing an IR remote (and any other device whose status response omitsdeviceType) now raisesKeyError: 'deviceType'.In Home Assistant 2026.4.x (which bumped this library to 2.11.0 in home-assistant/core#164663) this surfaces as the
switchbot_cloudintegration repeatedly failing setup with the following traceback:Fix
Use
dict.getso the missing-key case falls through to the existing "return response as-is" path. This restores the pre-#42 behavior for IR remotes while preserving the keypad special-casing introduced in #42:if device_type and device_type in KeyPadCommands.get_supported_devices():short-circuits cleanly whendevice_type is None, so no further changes are needed.Test plan
tests/fixtures/ir_remote.jsonmodeling the empty-body response the SwitchBot Cloud API returns for IR remotes ({"statusCode": 100, "body": {}, "message": "success"})test_device_status_ir_remoteregression test assertingget_statusreturns{}instead of raisingmainwith the exactKeyError: 'deviceType'from the bug report, and passes with this fix appliedpytest tests/→ 8 passed, 100% coverage, 4 snapshots passedruff format --checkclean on touched filesRefs
switchbot_cloudsetup failures after upgrading to HA Core 2026.4.x (Bumb switchbot api to v2.11.0 home-assistant/core#164663)