Skip to content

Commit d2e7537

Browse files
jbouwhfrenck
authored andcommitted
Fix supported _color_modes attribute not set for on/off MQTT JSON light (home-assistant#152126)
1 parent 9a165a6 commit d2e7537

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

homeassistant/components/mqtt/light/schema_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ def _setup_from_config(self, config: ConfigType) -> None:
223223
# Brightness is supported and no supported_color_modes are set,
224224
# so set brightness as the supported color mode.
225225
self._attr_supported_color_modes = {ColorMode.BRIGHTNESS}
226+
else:
227+
self._attr_supported_color_modes = {ColorMode.ONOFF}
226228

227229
def _update_color(self, values: dict[str, Any]) -> None:
228230
color_mode: str = values["color_mode"]

tests/components/mqtt/test_light_json.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ def __eq__(self, other: bytes | str) -> bool: # type:ignore[override]
182182
return json_loads(self.jsondata) == json_loads(other)
183183

184184

185+
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
186+
async def test_simple_on_off_light(
187+
hass: HomeAssistant,
188+
mqtt_mock_entry: MqttMockHAClientGenerator,
189+
caplog: pytest.LogCaptureFixture,
190+
) -> None:
191+
"""Test if setup fails with no command topic."""
192+
assert await mqtt_mock_entry()
193+
state = hass.states.get("light.test")
194+
assert state and state.state == STATE_UNKNOWN
195+
assert state.attributes["supported_color_modes"] == ["onoff"]
196+
197+
185198
@pytest.mark.parametrize(
186199
"hass_config", [{mqtt.DOMAIN: {light.DOMAIN: {"schema": "json", "name": "test"}}}]
187200
)

0 commit comments

Comments
 (0)