Improve error logging on invalid MQTT entity state (#118006)

* Improve error logging on invalid MQTT entity state

* Explain not hanlding TpeError and ValueError

* Move length check closer to source

* use _LOGGER.exception
This commit is contained in:
Jan Bouwhuis 2024-05-24 13:11:52 +02:00 committed by GitHub
parent 7d44321f0f
commit f12aee28a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 106 additions and 12 deletions

View file

@ -110,6 +110,36 @@ async def test_setting_sensor_value_via_mqtt_message(
assert state.attributes.get("unit_of_measurement") == "fav unit"
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
sensor.DOMAIN: {
"name": "test",
"state_topic": "test-topic",
}
}
},
],
)
async def test_setting_sensor_to_long_state_via_mqtt_message(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the setting of the value via MQTT."""
await mqtt_mock_entry()
async_fire_mqtt_message(hass, "test-topic", "".join("x" for _ in range(310)))
state = hass.states.get("sensor.test")
await hass.async_block_till_done()
assert state.state == STATE_UNKNOWN
assert "Cannot update state for entity sensor.test" in caplog.text
@pytest.mark.parametrize(
("hass_config", "device_class", "native_value", "state_value", "log"),
[