1 """WiZ integration light platform."""
3 from __future__
import annotations
7 from pywizlight
import PilotBuilder
8 from pywizlight.bulblibrary
import BulbClass, BulbType, Features
9 from pywizlight.scenes
import get_id_from_scene_name
20 filter_supported_color_modes,
25 color_temperature_kelvin_to_mired,
26 color_temperature_mired_to_kelvin,
29 from .
import WizConfigEntry
30 from .entity
import WizToggleEntity
31 from .models
import WizData
33 RGB_WHITE_CHANNELS_COLOR_MODE = {1: ColorMode.RGBW, 2: ColorMode.RGBWW}
37 """Create the PilotBuilder for turn on."""
38 brightness = kwargs.get(ATTR_BRIGHTNESS)
40 if ATTR_RGBWW_COLOR
in kwargs:
41 return PilotBuilder(brightness=brightness, rgbww=kwargs[ATTR_RGBWW_COLOR])
43 if ATTR_RGBW_COLOR
in kwargs:
44 return PilotBuilder(brightness=brightness, rgbw=kwargs[ATTR_RGBW_COLOR])
46 if ATTR_COLOR_TEMP
in kwargs:
48 brightness=brightness,
52 if ATTR_EFFECT
in kwargs:
53 scene_id = get_id_from_scene_name(kwargs[ATTR_EFFECT])
56 return PilotBuilder(brightness=brightness, scene=scene_id)
58 return PilotBuilder(brightness=brightness)
63 entry: WizConfigEntry,
64 async_add_entities: AddEntitiesCallback,
66 """Set up the WiZ Platform from config_flow."""
67 if entry.runtime_data.bulb.bulbtype.bulb_type != BulbClass.SOCKET:
72 """Representation of WiZ Light bulb."""
75 _fixed_color_mode: ColorMode |
None =
None
77 def __init__(self, wiz_data: WizData, name: str) ->
None:
78 """Initialize an WiZLight."""
80 bulb_type: BulbType = self.
_device_device.bulbtype
81 features: Features = bulb_type.features
82 color_modes = {ColorMode.ONOFF}
84 color_modes.add(RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels])
85 if features.color_tmp:
86 color_modes.add(ColorMode.COLOR_TEMP)
87 if features.brightness:
88 color_modes.add(ColorMode.BRIGHTNESS)
94 if bulb_type.bulb_type != BulbClass.DW:
95 kelvin = bulb_type.kelvin_range
98 if bulb_type.features.effect:
104 """Handle updating _attr values."""
105 state = self.
_device_device.state
107 assert color_modes
is not None
108 if (brightness := state.get_brightness())
is not None:
110 if ColorMode.COLOR_TEMP
in color_modes
and (
111 color_temp := state.get_colortemp()
116 ColorMode.RGBWW
in color_modes
and (rgbww := state.get_rgbww())
is not None
120 elif ColorMode.RGBW
in color_modes
and (rgbw := state.get_rgbw())
is not None:
127 """Instruct the light to turn on."""
set[ColorMode]|set[str]|None supported_color_modes(self)
None _async_update_attrs(self)
None _async_update_attrs(self)
None __init__(self, WizData wiz_data, str name)
None async_turn_on(self, **Any kwargs)
_attr_supported_color_modes
None _async_update_attrs(self)
None turn_on(self, **Any kwargs)
None async_request_refresh(self)
set[ColorMode] filter_supported_color_modes(Iterable[ColorMode] color_modes)
None async_setup_entry(HomeAssistant hass, WizConfigEntry entry, AddEntitiesCallback async_add_entities)
PilotBuilder _async_pilot_builder(**Any kwargs)
int color_temperature_mired_to_kelvin(float mired_temperature)
int color_temperature_kelvin_to_mired(float kelvin_temperature)