1 """LED BLE integration light platform."""
3 from __future__
import annotations
7 from led_ble
import LEDBLE
25 DataUpdateCoordinator,
28 from .const
import DEFAULT_EFFECT_SPEED, DOMAIN
29 from .models
import LEDBLEData
35 async_add_entities: AddEntitiesCallback,
37 """Set up the light platform for LEDBLE."""
38 data: LEDBLEData = hass.data[DOMAIN][entry.entry_id]
43 """Representation of LEDBLE device."""
45 _attr_supported_color_modes = {ColorMode.RGB, ColorMode.WHITE}
46 _attr_has_entity_name =
True
48 _attr_supported_features = LightEntityFeature.EFFECT
51 self, coordinator: DataUpdateCoordinator[
None], device: LEDBLE, name: str
53 """Initialize an ledble light."""
59 model=f
"{device.model_data.description} {hex(device.model_num)}",
60 sw_version=hex(device.version_num),
61 connections={(dr.CONNECTION_BLUETOOTH, device.address)},
67 """Handle updating _attr values."""
78 await self.
_device_device.async_set_effect(
80 self.
_device_device.speed
or DEFAULT_EFFECT_SPEED,
81 round(brightness / 255 * 100),
85 """Instruct the light to turn on."""
86 brightness = kwargs.get(ATTR_BRIGHTNESS, self.
brightnessbrightness)
87 if effect := kwargs.get(ATTR_EFFECT):
90 if ATTR_RGB_COLOR
in kwargs:
91 rgb = kwargs[ATTR_RGB_COLOR]
92 await self.
_device_device.set_rgb(rgb, brightness)
94 if ATTR_BRIGHTNESS
in kwargs:
95 await self.
_device_device.set_brightness(brightness)
97 if ATTR_WHITE
in kwargs:
98 await self.
_device_device.set_white(kwargs[ATTR_WHITE])
103 """Instruct the light to turn off."""
108 """Handle data update."""
113 """Register callbacks."""
None __init__(self, DataUpdateCoordinator[None] coordinator, LEDBLE device, str name)
None async_added_to_hass(self)
None _async_update_attrs(self)
None async_turn_on(self, **Any kwargs)
None _async_set_effect(self, str effect, int brightness)
None _handle_coordinator_update(self, *Any args)
None async_turn_off(self, **Any kwargs)
int|None brightness(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)