fix: decode observations that omit solar_radiation (KeyError)#129
Open
brentb2529 wants to merge 1 commit into
Open
fix: decode observations that omit solar_radiation (KeyError)#129brentb2529 wants to merge 1 commit into
brentb2529 wants to merge 1 commit into
Conversation
…ields Some WeatherFlow/Tempest stations never report solar_radiation (it is absent from both obs[0] and outdoor_keys). dataclasses_json decodes via a bare kvs[field.name] lookup, so a required field with no default raises KeyError on a missing key and the entire observation is discarded -- the station's consumers (HA tempest / weatherflow_cloud) go stale. Make the sensor-derived observation fields optional with a None default so a missing key decodes to None instead of raising. With dataclasses_json the default value (not just the Optional hint) is what skips the dict lookup. timestamp remains the sole required field and is moved first to satisfy dataclass field-ordering. uv_index_color/uv_index_exposure now guard against a None uv. Same bug class as jeeftor#128 (air_temperature) and #156969 (brightness). Adds a regression test + fixture (real station 113968 payload) covering an observation with no solar_radiation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
KeyError: 'solar_radiation'—Observationdecode fails for stations that don't report solar radiation.Some WeatherFlow/Tempest stations never report
solar_radiation: it's absent from bothobs[0]andoutdoor_keys.Observationdeclaressolar_radiation(along withbrightness,dew_point,heat_index,pressure_trend,relative_humidity,uv) as a required field with no default.dataclasses_jsondecodes via a barekvs[field.name]lookup, so a missing key raisesKeyErrorand the entire observation is discarded. Downstream consumers (HAcustom_components/tempest, coreweatherflow_cloud) then go stale /unavailable.This is the same bug class previously fixed for
air_temperature(#128) and reported forbrightness(home-assistant/core#156969) andpressure_trend.Observed in HA as:
Fix
Make the sensor-derived observation fields optional with a
Nonedefault, so a missing key decodes toNoneinstead of raising. Withdataclasses_jsonit's the default value (not just the| Nonehint) that makes the decoder skip the dict lookup.brightness,dew_point,heat_index,pressure_trend,relative_humidity,solar_radiation,uv→... | None = Nonetimestampremains the only required field (present in every observation) and is moved first to satisfy dataclass field-ordering (a no-default field can't follow a defaulted one).uv_index_color/uv_index_exposurenow guard against aNoneuvand returnNone.No version bump — left to maintainer per the existing "bump version" commit convention.
Tests
test_convert_json_to_observation_no_solar_radiation+ fixturestation_observation_no_solar_radiation.json(verbatim real payload from station 113968, which omitssolar_radiationfrom bothobs[0]andoutdoor_keys).ruff checkclean.Closes the
solar_radiationcase of the recurring missing-field decode bug.🤖 Generated with Claude Code