mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add effects support to led-ble (#82224)
This commit is contained in:
parent
e37211ad42
commit
9d8dfc2d71
@ -1,5 +1,7 @@
|
|||||||
"""Constants for the LED BLE integration."""
|
"""Constants for the LED BLE integration."""
|
||||||
|
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
DOMAIN = "led_ble"
|
DOMAIN = "led_ble"
|
||||||
|
|
||||||
DEVICE_TIMEOUT = 30
|
DEVICE_TIMEOUT = 30
|
||||||
@ -8,3 +10,5 @@ LOCAL_NAMES = {"LEDnet", "BLE-LED", "LEDBLE", "Triones", "LEDBlue"}
|
|||||||
UNSUPPORTED_SUB_MODEL = "LEDnetWF"
|
UNSUPPORTED_SUB_MODEL = "LEDnetWF"
|
||||||
|
|
||||||
UPDATE_SECONDS = 15
|
UPDATE_SECONDS = 15
|
||||||
|
|
||||||
|
DEFAULT_EFFECT_SPEED: Final = 50
|
||||||
|
@ -7,10 +7,12 @@ from led_ble import LEDBLE
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
ATTR_EFFECT,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_WHITE,
|
ATTR_WHITE,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -22,7 +24,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DEFAULT_EFFECT_SPEED, DOMAIN
|
||||||
from .models import LEDBLEData
|
from .models import LEDBLEData
|
||||||
|
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ class LEDBLEEntity(CoordinatorEntity, LightEntity):
|
|||||||
|
|
||||||
_attr_supported_color_modes = {ColorMode.RGB, ColorMode.WHITE}
|
_attr_supported_color_modes = {ColorMode.RGB, ColorMode.WHITE}
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
_attr_supported_features = LightEntityFeature.EFFECT
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, coordinator: DataUpdateCoordinator, device: LEDBLE, name: str
|
self, coordinator: DataUpdateCoordinator, device: LEDBLE, name: str
|
||||||
@ -51,7 +54,7 @@ class LEDBLEEntity(CoordinatorEntity, LightEntity):
|
|||||||
self._attr_unique_id = device.address
|
self._attr_unique_id = device.address
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
name=name,
|
name=name,
|
||||||
model=hex(device.model_num),
|
model=f"{device.model_data.description} {hex(device.model_num)}",
|
||||||
sw_version=hex(device.version_num),
|
sw_version=hex(device.version_num),
|
||||||
connections={(dr.CONNECTION_BLUETOOTH, device.address)},
|
connections={(dr.CONNECTION_BLUETOOTH, device.address)},
|
||||||
)
|
)
|
||||||
@ -65,10 +68,23 @@ class LEDBLEEntity(CoordinatorEntity, LightEntity):
|
|||||||
self._attr_brightness = device.brightness
|
self._attr_brightness = device.brightness
|
||||||
self._attr_rgb_color = device.rgb_unscaled
|
self._attr_rgb_color = device.rgb_unscaled
|
||||||
self._attr_is_on = device.on
|
self._attr_is_on = device.on
|
||||||
|
self._attr_effect = device.effect
|
||||||
|
self._attr_effect_list = device.effect_list
|
||||||
|
|
||||||
|
async def _async_set_effect(self, effect: str, brightness: int) -> None:
|
||||||
|
"""Set an effect."""
|
||||||
|
await self._device.async_set_effect(
|
||||||
|
effect,
|
||||||
|
self._device.speed or DEFAULT_EFFECT_SPEED,
|
||||||
|
round(brightness / 255 * 100),
|
||||||
|
)
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness)
|
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness)
|
||||||
|
if effect := kwargs.get(ATTR_EFFECT):
|
||||||
|
await self._async_set_effect(effect, brightness)
|
||||||
|
return
|
||||||
if ATTR_RGB_COLOR in kwargs:
|
if ATTR_RGB_COLOR in kwargs:
|
||||||
rgb = kwargs[ATTR_RGB_COLOR]
|
rgb = kwargs[ATTR_RGB_COLOR]
|
||||||
await self._device.set_rgb(rgb, brightness)
|
await self._device.set_rgb(rgb, brightness)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "LED BLE",
|
"name": "LED BLE",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/led_ble/",
|
"documentation": "https://www.home-assistant.io/integrations/led_ble/",
|
||||||
"requirements": ["bluetooth-data-tools==0.2.0", "led-ble==1.0.0"],
|
"requirements": ["bluetooth-data-tools==0.3.0", "led-ble==1.0.0"],
|
||||||
"dependencies": ["bluetooth"],
|
"dependencies": ["bluetooth"],
|
||||||
"codeowners": ["@bdraco"],
|
"codeowners": ["@bdraco"],
|
||||||
"bluetooth": [
|
"bluetooth": [
|
||||||
|
@ -452,10 +452,8 @@ bluetooth-adapters==0.7.0
|
|||||||
# homeassistant.components.bluetooth
|
# homeassistant.components.bluetooth
|
||||||
bluetooth-auto-recovery==0.4.0
|
bluetooth-auto-recovery==0.4.0
|
||||||
|
|
||||||
# homeassistant.components.led_ble
|
|
||||||
bluetooth-data-tools==0.2.0
|
|
||||||
|
|
||||||
# homeassistant.components.bluetooth
|
# homeassistant.components.bluetooth
|
||||||
|
# homeassistant.components.led_ble
|
||||||
bluetooth-data-tools==0.3.0
|
bluetooth-data-tools==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.bond
|
# homeassistant.components.bond
|
||||||
|
@ -366,10 +366,8 @@ bluetooth-adapters==0.7.0
|
|||||||
# homeassistant.components.bluetooth
|
# homeassistant.components.bluetooth
|
||||||
bluetooth-auto-recovery==0.4.0
|
bluetooth-auto-recovery==0.4.0
|
||||||
|
|
||||||
# homeassistant.components.led_ble
|
|
||||||
bluetooth-data-tools==0.2.0
|
|
||||||
|
|
||||||
# homeassistant.components.bluetooth
|
# homeassistant.components.bluetooth
|
||||||
|
# homeassistant.components.led_ble
|
||||||
bluetooth-data-tools==0.3.0
|
bluetooth-data-tools==0.3.0
|
||||||
|
|
||||||
# homeassistant.components.bond
|
# homeassistant.components.bond
|
||||||
|
Loading…
x
Reference in New Issue
Block a user