Refactor Rest Sensor with ManualTriggerEntity (#97396)

* ManualTriggerEntity for rest sensor

* add availability test

* review comments

* last fixes
This commit is contained in:
G Johansson
2023-08-10 21:46:56 +02:00
committed by GitHub
parent 82ade574d8
commit aacb8aecfc
4 changed files with 95 additions and 13 deletions

View File

@@ -653,3 +653,17 @@ class ManualTriggerEntity(TriggerBaseEntity):
variables = {"this": this, **(run_variables or {})}
self._render_templates(variables)
class ManualTriggerSensorEntity(ManualTriggerEntity):
"""Template entity based on manual trigger data for sensor."""
def __init__(
self,
hass: HomeAssistant,
config: dict,
) -> None:
"""Initialize the sensor entity."""
ManualTriggerEntity.__init__(self, hass, config)
self._attr_native_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
self._attr_state_class = config.get(CONF_STATE_CLASS)