diff --git a/homeassistant/components/template/sensor.py b/homeassistant/components/template/sensor.py index 7a5df84a207..aa6788109ff 100644 --- a/homeassistant/components/template/sensor.py +++ b/homeassistant/components/template/sensor.py @@ -14,6 +14,7 @@ from homeassistant.components.sensor import ( PLATFORM_SCHEMA, RestoreSensor, SensorDeviceClass, + SensorEntity, ) from homeassistant.components.sensor.helpers import async_parse_date_datetime from homeassistant.const import ( @@ -39,7 +40,7 @@ from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.template_entity import ( TEMPLATE_SENSOR_BASE_SCHEMA, - TemplateSensor, + TemplateEntity, ) from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -196,7 +197,7 @@ async def async_setup_platform( ) -class SensorTemplate(TemplateSensor): +class SensorTemplate(TemplateEntity, SensorEntity): """Representation of a Template Sensor.""" _attr_should_poll = False @@ -209,6 +210,9 @@ class SensorTemplate(TemplateSensor): ) -> None: """Initialize the sensor.""" super().__init__(hass, config=config, fallback_name=None, unique_id=unique_id) + self._attr_native_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT) + self._attr_device_class = config.get(CONF_DEVICE_CLASS) + self._attr_state_class = config.get(CONF_STATE_CLASS) self._template: template.Template = config[CONF_STATE] if (object_id := config.get(CONF_OBJECT_ID)) is not None: self.entity_id = async_generate_entity_id( diff --git a/homeassistant/helpers/template_entity.py b/homeassistant/helpers/template_entity.py index 70a0ee1d16c..16dc212e8cc 100644 --- a/homeassistant/helpers/template_entity.py +++ b/homeassistant/helpers/template_entity.py @@ -454,27 +454,6 @@ class TemplateEntity(Entity): ) -class TemplateSensor(TemplateEntity, SensorEntity): - """Representation of a Template Sensor.""" - - def __init__( - self, - hass: HomeAssistant, - *, - config: dict[str, Any], - fallback_name: str | None, - unique_id: str | None, - ) -> None: - """Initialize the sensor.""" - super().__init__( - hass, config=config, fallback_name=fallback_name, unique_id=unique_id - ) - - self._attr_native_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT) - self._attr_device_class = config.get(CONF_DEVICE_CLASS) - self._attr_state_class = config.get(CONF_STATE_CLASS) - - class TriggerBaseEntity(Entity): """Template Base entity based on trigger data."""