Remove unnecessary assignment of Template.hass from template (#123773)

This commit is contained in:
Erik Montnemery 2024-08-13 11:54:36 +02:00 committed by GitHub
parent 5837450a05
commit dc462aa529
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 39 additions and 32 deletions

View file

@ -11,14 +11,14 @@ async def test_template_entity_requires_hass_set(hass: HomeAssistant) -> None:
"""Test template entity requires hass to be set before accepting templates."""
entity = template_entity.TemplateEntity(hass)
with pytest.raises(AssertionError):
with pytest.raises(ValueError, match="^hass cannot be None"):
entity.add_template_attribute("_hello", template.Template("Hello"))
entity.hass = object()
entity.add_template_attribute("_hello", template.Template("Hello", None))
with pytest.raises(ValueError, match="^template.hass cannot be None"):
entity.add_template_attribute("_hello", template.Template("Hello", None))
tpl_with_hass = template.Template("Hello", entity.hass)
entity.add_template_attribute("_hello", tpl_with_hass)
# Because hass is set in `add_template_attribute`, both templates match `tpl_with_hass`
assert len(entity._template_attrs.get(tpl_with_hass, [])) == 2
assert len(entity._template_attrs.get(tpl_with_hass, [])) == 1