Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions homeassistant/components/smartthings/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
r2xj marked this conversation as resolved.
color_modes = set()
if "off" not in levels or len(levels) > 2:
color_modes.add(ColorMode.BRIGHTNESS)
Expand All @@ -318,15 +320,15 @@ 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:
await self.async_set_level(255)

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(
Expand Down Expand Up @@ -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
):
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tests/components/smartthings/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Loading