Handle template errors on MQTT payload handling (#110180)
* Handle template errors on MQTT payload handling (alt) * Handle mqtt event en image template errors correctly
This commit is contained in:
parent
ee25f6b960
commit
09f1ec78a5
32 changed files with 859 additions and 22 deletions
|
@ -396,3 +396,59 @@ async def test_name_attribute_is_set_or_not(
|
|||
|
||||
assert state is not None
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
sensor.DOMAIN: {
|
||||
"name": "test",
|
||||
"state_topic": "state-topic",
|
||||
"availability_topic": "test-topic",
|
||||
"availability_template": "{{ value_json.some_var * 1 }}",
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
sensor.DOMAIN: {
|
||||
"name": "test",
|
||||
"state_topic": "state-topic",
|
||||
"availability": {
|
||||
"topic": "test-topic",
|
||||
"value_template": "{{ value_json.some_var * 1 }}",
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
sensor.DOMAIN: {
|
||||
"name": "test",
|
||||
"state_topic": "state-topic",
|
||||
"json_attributes_topic": "test-topic",
|
||||
"json_attributes_template": "{{ value_json.some_var * 1 }}",
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
ids=[
|
||||
"availability_template1",
|
||||
"availability_template2",
|
||||
"json_attributes_template",
|
||||
],
|
||||
)
|
||||
async def test_value_template_fails(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the rendering of MQTT value template fails."""
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, "test-topic", '{"some_var": null }')
|
||||
assert (
|
||||
"TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' rendering template"
|
||||
in caplog.text
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue