Conversation
Home Assistant only accepts `lx` for the `illuminance` device class and `W/m2`/`BTU/(h.ft2)` for `irradiance`. `DATA_POINT_SOLARRADIATION` hardcoded `irradiance` in its `EntityDescription`, but the unit is user-selectable via `--output-unit-illuminance`, so any non-default choice produced a combination Home Assistant rejects: lx -> irradiance (invalid) klx/fc/kfc -> irradiance (invalid) MQTT discovery treats this as a hard schema failure, so the sensor is never created and an error is logged on every discovery message. Derive the device class from the resolved unit instead, and omit it entirely for units that map to no valid device class (`klx`, `fc`, `kfc`) - which Home Assistant explicitly permits. Fixes bachya#1297 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1434 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 33 33
Lines 1797 1798 +1
=========================================
+ Hits 1797 1798 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 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.
DATA_POINT_SOLARRADIATIONhardcodesdevice_class=irradiance, but its unit isuser-selectable via
--output-unit-illuminance. Home Assistant accepts onlyW/m²andBTU/(h⋅ft²)forirradiance, and onlylxforilluminance, so every non-defaultunit produces a pair HA rejects:
--output-unit-illuminancedevice_classemittedW/m²(default)irradiancelx/klx/fc/kfcirradianceMQTT discovery treats this as a schema error rather than a warning, so the sensor is
never created:
If the sensor already exists on the default unit, HA rejects the update instead and
keeps the old config, so the entity carries on reporting
W/m²while lux values arriveunderneath.
Fix
Override the device class from the resolved unit, in the same style as
STATE_CLASS_OVERRIDESjust below it:klx/fc/kfcmap toNonebecause HA has no device class that accepts them; omittingdevice_classis valid and the sensor is created normally. Data points with no entrykeep their static device class, so the default output is unchanged.
Tests cover each unit, and the README's Illuminance section notes the resulting device
class. Verified against Home Assistant 2026.9.2.
Previously reported in #1297.