Add state_class to Nuki battery sensor#159756
Conversation
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @pschmitt, @pvizeli, @pree, 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
This pull request adds the state_class attribute to the Nuki battery sensor to enable long-term statistics collection in Home Assistant. Battery level is a measurement that users want to track over time, and without a state_class, the sensor is not eligible for long-term statistics.
Key Changes
- Added
SensorStateClass.MEASUREMENTto the Nuki battery sensor - Updated test snapshots to reflect the new capability
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/components/nuki/sensor.py |
Imported SensorStateClass and added _attr_state_class = SensorStateClass.MEASUREMENT to the NukiBatterySensor class |
tests/components/nuki/snapshots/test_sensor.ambr |
Updated test snapshots to include the new state_class capability in both entity registry and state attributes |
The changes are well-implemented and follow Home Assistant patterns. The addition of SensorStateClass.MEASUREMENT to battery sensors is a common pattern used across many integrations in Home Assistant (e.g., August, Yale, and others). The test snapshots have been properly updated to reflect the new capability. No issues identified.
jbouwh
left a comment
There was a problem hiding this comment.
LGTM,
Thanks @victor-gurbani 👍
Proposed change
This PR fixes the Nuki battery level sensor missing long-term statistics by setting the sensor’s
state_classto "measurement".Battery percentage is a value that benefits from being stored long-term. Without a state_class, the sensor is not eligible for long-term statistics, and users need to resort to manually customised overrides.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt. (not needed)Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests:
Commands I ran locally: