feat: Add state_class to CollectionShipment sensor for long-term statistics#74
Open
robbybarnes wants to merge 2 commits intojmdevita:mainfrom
Open
feat: Add state_class to CollectionShipment sensor for long-term statistics#74robbybarnes wants to merge 2 commits intojmdevita:mainfrom
robbybarnes wants to merge 2 commits intojmdevita:mainfrom
Conversation
…ensor Adds SensorStateClass.MEASUREMENT and native_unit_of_measurement to the CollectionShipment sensor, enabling better integration with Home Assistant's long-term statistics and energy dashboard features. Changes: - Import SensorStateClass from homeassistant.components.sensor - Add _attr_state_class = SensorStateClass.MEASUREMENT - Add _attr_native_unit_of_measurement = "parcels" This allows the sensor to be properly tracked in HA's statistics and provides better metadata for display and graphing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Collaborator
PineappleEmperor
left a comment
There was a problem hiding this comment.
I think this one works. We may wish to modify the active sensor to always return an integer state and use the same setup. Would you like to incorporate those changes into this PR?
Per maintainer feedback, extends the state_class addition to ActiveShipment:
- Added SensorStateClass.MEASUREMENT and native_unit_of_measurement
- State now returns integer count of active parcels (enables HA statistics)
- Previous verbose text ("1 parcel", "in 2 days") moved to status_text attribute
This is a breaking change for users relying on the text state value,
but enables Home Assistant's long-term statistics tracking.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
Adds
SensorStateClass.MEASUREMENTto theCollectionShipmentsensor, enabling Home Assistant's long-term statistics tracking.Motivation
Home Assistant can record long-term statistics for sensors that have a
state_classdefined. Without this, the collectable parcels count isn't available in the Statistics dashboard or for historical analysis.This is useful for users who want to:
Changes
SensorStateClassfromhomeassistant.components.sensor_attr_state_class = SensorStateClass.MEASUREMENTtoCollectionShipment_attr_native_unit_of_measurement = "parcels"for proper unit displayTechnical Notes
MEASUREMENTis the appropriate state class for a point-in-time count valueTesting