Remove unnecessary assignment of Template.hass from template (#123773)
This commit is contained in:
parent
5837450a05
commit
dc462aa529
15 changed files with 39 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue