Skip to content

fix: tolerate older HA cores lacking WIND_DIRECTION / MEASUREMENT_ANGLE#107

Merged
kmich merged 2 commits into
mainfrom
claude/fix-wind-direction-compat
Jun 24, 2026
Merged

fix: tolerate older HA cores lacking WIND_DIRECTION / MEASUREMENT_ANGLE#107
kmich merged 2 commits into
mainfrom
claude/fix-wind-direction-compat

Conversation

@kmich

@kmich kmich commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Problem

custom_components/ws_core/sensor.py referenced SensorDeviceClass.WIND_DIRECTION and SensorStateClass.MEASUREMENT_ANGLE unconditionally (the two wind-direction sensors). Both were added in HA 2025.1, but hacs.json declares a minimum of HA 2024.6.0. On cores between 2024.6 and 2024.12, importing sensor.py raises AttributeError: 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:

_WIND_DIRECTION_DEVICE_CLASS = getattr(SensorDeviceClass, "WIND_DIRECTION", None)
_MEASUREMENT_ANGLE_STATE_CLASS = getattr(SensorStateClass, "MEASUREMENT_ANGLE", SensorStateClass.MEASUREMENT)
  • HA 2025.1+: behaviour unchanged (real device/state classes).
  • HA 2024.6–2024.12: the wind-direction sensors degrade to a plain numeric ° sensor (device_class=None, state_class=MEASUREMENT) instead of crashing.

This keeps the code consistent with the declared hacs.json minimum (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

  • ruff + ruff format clean
  • 255 tests pass locally (HA 2026.2.3)
  • dashboard entity validator passes
  • The real proof is CI here, which runs the older pinned HA

🤖 Generated with Claude Code

kmich and others added 2 commits June 24, 2026 13:19
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]>
@kmich
kmich merged commit 9c4c42c into main Jun 24, 2026
10 checks passed
@kmich
kmich deleted the claude/fix-wind-direction-compat branch July 9, 2026 06:13
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.

1 participant