diff --git a/homeassistant/components/smartthings/light.py b/homeassistant/components/smartthings/light.py index 426fb6f9b85be..62851d409fdb9 100644 --- a/homeassistant/components/smartthings/light.py +++ b/homeassistant/components/smartthings/light.py @@ -304,6 +304,8 @@ def __init__( ) or [] ) + # If "off" is in supported levels, the switch doesn't control the lamp + self._use_switch = "off" not in levels color_modes = set() if "off" not in levels or len(levels) > 2: color_modes.add(ColorMode.BRIGHTNESS) @@ -318,7 +320,7 @@ async def async_turn_on(self, **kwargs: Any) -> None: if ATTR_BRIGHTNESS in kwargs: await self.async_set_level(kwargs[ATTR_BRIGHTNESS]) return - if self.supports_capability(Capability.SWITCH): + if self._use_switch and self.supports_capability(Capability.SWITCH): await self.execute_device_command(Capability.SWITCH, Command.ON) # if no switch, turn on via brightness level else: @@ -326,7 +328,7 @@ async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None: """Turn the lamp off.""" - if self.supports_capability(Capability.SWITCH): + if self._use_switch and self.supports_capability(Capability.SWITCH): await self.execute_device_command(Capability.SWITCH, Command.OFF) return await self.execute_device_command( @@ -356,7 +358,8 @@ async def async_set_level(self, brightness: int) -> None: ) # turn on switch separately if needed if ( - self.supports_capability(Capability.SWITCH) + self._use_switch + and self.supports_capability(Capability.SWITCH) and not self.is_on and brightness > 0 ): @@ -387,7 +390,7 @@ def _update_attr(self) -> None: @property def is_on(self) -> bool | None: """Return true if lamp is on.""" - if self.supports_capability(Capability.SWITCH): + if self._use_switch and self.supports_capability(Capability.SWITCH): state = self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH) if state is None: return None diff --git a/tests/components/smartthings/test_light.py b/tests/components/smartthings/test_light.py index d51686a14080b..7e581b53c3742 100644 --- a/tests/components/smartthings/test_light.py +++ b/tests/components/smartthings/test_light.py @@ -642,3 +642,42 @@ async def test_lamp_unknown_brightness( ) assert hass.states.get("light.vulcan_light").state == STATE_UNKNOWN + + +@pytest.mark.parametrize("device_fixture", ["da_ks_hood_01001"]) +@pytest.mark.parametrize( + ("service", "argument"), + [(SERVICE_TURN_ON, "high"), (SERVICE_TURN_OFF, "off")], +) +async def test_lamp_switch_not_used_when_off_in_supported_levels( + hass: HomeAssistant, + devices: AsyncMock, + mock_config_entry: MockConfigEntry, + service: str, + argument: str, +) -> None: + """Test samsungce.lamp on/off uses brightness commands when 'off' is in supported levels, even with switch capability.""" + # Modify the device status to include "off" in supported brightness levels + # This simulates a device where the switch doesn't control the lamp + set_attribute_value( + devices, + Capability.SAMSUNG_CE_LAMP, + Attribute.SUPPORTED_BRIGHTNESS_LEVEL, + ["off", "low", "high"], + component="lamp", + ) + await setup_integration(hass, mock_config_entry) + + await hass.services.async_call( + LIGHT_DOMAIN, + service, + {ATTR_ENTITY_ID: "light.range_hood_light"}, + blocking=True, + ) + devices.execute_device_command.assert_called_once_with( + "fa5fca25-fa7a-1807-030a-2f72ee0f7bff", + Capability.SAMSUNG_CE_LAMP, + Command.SET_BRIGHTNESS_LEVEL, + "lamp", + argument=argument, + )