Skip to content

Tolerate missing “type” in device info for legacy myStrom v1 switches#60

Merged
fabaff merged 1 commit intohome-assistant-ecosystem:masterfrom
elsi06:fix/tolerate-missing-type-v1-switches
Aug 19, 2025
Merged

Tolerate missing “type” in device info for legacy myStrom v1 switches#60
fabaff merged 1 commit intohome-assistant-ecosystem:masterfrom
elsi06:fix/tolerate-missing-type-v1-switches

Conversation

@elsi06
Copy link
Contributor

@elsi06 elsi06 commented Aug 14, 2025

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.

…; use .get for version/mac/type; add test; update changelog (refs home-assistant/core#150264)
@elsi06
Copy link
Contributor Author

elsi06 commented Aug 15, 2025

@fabaff how does it looks? Chöimer das züg merge?

@fabaff fabaff merged commit 7c6360d into home-assistant-ecosystem:master Aug 19, 2025
0 of 3 checks passed
@elsi06 elsi06 deleted the fix/tolerate-missing-type-v1-switches branch August 20, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants