1 """Support for Belkin WeMo lights."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pywemo
import Bridge, BridgeLight, Dimmer
24 from .
import async_wemo_dispatcher_connect
25 from .const
import DOMAIN
as WEMO_DOMAIN
26 from .coordinator
import DeviceCoordinator
27 from .entity
import WemoBinaryStateEntity, WemoEntity
35 config_entry: ConfigEntry,
36 async_add_entities: AddEntitiesCallback,
38 """Set up WeMo lights."""
40 async
def _discovered_wemo(coordinator: DeviceCoordinator) ->
None:
41 """Handle a discovered Wemo device."""
42 if isinstance(coordinator.wemo, Bridge):
53 config_entry: ConfigEntry,
54 async_add_entities: AddEntitiesCallback,
55 coordinator: DeviceCoordinator,
57 """Set up a WeMo link."""
58 known_light_ids = set()
61 def async_update_lights() -> None:
62 """Check to see if the bridge has any new lights."""
65 bridge = cast(Bridge, coordinator.wemo)
66 for light_id, light
in bridge.Lights.items():
67 if light_id
not in known_light_ids:
68 known_light_ids.add(light_id)
69 new_lights.append(
WemoLight(coordinator, light))
74 config_entry.async_on_unload(coordinator.async_add_listener(async_update_lights))
78 """Representation of a WeMo light."""
80 _attr_supported_features = LightEntityFeature.TRANSITION
82 def __init__(self, coordinator: DeviceCoordinator, light: BridgeLight) ->
None:
83 """Initialize the WeMo light."""
91 """Return the name of the device if any."""
92 return self.
lightlight.name
96 """Return true if the device is available."""
97 return super().available
and self.
lightlight.state.get(
"available",
False)
101 """Return the ID of this light."""
102 return self.
lightlight.uniqueID
106 """Return the device info."""
108 connections={(CONNECTION_ZIGBEE, self.
_unique_id_unique_id)},
109 identifiers={(WEMO_DOMAIN, self.
_unique_id_unique_id)},
110 manufacturer=
"Belkin",
117 """Return the brightness of this light between 0..255."""
118 return self.
lightlight.state.get(
"level", 255)
122 """Return the xy color value [float, float]."""
123 return self.
lightlight.state.get(
"color_xy")
127 """Return the color temperature of this light in mireds."""
128 return self.
lightlight.state.get(
"temperature_mireds")
132 """Return the color mode of the light."""
134 "colorcontrol" in self.
lightlight.capabilities
135 and self.
lightlight.state.get(
"color_xy")
is not None
138 if "colortemperature" in self.
lightlight.capabilities:
139 return ColorMode.COLOR_TEMP
140 if "levelcontrol" in self.
lightlight.capabilities:
141 return ColorMode.BRIGHTNESS
142 return ColorMode.ONOFF
146 """Flag supported color modes."""
147 modes: set[ColorMode] = set()
148 if "colorcontrol" in self.
lightlight.capabilities:
149 modes.add(ColorMode.XY)
150 if "colortemperature" in self.
lightlight.capabilities:
151 modes.add(ColorMode.COLOR_TEMP)
152 if "levelcontrol" in self.
lightlight.capabilities
and not modes:
153 modes.add(ColorMode.BRIGHTNESS)
155 modes.add(ColorMode.ONOFF)
160 """Return true if device is on."""
161 return self.
lightlight.state.get(
"onoff", WEMO_OFF) != WEMO_OFF
164 """Turn the light on."""
168 color_temp = kwargs.get(ATTR_COLOR_TEMP)
169 hs_color = kwargs.get(ATTR_HS_COLOR)
170 transition_time =
int(kwargs.get(ATTR_TRANSITION, 0))
172 if hs_color
is not None:
173 xy_color = color_util.color_hs_to_xy(*hs_color)
177 "transition": transition_time,
178 "force_update":
False,
182 if xy_color
is not None:
183 self.
lightlight.set_color(xy_color, transition=transition_time)
185 if color_temp
is not None:
186 self.
lightlight.set_temperature(
187 mireds=color_temp, transition=transition_time
193 """Turn the light off."""
194 transition_time =
int(kwargs.get(ATTR_TRANSITION, 0))
201 """Representation of a WeMo dimmer."""
203 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
204 _attr_color_mode = ColorMode.BRIGHTNESS
209 """Return the brightness of this light between 1 and 100."""
210 wemo_brightness: int = self.
wemowemowemo.get_brightness()
211 return int((wemo_brightness * 255) / 100)
214 """Turn the dimmer on."""
217 if ATTR_BRIGHTNESS
in kwargs:
218 brightness = kwargs[ATTR_BRIGHTNESS]
219 brightness =
int((brightness / 255) * 100)
221 self.
wemowemowemo.set_brightness(brightness)
227 """Turn the dimmer off."""
int|None brightness(self)
Generator[None] _wemo_call_wrapper(self, str message)
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
ColorMode color_mode(self)
set[ColorMode] supported_color_modes(self)
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
int|None color_temp(self)
tuple[float, float]|None xy_color(self)
None __init__(self, DeviceCoordinator coordinator, BridgeLight light)
str|UndefinedType|None name(self)
None async_setup_bridge(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities, DeviceCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_wemo_dispatcher_connect(HomeAssistant hass, DispatchCallback dispatch)