Add more light models to SwitchBot Cloud (#150986)

This commit is contained in:
Samuel Xiao
2025-09-11 18:39:29 +02:00
committed by GitHub
parent a368ad4ab5
commit 937d3e4a96
2 changed files with 10 additions and 2 deletions
@@ -247,6 +247,8 @@ async def make_device_data(
"Strip Light 3",
"Floor Lamp",
"Color Bulb",
"RGBICWW Floor Lamp",
"RGBICWW Strip Light",
]:
coordinator = await coordinator_for_device(
hass, entry, api, device, coordinators_by_id
@@ -27,6 +27,11 @@ def value_map_brightness(value: int) -> int:
return int(value / 255 * 100)
def brightness_map_value(value: int) -> int:
"""Return brightness from map value."""
return int(value * 255 / 100)
async def async_setup_entry(
hass: HomeAssistant,
config: ConfigEntry,
@@ -52,13 +57,14 @@ class SwitchBotCloudLight(SwitchBotCloudEntity, LightEntity):
"""Set attributes from coordinator data."""
if self.coordinator.data is None:
return
power: str | None = self.coordinator.data.get("power")
brightness: int | None = self.coordinator.data.get("brightness")
color: str | None = self.coordinator.data.get("color")
color_temperature: int | None = self.coordinator.data.get("colorTemperature")
self._attr_is_on = power == "on" if power else None
self._attr_brightness: int | None = brightness if brightness else None
self._attr_brightness: int | None = (
brightness_map_value(brightness) if brightness else None
)
self._attr_rgb_color: tuple | None = (
(tuple(int(i) for i in color.split(":"))) if color else None
)