Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions blog/2021-08-12-sensor_temperature_conversion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
author: Erik Montnémery
authorURL: https://github.com/emontnemery
title: Temperature conversions moving to SensorEntity
---

Temperature unit conversions are moving from the `Entity` base class to the `SensorEntity` base
class. Unit conversions will only be done if the sensor's `device_class` attribute is set
to `DEVICE_CLASS_TEMPERATURE`. If the `device_class` is not set or is not set to
`DEVICE_CLASS_TEMPERATURE` temperature conversion will take place during a transition
period and a warning will be logged.

To facilitate this, the sensor entity model has been updated with two new properties,
`native_value` and `native_unit_of_measurement`. This allows us to add additional
unit conversions in the future instead of relying on the integrations to do it themselves.

Sensor implementations should no longer implement the `state()` property function or set
the `_attr_state` attribute. Sensor implementations should also not implement the
`unit_of_measurement` property function, set the `_attr_unit_of_measurement` attribute
or set the `unit_of_measurement` member of `EntityDescription`.

### native_value

The value reported by the sensor.
The actual state written to the state machine may be modified by `SensorEntity` due to
unit conversions.

### native_unit_of_measurement

The unit of measurement of the sensor, if any.
The `unit_of_measurement` written to the state machine may be modified by `SensorEntity`
due to unit conversions.