Fix handling MQTT light brightness from zero rgb (#96286)

* Fix handling MQTT light brightness from zero rgb

* Fix log message
This commit is contained in:
Jan Bouwhuis 2023-07-11 20:22:12 +02:00 committed by GitHub
parent dfad1a920f
commit efcaad1179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -482,6 +482,13 @@ class MqttLight(MqttEntity, LightEntity, RestoreEntity):
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None:
rgb = convert_color(*color)
brightness = max(rgb)
if brightness == 0:
_LOGGER.debug(
"Ignoring %s message with zero rgb brightness from '%s'",
color_mode,
msg.topic,
)
return None
self._attr_brightness = brightness
# Normalize the color to 100% brightness
color = tuple(

View File

@ -666,6 +666,12 @@ async def test_brightness_from_rgb_controlling_scale(
assert state.attributes.get("brightness") == 128
assert state.attributes.get("rgb_color") == (255, 128, 64)
# Test zero rgb is ignored
async_fire_mqtt_message(hass, "test_scale_rgb/rgb/status", "0,0,0")
state = hass.states.get("light.test")
assert state.attributes.get("brightness") == 128
assert state.attributes.get("rgb_color") == (255, 128, 64)
mqtt_mock.async_publish.reset_mock()
await common.async_turn_on(hass, "light.test", brightness=191)
await hass.async_block_till_done()