1 """Support for Lagute LW-12 WiFi LED Controller."""
3 from __future__
import annotations
9 import voluptuous
as vol
16 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
28 _LOGGER = logging.getLogger(__name__)
31 DEFAULT_NAME =
"LW-12 FC"
34 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
36 vol.Required(CONF_HOST): cv.string,
37 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
38 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
46 add_entities: AddEntitiesCallback,
47 discovery_info: DiscoveryInfoType |
None =
None,
49 """Set up LW-12 WiFi LED Controller platform."""
51 name = config.get(CONF_NAME)
52 host = config.get(CONF_HOST)
53 port = config.get(CONF_PORT)
55 lw12_light = lw12.LW12Controller(host, port)
60 """LW-12 WiFi LED Controller."""
62 _attr_color_mode = ColorMode.HS
63 _attr_should_poll =
False
64 _attr_supported_color_modes = {ColorMode.HS}
65 _attr_supported_features = LightEntityFeature.EFFECT | LightEntityFeature.TRANSITION
68 """Initialise LW-12 WiFi LED Controller.
70 :param name: Friendly name for this platform to use.
71 :param lw12_light: Instance of the LW12 controller.
82 """Return the display name of the controlled light."""
83 return self.
_name_name
87 """Return the brightness of the light."""
92 """Read back the hue-saturation of the light."""
93 return color_util.color_RGB_to_hs(*self.
_rgb_color_rgb_color)
97 """Return current light effect."""
100 return self.
_effect_effect.replace(
"_",
" ").title()
104 """Return true if light is on."""
109 """Return a list of available effects.
111 Use the Enum element name for display.
113 return [effect.name.replace(
"_",
" ").title()
for effect
in lw12.LW12_EFFECT]
117 """Return True if unable to access real state of the entity."""
121 """Instruct the light to turn on."""
122 self.
_light_light.light_on()
123 if ATTR_HS_COLOR
in kwargs:
124 self.
_rgb_color_rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
127 if ATTR_BRIGHTNESS
in kwargs:
128 self.
_brightness_brightness = kwargs[ATTR_BRIGHTNESS]
130 self.
_light_light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, brightness)
131 if ATTR_EFFECT
in kwargs:
132 self.
_effect_effect = kwargs[ATTR_EFFECT].replace(
" ",
"_").upper()
134 if self.
_effect_effect
in [eff.name
for eff
in lw12.LW12_EFFECT]:
136 self.
_light_light.set_effect(lw12.LW12_EFFECT[self.
_effect_effect])
140 _LOGGER.error(
"Unknown effect selected: %s", self.
_effect_effect)
142 if ATTR_TRANSITION
in kwargs:
143 transition_speed =
int(kwargs[ATTR_TRANSITION])
144 self.
_light_light.set_light_option(lw12.LW12_LIGHT.FLASH, transition_speed)
148 """Instruct the light to turn off."""
149 self.
_light_light.light_off()
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
def __init__(self, name, lw12_light)
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)