Ensure an entity platform is added in mqtt tests (#134331)

This commit is contained in:
Jan Bouwhuis 2024-12-31 23:01:55 +01:00 committed by GitHub
parent 1d6ecbd1d5
commit 8098122dfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,6 +44,7 @@ from homeassistant.util.dt import utcnow
from tests.common import ( from tests.common import (
MockConfigEntry, MockConfigEntry,
MockEntity, MockEntity,
MockEntityPlatform,
async_fire_mqtt_message, async_fire_mqtt_message,
async_fire_time_changed, async_fire_time_changed,
mock_restore_cache, mock_restore_cache,
@ -194,6 +195,7 @@ async def test_value_template_value(hass: HomeAssistant) -> None:
# test value template with entity # test value template with entity
entity = Entity() entity = Entity()
entity.hass = hass entity.hass = hass
entity.platform = MockEntityPlatform(hass)
entity.entity_id = "select.test" entity.entity_id = "select.test"
tpl = template.Template("{{ value_json.id }}", hass=hass) tpl = template.Template("{{ value_json.id }}", hass=hass)
val_tpl = mqtt.MqttValueTemplate(tpl, entity=entity) val_tpl = mqtt.MqttValueTemplate(tpl, entity=entity)
@ -218,6 +220,7 @@ async def test_value_template_fails(hass: HomeAssistant) -> None:
"""Test the rendering of MQTT value template fails.""" """Test the rendering of MQTT value template fails."""
entity = MockEntity(entity_id="sensor.test") entity = MockEntity(entity_id="sensor.test")
entity.hass = hass entity.hass = hass
entity.platform = MockEntityPlatform(hass)
tpl = template.Template("{{ value_json.some_var * 2 }}", hass=hass) tpl = template.Template("{{ value_json.some_var * 2 }}", hass=hass)
val_tpl = mqtt.MqttValueTemplate(tpl, entity=entity) val_tpl = mqtt.MqttValueTemplate(tpl, entity=entity)
with pytest.raises(MqttValueTemplateException) as exc: with pytest.raises(MqttValueTemplateException) as exc: