feat(domains): add AirQuality domain (#34)#66
Merged
Conversation
Adds a read-only AirQuality domain wrapping HA's air_quality entities with typed pollutant metric properties (AQI, PM2.5, PM10, CO2, CO, VOC, NO2, ozone). All metrics return None when the underlying sensor does not report them, so unsupported metrics degrade silently. Provides on_aqi_change / on_pm25_change / on_co2_change listener decorators.
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.
Closes #34.
Issue validity
Valid feature request. Air quality entities are a distinct HA domain with multiple co-reported pollutant metrics that do not fit the single-value Sensor abstraction. Without a domain helper users must hand-parse attributes with no type safety or change listeners — inconsistent with the typed experience of Sensor, Climate, etc.
Fix
Adds `src/haclient/domains/air_quality.py`:
on_aqi_change,on_pm25_change,on_co2_change.haclient.domains.__init__, automatically reachable asha.air_quality("name").Tests added (
tests/test_domains.py)test_air_quality_full_metrics— every metric reads its attribute.test_air_quality_degrades_when_metrics_missing— every metric returnsNoneon an empty sensor.test_air_quality_index_prefers_explicit_attribute— attribute overrides state.test_air_quality_coercion_handles_strings_and_bad_values— numeric strings coerce, junk/bool/list yieldNone.test_air_quality_listeners— all three decorators fire correctly.Validation
ruff check src tests— cleanruff format --check src tests— cleanmypy src(strict) — cleanpytest tests/ --cov=haclient --cov-report=term-missing --cov-fail-under=95— 265 passed, total coverage 96.62% (new module 100%).EOF
)