mirror of
https://github.com/home-assistant/core.git
synced 2026-09-05 10:05:52 -05:00
Fix supported _color_modes attribute not set for on/off MQTT JSON light (#152126)
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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"}}}]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user