Skip to content

mystrom: temporary fallback for v1 switches without 'type' (legacy firmware)#150845

Closed
elsi06 wants to merge 2 commits intohome-assistant:devfrom
elsi06:fix/mystrom-v1-legacy-fallback
Closed

mystrom: temporary fallback for v1 switches without 'type' (legacy firmware)#150845
elsi06 wants to merge 2 commits intohome-assistant:devfrom
elsi06:fix/mystrom-v1-legacy-fallback

Conversation

@elsi06
Copy link
Copy Markdown
Contributor

@elsi06 elsi06 commented Aug 18, 2025

Summary

Older myStrom v1 switches (e.g., firmware 2.x) can omit the type key in their info endpoints. The library then raises a KeyError during get_state, which prevents the integration from setting up in 2025.8.x.

This PR adds a minimal, temporary fallback in the myStrom integration to handle that case until the upstream fix in python‑mystrom is released.

Problem

What this PR changes

  • Catches only the specific KeyError during initial switch setup
  • Falls back to a small, local “legacy” client for v1 devices that:
    • Reads state via /report (power/Ws/relay/temperature)
    • Toggles via /relay
    • Optionally refreshes firmware/mac if present
  • The legacy client is clearly marked TEMPORARY and scoped to the KeyError path only
  • No behavior change for v2+ devices or bulbs

Why this is safe

  • Extremely narrow scope: activated only if the library throws KeyError for missing type
  • Leaves the existing code path untouched for all other devices
  • Backwards-compatible; no config or UI changes

Files touched

  • homeassistant/components/mystrom/__init__.py — fallback hook on KeyError only
  • homeassistant/components/mystrom/legacy.py — NEW; temporary v1 helper
  • tests/components/mystrom/test_legacy_v1.py — NEW; covers fallback path

Testing

  • New test simulates the KeyError path and verifies:
    • The entity is created and the config entry loads
    • No impact on the normal code path
  • Normal flows (v2+) remain unchanged

Follow-up plan

  • After a new python‑mystrom release that tolerates missing type is published:
    • Bump the requirement in manifest.json
    • Remove legacy.py and the fallback branch
    • Keep tests green

Related links

Reviewer checklist

  • Scope limited to KeyError path
  • No regressions for v2+ devices
  • Temporary code clearly labeled and easy to remove post library update
  • Test covers the fallback path and passes CI

…patibility until python-mystrom fix releases
@elsi06 elsi06 requested a review from fabaff as a code owner August 18, 2025 12:34
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @elsi06

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link
Copy Markdown

Hey there @fabaff, mind taking a look at this pull request as it has been labeled with an integration (mystrom) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of mystrom can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign mystrom Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@elsi06 elsi06 marked this pull request as ready for review August 18, 2025 12:47
Copy link
Copy Markdown
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so 2 things

  1. We don't allow integrations to do requests themselves, that should happen in the library. I know you have the PR open, but my teacher used to say "nothing is as definitive as a temporary solution". So I don't want to merge this as is.
  2. You mention that it doesn't work in 2025.8.0 anymore because of a keyerror because it is missing type, but on line 54, we use .setdefault to set type to a value, so I am not sure why this would be ommitted now

@home-assistant home-assistant bot marked this pull request as draft August 19, 2025 13:57
@elsi06 elsi06 closed this Aug 19, 2025
@elsi06 elsi06 mentioned this pull request Aug 20, 2025
5 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Aug 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants