Add config flow for template sensor (#98970)

* Add config flow for template sensor

* Tweak error reporting

* Improve validation

* Fix test

* Rename translation strings

* Improve validation

* Fix sensor async_setup_entry

* Avoid duplicating sensor device class translations

* Avoid duplicating sensor device class translations

* Add config flow tests

* Include all units from DEVICE_CLASS_UNITS in unit_of_measurement select

* Address review comments
This commit is contained in:
Erik Montnemery 2023-08-30 16:22:52 +02:00 committed by GitHub
parent bc5f934f35
commit 63c538b024
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1174 additions and 54 deletions

View file

@ -351,8 +351,9 @@ class TemplateFan(TemplateEntity, FanEntity):
self._state = False
async def async_added_to_hass(self) -> None:
"""Register callbacks."""
@callback
def _async_setup_templates(self) -> None:
"""Set up templates."""
if self._template:
self.add_template_attribute(
"_state", self._template, None, self._update_state
@ -390,7 +391,7 @@ class TemplateFan(TemplateEntity, FanEntity):
self._update_direction,
none_on_template_error=True,
)
await super().async_added_to_hass()
super()._async_setup_templates()
@callback
def _update_percentage(self, percentage):