Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions homeassistant/components/switchbot_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ async def make_device_data(
"Color Bulb",
"RGBICWW Floor Lamp",
"RGBICWW Strip Light",
"Ceiling Light",
"Ceiling Light Pro",
]:
coordinator = await coordinator_for_device(
hass, entry, api, device, coordinators_by_id
Expand Down
28 changes: 27 additions & 1 deletion homeassistant/components/switchbot_cloud/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any

from switchbot_api import (
CeilingLightCommands,
CommonCommands,
Device,
Remote,
Expand Down Expand Up @@ -149,11 +150,36 @@ async def _send_rgb_color_command(self, rgb_color: tuple) -> None:
)


class SwitchBotCloudCeilingLight(SwitchBotCloudLight):
"""Representation of SwitchBot Ceiling Light."""

_attr_max_color_temp_kelvin = 6500
_attr_min_color_temp_kelvin = 2700

_attr_supported_color_modes = {ColorMode.COLOR_TEMP}

async def _send_brightness_command(self, brightness: int) -> None:
"""Send a brightness command."""
await self.send_api_command(
CeilingLightCommands.SET_BRIGHTNESS,
parameters=str(value_map_brightness(brightness)),
)

async def _send_color_temperature_command(self, color_temp_kelvin: int) -> None:
"""Send a color temperature command."""
await self.send_api_command(
CeilingLightCommands.SET_COLOR_TEMPERATURE,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These, arguably, could be the same commands as RGBWWLightCommands, since they use the same actual commands (here: https://github.com/SeraphicCorp/py-switchbot-api/blob/main/switchbot_api/commands.py#L294C30-L294C49).

But they're separate on the py-switchbot-api side, so I've left them distinct here too. Maybe we should unify that somehow?

parameters=str(color_temp_kelvin),
)

Comment on lines +164 to +185

Copilot AI Dec 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new SwitchBotCloudCeilingLight class lacks test coverage. Tests should be added to verify:

  1. Turn on/off functionality
  2. Brightness control using CeilingLightCommands.SET_BRIGHTNESS
  3. Color temperature control using CeilingLightCommands.SET_COLOR_TEMPERATURE
  4. Supported color modes (only COLOR_TEMP)
  5. Temperature range enforcement (2700-6500K)

Other light types in this integration have comprehensive tests (see test_strip_light_turn_on, test_rgbww_light_turn_on). Similar tests should be added for ceiling lights.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that can happen in this PR


Comment on lines +185 to +186

Copilot AI Dec 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base class async_turn_on method sets _attr_color_mode = ColorMode.RGB when adjusting brightness (line 88) or when turning on without parameters (line 97). However, SwitchBotCloudCeilingLight only supports ColorMode.COLOR_TEMP. This mismatch could cause the entity to report an incorrect color mode.

Consider overriding async_turn_on in SwitchBotCloudCeilingLight to set the correct color mode, or adjust the base class logic to check the supported color modes before setting the color mode.

Suggested change
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the ceiling light with the correct color mode."""
# Only COLOR_TEMP is supported
if (brightness := kwargs.get("brightness")) is not None:
await self._send_brightness_command(brightness)
if (color_temp := kwargs.get("color_temp_kelvin")) is not None:
await self._send_color_temperature_command(color_temp)
if not kwargs:
await self.send_api_command(CommonCommands.TURN_ON)
self._attr_is_on = True
self._attr_color_mode = ColorMode.COLOR_TEMP
await asyncio.sleep(AFTER_COMMAND_REFRESH)
await self.coordinator.async_request_refresh()

Copilot uses AI. Check for mistakes.
@callback
def _async_make_entity(
api: SwitchBotAPI, device: Device | Remote, coordinator: SwitchBotCoordinator
) -> SwitchBotCloudStripLight | SwitchBotCloudRGBWWLight:
) -> SwitchBotCloudStripLight | SwitchBotCloudRGBWWLight | SwitchBotCloudCeilingLight:
"""Make a SwitchBotCloudLight."""
if device.device_type == "Strip Light":
return SwitchBotCloudStripLight(api, device, coordinator)
if device.device_type in ["Ceiling Light", "Ceiling Light Pro"]:
return SwitchBotCloudCeilingLight(api, device, coordinator)
return SwitchBotCloudRGBWWLight(api, device, coordinator)
Loading