Add Rabbit Air air quality sensor#172993
Conversation
|
Hey there @rabbit-air, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds an air quality sensor entity to the Rabbit Air integration, exposing the device's air quality reading (lowest, low, medium, high, highest) as a Home Assistant sensor.
Changes:
- Adds a new
sensor.pyplatform file with an enum-based air quality sensor entity. - Registers the sensor platform and adds corresponding strings, icons, and test coverage.
- Updates the shared
get_mock_statehelper to include thequalityattribute.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/components/rabbitair/init.py | Registers the new SENSOR platform |
| homeassistant/components/rabbitair/sensor.py | New sensor entity for air quality |
| homeassistant/components/rabbitair/strings.json | Adds translation strings for the sensor states |
| homeassistant/components/rabbitair/icons.json | Adds icon for the sensor entity |
| tests/components/rabbitair/test_config_flow.py | Extends get_mock_state with quality param |
| tests/components/rabbitair/test_sensor.py | New test file for the air quality sensor |
| ) -> None: | ||
| """Initialize the entity.""" | ||
| super().__init__(coordinator, entry) | ||
| self._attr_name = entry.title |
There was a problem hiding this comment.
Hmm, shouldn't we set _attr_has_entity_name = True at the base entity and then set _attr_name = None here?
There was a problem hiding this comment.
Updated. _attr_has_entity_name = True is now set on RabbitAirBaseEntity, and the fan entity sets _attr_name = None to preserve the primary device entity naming pattern.
| self._attr_native_value = _quality_value(coordinator.data.quality) | ||
|
|
||
| @callback | ||
| def _handle_coordinator_update(self) -> None: | ||
| """Handle updated data from the coordinator.""" | ||
| self._attr_native_value = _quality_value(self.coordinator.data.quality) | ||
| super()._handle_coordinator_update() |
There was a problem hiding this comment.
Instead I'd implement the native_value property
There was a problem hiding this comment.
Updated. The air quality sensor now implements native_value as a property based on the coordinator data instead of storing _attr_native_value and updating it manually.
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| data={ | ||
| CONF_HOST: TEST_HOST, | ||
| CONF_ACCESS_TOKEN: TEST_TOKEN, | ||
| CONF_MAC: TEST_MAC, | ||
| }, | ||
| title=TEST_TITLE, | ||
| unique_id=TEST_UNIQUE_ID, | ||
| ) |
There was a problem hiding this comment.
can we make this a test fixture?
There was a problem hiding this comment.
Updated. The repeated MockConfigEntry setup is now in a mock_config_entry fixture.
| with patch( | ||
| "rabbitair.UdpClient.get_state", | ||
| return_value=get_mock_state(quality=Quality.High), | ||
| ): |
There was a problem hiding this comment.
Can we patch it where we use it?
There was a problem hiding this comment.
Updated. The tests now patch homeassistant.components.rabbitair.coordinator.Client.get_state, where the integration uses the client.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
| if entry.runtime_data.data.quality is not None: | ||
| async_add_entities([RabbitAirAirQualitySensor(entry.runtime_data, entry)]) |
There was a problem hiding this comment.
@joostlek - I’m not sure we can definitively know which current and future Rabbit Air models support quality, though my assumption is that they all will do. Given that, would you prefer that we always create the air quality sensor and let it report unknown when the device returns quality=None, or keep the current setup-time check and only create the entity when the first fetched state includes a quality value?
|
Thanks for your reviews, @joostlek. For the future sensors, do you want them as individual PRs, or grouped into say 2-3 per PR, or just done in bulk? |
|
What future sensors? I'd recommend to keep it to a well scoped PR |
|
The base library exposes a lot more sensors I intend to surface through HA, so wanted to ask how you'd prefer those be added - individually per PR, or grouped - for example, filter sensors, particulate sensors, etc... |
|
You can probably split on how you feel like makes sense, if a specific entity contains more logic it might make sense to split for example |
|
Please open a docs PR |
## Proposed change Document the Rabbit Air air quality sensor added in home-assistant/core#172993. ## Type of change - [ ] Spelling, grammar or other readability improvements (`current` branch). - [x] Adjusted missing or incorrect information in the current documentation (`current` branch). - [ ] Added documentation for a new integration I'm adding to Home Assistant (`next` branch). - [ ] Added documentation for a new feature I'm adding to Home Assistant (`next` branch).
|
Link to documentation pull request: home-assistant/home-assistant.io#45749 |
Document the Rabbit Air air quality sensor added in home-assistant/core#172993. - [ ] Spelling, grammar or other readability improvements (`current` branch). - [x] Adjusted missing or incorrect information in the current documentation (`current` branch). - [ ] Added documentation for a new integration I'm adding to Home Assistant (`next` branch). - [ ] Added documentation for a new feature I'm adding to Home Assistant (`next` branch).
Proposed change
Add an air quality sensor to the Rabbit Air integration.
The sensor uses the existing Rabbit Air coordinator data and exposes the
qualityvalue frompython-rabbitairas a Home Assistant enum sensor with the following states:lowestlowmediumhighhighestThis also adds translations and an icon for the new sensor.
This is the first of many sensors to be added, I'd like to make sure I have the basic approach right before adding more in bulk.
The change was co-authored by OpenAI Codex 5.5.
Type of change
Additional information
Checklist
ruff format homeassistant tests)Validation
uv run ruff check homeassistant/components/rabbitair tests/components/rabbitairuv run ruff format --check homeassistant/components/rabbitair tests/components/rabbitairuv run pytest tests/components/rabbitairuv run --with tqdm python -m script.hassfest --integration-path homeassistant/components/rabbitair