Improve warnings in mqtt light messages (#89552)
* improved warnings in mqtt light messages. * fixed tests.
This commit is contained in:
parent
3637d787cf
commit
179cc4d7f7
2 changed files with 27 additions and 10 deletions
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue