From 2653f054a212485dc0b26a5ef9399ca57a3fa68e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 13 Aug 2021 12:35:52 +0200 Subject: [PATCH] Add blog post about sensor temperature conversion (#1024) * Add blog post about sensor temperature conversion * Update blog/2021-08-12-sensor_temperature_conversion.md Co-authored-by: Tom Brien * Document that device_class is mandatory * Update 2021-08-12-sensor_temperature_conversion.md Co-authored-by: Tom Brien --- ...021-08-12-sensor_temperature_conversion.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 blog/2021-08-12-sensor_temperature_conversion.md diff --git a/blog/2021-08-12-sensor_temperature_conversion.md b/blog/2021-08-12-sensor_temperature_conversion.md new file mode 100644 index 00000000..8f1d32cc --- /dev/null +++ b/blog/2021-08-12-sensor_temperature_conversion.md @@ -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.