Skip to content

Fix Solis case-insensitive SN matching in event handlers (#3433)#3502

Merged
springfall2008 merged 1 commit intomainfrom
fix-solis-uppercase-sn-entity-id
Mar 5, 2026
Merged

Fix Solis case-insensitive SN matching in event handlers (#3433)#3502
springfall2008 merged 1 commit intomainfrom
fix-solis-uppercase-sn-entity-id

Conversation

@springfall2008
Copy link
Owner

Summary

Fixes #3433solis.py event handlers still ignoring writes for inverters with uppercase hex digits in their serial number.

Root cause

HA normalises entity IDs to lowercase, so when number_event, select_event, or switch_event extract the serial number from the entity ID it arrives in lowercase (e.g. 111f33333333333). The previous fix (PR #3457) lowercased the SN when building entity IDs, but the event handlers still validated with a plain sn in self.inverter_sn check against self.inverter_sn which retains the original API casing (e.g. 111F33333333333). The comparison therefore failed for every write, producing the repeated warning:

Warn: Solis API: Unknown inverter 111f33333333333 in number_event

Fix

Add a find_inverter_by_sn() helper that performs a case-insensitive lookup and returns the canonical (API-casing) SN:

def find_inverter_by_sn(self, sn_from_entity_id):
    return next((sn for sn in self.inverter_sn if sn.lower() == sn_from_entity_id.lower()), None)

All three event handlers now call this helper. The returned SN is then used for Solis API payloads and internal dict keys (cached_values, charge_discharge_time_windows, etc.) so original casing is preserved where the API requires it.

Testing

Unit tests pass (./run_all --quick).

HA normalises entity IDs to lowercase, so inverter serial numbers
containing uppercase hex digits (A-F) are stored internally with their
original casing but arrive in number_event / select_event / switch_event
in lowercase form.  The plain 'sn in self.inverter_sn' check therefore
always fails for such inverters, causing every write to be silently
dropped with a spurious 'Unknown inverter' warning.

Fix: add a find_inverter_by_sn() helper that does a case-insensitive
match and returns the canonical (API-casing) serial number.  All three
event handlers now call this helper so that cache keys and Solis API
payloads continue to use the original casing while correctly resolving
entity-ID SNs that HA has lowercased.
Copilot AI review requested due to automatic review settings March 5, 2026 19:19
@springfall2008 springfall2008 merged commit c20ac3f into main Mar 5, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix-solis-uppercase-sn-entity-id branch March 5, 2026 19:23
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.

solis.py event handlers ignore writes (and warn) for inverters with hex digits in serial number

1 participant