1 """Support for Yeelight Sunflower color bulbs (not Yeelight Blue or WiFi)."""
3 from __future__
import annotations
8 import voluptuous
as vol
9 import yeelightsunflower
14 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
25 _LOGGER = logging.getLogger(__name__)
27 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
33 add_entities: AddEntitiesCallback,
34 discovery_info: DiscoveryInfoType |
None =
None,
36 """Set up the Yeelight Sunflower Light platform."""
37 host = config.get(CONF_HOST)
38 hub = yeelightsunflower.Hub(host)
41 _LOGGER.error(
"Could not connect to Yeelight Sunflower hub")
48 """Representation of a Yeelight Sunflower Light."""
50 _attr_color_mode = ColorMode.HS
51 _attr_supported_color_modes = {ColorMode.HS}
53 def __init__(self, light: yeelightsunflower.Bulb) ->
None:
54 """Initialize a Yeelight Sunflower bulb."""
61 self.
_attr_name_attr_name = f
"sunflower_{self._light.zid}"
65 """Return the brightness is 0-255; Yeelight's brightness is 0-100."""
70 """Return the color property."""
71 return color_util.color_RGB_to_hs(*self.
_rgb_color_rgb_color)
74 """Instruct the light to turn on, optionally set colour/brightness."""
78 elif ATTR_HS_COLOR
in kwargs
and ATTR_BRIGHTNESS
in kwargs:
79 rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
80 bright =
int(kwargs[ATTR_BRIGHTNESS] / 255 * 100)
81 self.
_light_light.set_all(rgb[0], rgb[1], rgb[2], bright)
82 elif ATTR_HS_COLOR
in kwargs:
83 rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
84 self.
_light_light.set_rgb_color(rgb[0], rgb[1], rgb[2])
85 elif ATTR_BRIGHTNESS
in kwargs:
86 bright =
int(kwargs[ATTR_BRIGHTNESS] / 255 * 100)
87 self.
_light_light.set_brightness(bright)
90 """Instruct the light to turn off."""
94 """Fetch new state data for this light and update local values."""
None turn_on(self, **Any kwargs)
None __init__(self, yeelightsunflower.Bulb light)
tuple[float, float] hs_color(self)
None turn_off(self, **Any kwargs)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)