Tolerate missing “type” in device info for legacy myStrom v1 switches#60
Merged
fabaff merged 1 commit intohome-assistant-ecosystem:masterfrom Aug 19, 2025
Conversation
…; use .get for version/mac/type; add test; update changelog (refs home-assistant/core#150264)
Contributor
Author
|
@fabaff how does it looks? Chöimer das züg merge? |
bachp
approved these changes
Aug 16, 2025
4 tasks
fabaff
approved these changes
Aug 19, 2025
5 tasks
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.
Older myStrom v1 switches (e.g., firmware 2.x) may omit “type” in their info endpoints. MyStromSwitch.get_state() previously accessed response["type"] directly, causing a KeyError. This change uses response.get("type") (and .get for "version"/"mac") to handle legacy devices gracefully.
Details:
Switch report parsing remains unchanged and tolerant via try/except.
Device info retrieval keeps existing behavior: try /api/v1/info first; if response isn’t a dict, fall back to info.json.
No public API changes.
Testing:
Added tests/test_switch_missing_type.py to simulate info without "type" and verify:
No exception raised,
device_type is None,
relay/power/Ws/mac/firmware parsed correctly.
Closes/References:
Related to home-assistant/core#150264 (v1 devices unavailable due to KeyError)
Changelog:
Fix: Tolerate missing “type” in device info for legacy myStrom v1 switches, preventing KeyError during get_state.