1 """Support for VeSync bulbs and wall dimmers."""
17 from .const
import DEV_TYPE_TO_HA, DOMAIN, VS_DISCOVERY, VS_LIGHTS
18 from .entity
import VeSyncDevice
20 _LOGGER = logging.getLogger(__name__)
25 config_entry: ConfigEntry,
26 async_add_entities: AddEntitiesCallback,
32 """Add new devices to platform."""
35 config_entry.async_on_unload(
44 """Check if device is online and add entity."""
47 if DEV_TYPE_TO_HA.get(dev.device_type)
in (
"walldimmer",
"bulb-dimmable"):
49 elif DEV_TYPE_TO_HA.get(dev.device_type)
in (
"bulb-tunable-white",):
53 "%s - Unknown device type - %s", dev.device_name, dev.device_type
61 """Base class for VeSync Light Devices Representations."""
67 """Get light brightness."""
69 result = self.
devicedevice.brightness
72 brightness_value =
int(result)
76 "VeSync - received unexpected 'brightness' value from pyvesync api: %s",
81 return round((
max(1, brightness_value) / 100) * 255)
84 """Turn the device on."""
85 attribute_adjustment_only =
False
89 color_temp =
int(kwargs[ATTR_COLOR_TEMP])
98 color_temp = 100 - color_temp
100 color_temp =
max(0,
min(color_temp, 100))
102 self.
devicedevice.set_color_temp(color_temp)
104 attribute_adjustment_only =
True
108 and ATTR_BRIGHTNESS
in kwargs
111 brightness =
int(kwargs[ATTR_BRIGHTNESS])
113 brightness =
max(1,
min(brightness, 255))
115 brightness = round((brightness / 255) * 100)
117 brightness =
max(1,
min(brightness, 100))
119 self.
devicedevice.set_brightness(brightness)
122 attribute_adjustment_only =
True
124 if attribute_adjustment_only:
131 """Representation of a VeSync dimmable light device."""
133 _attr_color_mode = ColorMode.BRIGHTNESS
134 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
138 """Representation of a VeSync Tunable White Light device."""
140 _attr_color_mode = ColorMode.COLOR_TEMP
141 _attr_max_mireds = 370
142 _attr_min_mireds = 154
143 _attr_supported_color_modes = {ColorMode.COLOR_TEMP}
147 """Get device white temperature."""
149 result = self.
devicedevice.color_temp_pct
152 color_temp_value =
int(result)
157 "VeSync - received unexpected 'color_temp_pct' value from pyvesync"
164 color_temp_value = 100 - color_temp_value
166 color_temp_value =
max(0,
min(color_temp_value, 100))
168 color_temp_value = round(
ColorMode|str|None color_mode(self)
None turn_on(self, **Any kwargs)
list[tuple[str, int]] discover(HomeAssistant hass)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def _setup_entities(devices, async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)