-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sensor device class for graph and precision #18099
Conversation
The code works correctly with the related backend PR. |
src/data/history.ts
Outdated
const numericStateFromHistory = | ||
!currentState && | ||
stateInfo.find((state) => state.a && attributesHaveUnits(state.a)); | ||
stateInfo.find((state) => state.a && isNumericFromAttributes(state.a)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move this in an else when isNumeric
is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldnt we use the same checks here as we do below for isNumeric
? So also use the domain and isNumericSensorEntity
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have device_class in the history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then I think we should just do a check on the domain before we go through the historic states
Backend has been merged. |
domain === "sensor" && | ||
isNumericSensorEntity(currentState, sensorNumericalDeviceClasses)); | ||
|
||
if (isNumeric) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isNumeric
can also be true if there is no state, but the domain is a numeric domain. We should still use the numericStateFromHistory
then if available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess in that case for now it will be correct, because it will not have a UOM and will use the correct BLANK_UNIT
, but I think that is pretty error prone...?
I would prefer:
unit = currentState?.attributes.unit_of_measurement || numericStateFromHistory?.a.unit_of_measurement || BLANK_UNIT;
Co-authored-by: Bram Kragten <[email protected]>
69648cb
to
521ff53
Compare
Proposed change
Use sensor device class to determine if the state is numeric or not.
This fixes 2 issues :
aqi
,ph
orpower_factor
device class
and without state_class doesn't render as a graph (core issue: "AQI" & "pH" device classes: cannot specify "" uom #18439)This PR also removes the
#
unit forcounter
,input_number
,number
to be consistent with other domains.Needs home-assistant/core#101257
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: