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
4903c1fb
"README.rst" did not exist on "a50ed4695035ed07bf1fac4a5562015abfb246b1"
Unverified
Commit
4903c1fb
authored
3 years ago
by
Erik Montnemery
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Minor cleanup of SensorEntity (#54624)
parent
32a2c5d5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/sensor/__init__.py
+4
-6
4 additions, 6 deletions
homeassistant/components/sensor/__init__.py
with
4 additions
and
6 deletions
homeassistant/components/sensor/__init__.py
+
4
−
6
View file @
4903c1fb
...
...
@@ -141,6 +141,7 @@ class SensorEntity(Entity):
_attr_native_unit_of_measurement
:
str
|
None
_attr_native_value
:
StateType
=
None
_attr_state_class
:
str
|
None
_attr_state
:
None
=
None
# Subclasses of SensorEntity should not set this
_last_reset_reported
=
False
_temperature_conversion_reported
=
False
...
...
@@ -176,8 +177,7 @@ class SensorEntity(Entity):
"""
Return state attributes.
"""
if
last_reset
:
=
self
.
last_reset
:
if
(
last_reset
is
not
None
and
self
.
state_class
==
STATE_CLASS_MEASUREMENT
self
.
state_class
==
STATE_CLASS_MEASUREMENT
and
not
self
.
_last_reset_reported
):
self
.
_last_reset_reported
=
True
...
...
@@ -211,6 +211,7 @@ class SensorEntity(Entity):
return
self
.
entity_description
.
native_unit_of_measurement
return
None
@final
@property
def
unit_of_measurement
(
self
)
->
str
|
None
:
"""
Return the unit of measurement of the entity, after unit conversion.
"""
...
...
@@ -232,13 +233,10 @@ class SensorEntity(Entity):
return
native_unit_of_measurement
@final
@property
def
state
(
self
)
->
Any
:
"""
Return the state of the sensor and perform unit conversions, if needed.
"""
# Test if _attr_state has been set in this instance
if
"
_attr_state
"
in
self
.
__dict__
:
return
self
.
_attr_state
unit_of_measurement
=
self
.
native_unit_of_measurement
value
=
self
.
native_value
...
...
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