Skip to content

Fix solar capability detection when multiple solarModes returned by API - #14

Merged
dan-r merged 2 commits into
dan-r:mainfrom
keeshanam:fix-solar-modes-len
Oct 9, 2026
Merged

dan-r merged 2 commits into
dan-r:mainfrom
keeshanam:fix-solar-modes-len

Conversation

@keeshanam

Copy link
Copy Markdown
Contributor

I noticed a regression in Home Assistant around August 10, 2026 (observed at ~18:27 UTC in recorder history), where switch.ohme_home_pro_solar_boost unexpectedly became unavailable and was no longer created across restarts.

Digging into the API responses, this appears to be tied to a recent backend API change from Ohme.

Observed API Behavior

In the response from GET /v1/users/me/account, chargeDevices[0]["modelCapabilities"]["solarModes"] on my Ohme Home Pro currently returns:

"solarModes": [
  "PURE_SOLAR",
  "ZERO_EXPORT"
]

It looks like Ohme has expanded their solar modes (presumably rolling out PURE_SOLAR alongside the existing ZERO_EXPORT).

Because line 614 checks for an exact length of 1:

solar_modes = device["modelCapabilities"]["solarModes"]
if isinstance(solar_modes, list) and len(solar_modes) == 1:
    self._capabilities["solar"] = True

the list now having 2 elements causes self._capabilities["solar"] to remain unset, so Home Assistant skips registering the entity.

Proposed Changes

While it's difficult to know for certain without an official OpenAPI spec if Ohme plans to introduce further solar modes, this PR proposes a couple of pragmatic changes to adapt to the current behavior:

  1. Capability check: Switch from len(solar_modes) == 1 to len(solar_modes) > 0 (and use .get("solarModes")) so any non-empty list of supported modes enables the capability without failing if additional modes appear or raising KeyError if missing.
  2. State check: Update solar_enabled to return True for either "ZERO_EXPORT" or "PURE_SOLAR" (the setting in optionalSettings["solarMode"]), ensuring the entity reflects that solar mode is active regardless of which of the two modes was toggled in the Ohme app.
  3. Unit tests: Added test cases in tests/test_solar.py covering multi-mode, single-mode, empty/missing list, and solar_enabled property behavior.

Tested locally against a live Ohme Home Pro on Home Assistant Core; solar boost switch entity registration and toggling are fully restored.

Ohme API returns multiple solar modes (e.g. ['PURE_SOLAR', 'ZERO_EXPORT'])
in modelCapabilities['solarModes']. Previously, len(solar_modes) == 1
caused solar capability to be falsely reported as unsupported when
both modes are supported.

Also update solar_enabled property to return True for either ZERO_EXPORT
or PURE_SOLAR.

@dan-r dan-r left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

All looks good. As this is our first set of unit tests, can you please add a workflow that runs everything in tests/ for every pull request as a check?

@keeshanam

Copy link
Copy Markdown
Contributor Author

Added .github/workflows/tests.yml to run the test suite across Python 3.11, 3.12, and 3.13 on pull requests and pushes to main. Thanks Dan!

@dan-r

dan-r commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Nice work. Thank you

@dan-r
dan-r merged commit 317577e into dan-r:main Oct 9, 2026
3 checks passed
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.

2 participants