From 179cc4d7f78b685e7f8cdac7ed13ee85ae08ce43 Mon Sep 17 00:00:00 2001 From: anotherthomas Date: Mon, 13 Mar 2023 14:46:16 +0100 Subject: [PATCH] Improve warnings in mqtt light messages (#89552) * improved warnings in mqtt light messages. * fixed tests. --- .../components/mqtt/light/schema_json.py | 25 +++++++++++++------ tests/components/mqtt/test_light_json.py | 12 ++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/mqtt/light/schema_json.py b/homeassistant/components/mqtt/light/schema_json.py index 55b2f99d536..e0b20436fe6 100644 --- a/homeassistant/components/mqtt/light/schema_json.py +++ b/homeassistant/components/mqtt/light/schema_json.py @@ -260,7 +260,9 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): pass except ValueError: _LOGGER.warning( - "Invalid RGB color value received for entity %s", self.entity_id + "Invalid RGB color value '%s' received for entity %s", + values, + self.entity_id, ) return @@ -272,7 +274,9 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): pass except ValueError: _LOGGER.warning( - "Invalid XY color value received for entity %s", self.entity_id + "Invalid XY color value '%s' received for entity %s", + values, + self.entity_id, ) return @@ -284,14 +288,18 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): pass except ValueError: _LOGGER.warning( - "Invalid HS color value received for entity %s", self.entity_id + "Invalid HS color value '%s' received for entity %s", + values, + self.entity_id, ) return else: color_mode: str = values["color_mode"] if not self._supports_color_mode(color_mode): _LOGGER.warning( - "Invalid color mode received for entity %s", self.entity_id + "Invalid color mode '%s' received for entity %s", + color_mode, + self.entity_id, ) return try: @@ -333,7 +341,8 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): self._attr_xy_color = (x, y) except (KeyError, ValueError): _LOGGER.warning( - "Invalid or incomplete color value received for entity %s", + "Invalid or incomplete color value '%s' received for entity %s", + values, self.entity_id, ) @@ -378,7 +387,8 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): pass except (TypeError, ValueError): _LOGGER.warning( - "Invalid brightness value received for entity %s", + "Invalid brightness value '%s' received for entity %s", + values["brightness"], self.entity_id, ) @@ -397,7 +407,8 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity): pass except ValueError: _LOGGER.warning( - "Invalid color temp value received for entity %s", + "Invalid color temp value '%s' received for entity %s", + values["color_temp"], self.entity_id, ) diff --git a/tests/components/mqtt/test_light_json.py b/tests/components/mqtt/test_light_json.py index be664d1c1f8..dc73d7e6d1b 100644 --- a/tests/components/mqtt/test_light_json.py +++ b/tests/components/mqtt/test_light_json.py @@ -616,14 +616,17 @@ async def test_controlling_state_via_topic2( async_fire_mqtt_message( hass, "test_light_rgb", '{"state":"ON", "color_mode":"col_temp"}' ) - assert "Invalid color mode received" in caplog.text + assert "Invalid color mode 'col_temp' received" in caplog.text caplog.clear() # Incomplete color async_fire_mqtt_message( hass, "test_light_rgb", '{"state":"ON", "color_mode":"rgb"}' ) - assert "Invalid or incomplete color value received" in caplog.text + assert ( + "Invalid or incomplete color value '{'state': 'ON', 'color_mode': 'rgb'}' received" + in caplog.text + ) caplog.clear() # Invalid color @@ -632,7 +635,10 @@ async def test_controlling_state_via_topic2( "test_light_rgb", '{"state":"ON", "color_mode":"rgb", "color":{"r":64,"g":128,"b":"cow"}}', ) - assert "Invalid or incomplete color value received" in caplog.text + assert ( + "Invalid or incomplete color value '{'state': 'ON', 'color_mode': 'rgb', 'color': {'r': 64, 'g': 128, 'b': 'cow'}}' received" + in caplog.text + ) async def test_sending_mqtt_commands_and_optimistic(