Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
8d37fd08
Unverified
Commit
8d37fd08
authored
3 years ago
by
Thomas Lovén
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix integration sensors sometimes not getting device_class or unit_of_measurement (#54802)
parent
bce7c739
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/integration/sensor.py
+8
-6
8 additions, 6 deletions
homeassistant/components/integration/sensor.py
with
8 additions
and
6 deletions
homeassistant/components/integration/sensor.py
+
8
−
6
View file @
8d37fd08
...
...
@@ -145,12 +145,6 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
"""
Handle the sensor state changes.
"""
old_state
=
event
.
data
.
get
(
"
old_state
"
)
new_state
=
event
.
data
.
get
(
"
new_state
"
)
if
(
old_state
is
None
or
old_state
.
state
in
(
STATE_UNKNOWN
,
STATE_UNAVAILABLE
)
or
new_state
.
state
in
(
STATE_UNKNOWN
,
STATE_UNAVAILABLE
)
):
return
if
self
.
_unit_of_measurement
is
None
:
unit
=
new_state
.
attributes
.
get
(
ATTR_UNIT_OF_MEASUREMENT
)
...
...
@@ -162,6 +156,14 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
and
new_state
.
attributes
.
get
(
ATTR_DEVICE_CLASS
)
==
DEVICE_CLASS_POWER
):
self
.
_attr_device_class
=
DEVICE_CLASS_ENERGY
if
(
old_state
is
None
or
old_state
.
state
in
(
STATE_UNKNOWN
,
STATE_UNAVAILABLE
)
or
new_state
.
state
in
(
STATE_UNKNOWN
,
STATE_UNAVAILABLE
)
):
return
try
:
# integration as the Riemann integral of previous measures.
area
=
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment