Correct unit_of_measurement for trigger-based template sensor (#69291)

pull/69323/head
Erik Montnemery 2022-04-05 07:10:59 +02:00 committed by GitHub
parent d0288f14f0
commit a95b4f6763
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

View File

@ -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."""

View File

@ -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."""