1 """Switchbot integration light platform."""
3 from __future__
import annotations
7 from switchbot
import ColorMode
as SwitchBotColorMode, SwitchbotBaseLight
19 color_temperature_kelvin_to_mired,
20 color_temperature_mired_to_kelvin,
23 from .coordinator
import SwitchbotConfigEntry, SwitchbotDataUpdateCoordinator
24 from .entity
import SwitchbotEntity
26 SWITCHBOT_COLOR_MODE_TO_HASS = {
27 SwitchBotColorMode.RGB: ColorMode.RGB,
28 SwitchBotColorMode.COLOR_TEMP: ColorMode.COLOR_TEMP,
36 entry: SwitchbotConfigEntry,
37 async_add_entities: AddEntitiesCallback,
39 """Set up the switchbot light."""
44 """Representation of switchbot light bulb."""
46 _device: SwitchbotBaseLight
49 def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) ->
None:
50 """Initialize the Switchbot light."""
56 SWITCHBOT_COLOR_MODE_TO_HASS[mode]
for mode
in device.color_modes
62 """Handle updating _attr values."""
66 if device.color_mode == SwitchBotColorMode.COLOR_TEMP:
74 """Instruct the light to turn on."""
75 brightness = round(kwargs.get(ATTR_BRIGHTNESS, self.
brightnessbrightness) / 255 * 100)
80 and ATTR_COLOR_TEMP
in kwargs
82 color_temp = kwargs[ATTR_COLOR_TEMP]
84 await self.
_device_device.set_color_temp(brightness, kelvin)
86 if ATTR_RGB_COLOR
in kwargs:
87 rgb = kwargs[ATTR_RGB_COLOR]
88 await self.
_device_device.set_rgb(brightness, rgb[0], rgb[1], rgb[2])
90 if ATTR_BRIGHTNESS
in kwargs:
91 await self.
_device_device.set_brightness(brightness)
96 """Instruct the light to turn off."""
int|None brightness(self)
set[ColorMode]|set[str]|None supported_color_modes(self)
None _async_update_attrs(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, SwitchbotDataUpdateCoordinator coordinator)
None _async_update_attrs(self)
_attr_supported_color_modes
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, SwitchbotConfigEntry entry, AddEntitiesCallback async_add_entities)
int color_temperature_mired_to_kelvin(float mired_temperature)
int color_temperature_kelvin_to_mired(float kelvin_temperature)