From a95b4f676345cfa6a2a09c8f49cb7d08cd45ff58 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 5 Apr 2022 07:10:59 +0200 Subject: [PATCH] Correct unit_of_measurement for trigger-based template sensor (#69291) --- homeassistant/components/template/sensor.py | 5 +++++ homeassistant/components/template/trigger_entity.py | 13 +------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/template/sensor.py b/homeassistant/components/template/sensor.py index c1fae1f4f3b..a61d15cb7a4 100644 --- a/homeassistant/components/template/sensor.py +++ b/homeassistant/components/template/sensor.py @@ -253,6 +253,11 @@ class TriggerSensorEntity(TriggerEntity, SensorEntity): """Sensor state class.""" return self._config.get(CONF_STATE_CLASS) + @property + def native_unit_of_measurement(self) -> str | None: + """Return the unit of measurement of the sensor, if any.""" + return self._config.get(CONF_UNIT_OF_MEASUREMENT) + @callback def _process_data(self) -> None: """Process new data.""" diff --git a/homeassistant/components/template/trigger_entity.py b/homeassistant/components/template/trigger_entity.py index 123b365d697..bebe941fbf9 100644 --- a/homeassistant/components/template/trigger_entity.py +++ b/homeassistant/components/template/trigger_entity.py @@ -4,13 +4,7 @@ from __future__ import annotations import logging from typing import Any -from homeassistant.const import ( - CONF_DEVICE_CLASS, - CONF_ICON, - CONF_NAME, - CONF_UNIQUE_ID, - CONF_UNIT_OF_MEASUREMENT, -) +from homeassistant.const import CONF_DEVICE_CLASS, CONF_ICON, CONF_NAME, CONF_UNIQUE_ID from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import TemplateError from homeassistant.helpers import template @@ -89,11 +83,6 @@ class TriggerEntity(CoordinatorEntity[TriggerUpdateCoordinator]): """Return device class of the entity.""" return self._config.get(CONF_DEVICE_CLASS) - @property - def unit_of_measurement(self) -> str | None: - """Return unit of measurement.""" - return self._config.get(CONF_UNIT_OF_MEASUREMENT) - @property def icon(self) -> str | None: """Return icon."""