fix: tolerate older HA cores lacking WIND_DIRECTION / MEASUREMENT_ANGLE#107
Merged
Conversation
sensor.py referenced SensorDeviceClass.WIND_DIRECTION and SensorStateClass.MEASUREMENT_ANGLE unconditionally. Both were added in HA 2025.1, but hacs.json declares a minimum of HA 2024.6.0, so on cores between 2024.6 and 2024.12 importing sensor.py raised AttributeError and the entire sensor platform failed to load. Resolve both defensively via getattr: on older cores the wind-direction sensors fall back to a plain numeric "°" sensor (device_class=None, state_class=MEASUREMENT) instead of crashing. On HA 2025.1+ behaviour is unchanged. Adds tests/test_sensor_platform.py, which imports the sensor module so this class of HA-version incompatibility is caught by CI in future (no existing test imported sensor.py). Co-Authored-By: Claude Opus 4.8 <[email protected]>
- tests/test_migration.py covers the v2 -> v3 hemisphere/climate_region slug migration (data + options, idempotency, v1 default-fill). - Version bumped to 2.5.1 (manifest, diagnostics, pyproject, docs) with a CHANGELOG entry for the older-HA WIND_DIRECTION compatibility fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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
custom_components/ws_core/sensor.pyreferencedSensorDeviceClass.WIND_DIRECTIONandSensorStateClass.MEASUREMENT_ANGLEunconditionally (the two wind-direction sensors). Both were added in HA 2025.1, buthacs.jsondeclares a minimum of HA 2024.6.0. On cores between 2024.6 and 2024.12, importingsensor.pyraisesAttributeError: type object 'SensorDeviceClass' has no attribute 'WIND_DIRECTION', which makes the entire sensor platform fail to load.This went unnoticed because no test imported
sensor.py; it surfaced when a v2.5.0 test imported the module against the CI-pinned HA version.Fix
Resolve both symbols defensively at module load:
°sensor (device_class=None,state_class=MEASUREMENT) instead of crashing.This keeps the code consistent with the declared
hacs.jsonminimum (rather than forcing a higher minimum on users).Regression guard
Adds
tests/test_sensor_platform.py, which imports the sensor module (and asserts both wind-direction sensors are present). The CI "Tests" job runs against a pinned HA version that lacks these APIs, so this test fails without the fix and passes with it - catching this class of incompatibility going forward.Verification
🤖 Generated with Claude Code