mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
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:
parent
dfad1a920f
commit
efcaad1179
@ -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(
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user