Improve MQTT json color_temp validation (#133174)

* Improve MQTT json color_temp validation

* Revert unrelated changes and assert on logs

* Typo
This commit is contained in:
Jan Bouwhuis 2024-12-15 13:07:10 +01:00 committed by GitHub
parent 74e4654c26
commit 16ad2d52c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -490,7 +490,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
)
except KeyError:
pass
except ValueError:
except (TypeError, ValueError):
_LOGGER.warning(
"Invalid color temp value '%s' received for entity %s",
values["color_temp"],

View File

@ -2185,7 +2185,9 @@ async def test_white_scale(
],
)
async def test_invalid_values(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test that invalid color/brightness/etc. values are ignored."""
await mqtt_mock_entry()
@ -2287,6 +2289,10 @@ async def test_invalid_values(
async_fire_mqtt_message(
hass, "test_light_rgb", '{"state":"ON", "color_temp": "badValue"}'
)
assert (
"Invalid color temp value 'badValue' received for entity light.test"
in caplog.text
)
# Color temperature should not have changed
state = hass.states.get("light.test")