Fix supported _color_modes attribute not set for on/off MQTT JSON light (#152126)

This commit is contained in:
Jan Bouwhuis
2025-09-12 20:20:41 +00:00
committed by Franck Nijhof
parent 9a165a64fe
commit d2e7537629
2 changed files with 15 additions and 0 deletions
@@ -223,6 +223,8 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
# Brightness is supported and no supported_color_modes are set,
# so set brightness as the supported color mode.
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
else:
self._attr_supported_color_modes = {ColorMode.ONOFF}
def _update_color(self, values: dict[str, Any]) -> None:
color_mode: str = values["color_mode"]
+13
View File
@@ -182,6 +182,19 @@ class JsonValidator:
return json_loads(self.jsondata) == json_loads(other)
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_simple_on_off_light(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test if setup fails with no command topic."""
assert await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state and state.state == STATE_UNKNOWN
assert state.attributes["supported_color_modes"] == ["onoff"]
@pytest.mark.parametrize(
"hass_config", [{mqtt.DOMAIN: {light.DOMAIN: {"schema": "json", "name": "test"}}}]
)