mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 22:10:09 +00:00
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:
@@ -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"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user