Remove TemplateSensor from the template_entity helper (#98945)

Clean off TemplateSensor
This commit is contained in:
G Johansson 2023-08-24 12:14:39 +02:00 committed by GitHub
parent 849cfa3af8
commit b69e8fda77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 23 deletions

View File

@ -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(

View File

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