mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Remove custom WLED services (#60537)
This commit is contained in:
parent
09af85c6a4
commit
3aa35e15c2
@ -19,18 +19,11 @@ ATTR_DURATION = "duration"
|
||||
ATTR_FADE = "fade"
|
||||
ATTR_INTENSITY = "intensity"
|
||||
ATTR_ON = "on"
|
||||
ATTR_PALETTE = "palette"
|
||||
ATTR_PRESET = "preset"
|
||||
ATTR_REVERSE = "reverse"
|
||||
ATTR_SEGMENT_ID = "segment_id"
|
||||
ATTR_SOFTWARE_VERSION = "sw_version"
|
||||
ATTR_SPEED = "speed"
|
||||
ATTR_TARGET_BRIGHTNESS = "target_brightness"
|
||||
ATTR_UDP_PORT = "udp_port"
|
||||
|
||||
# Services
|
||||
SERVICE_EFFECT = "effect"
|
||||
SERVICE_PRESET = "preset"
|
||||
|
||||
# Device classes
|
||||
DEVICE_CLASS_WLED_LIVE_OVERRIDE: Final = "wled__live_override"
|
||||
|
@ -4,8 +4,6 @@ from __future__ import annotations
|
||||
from functools import partial
|
||||
from typing import Any, Tuple, cast
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_EFFECT,
|
||||
@ -21,23 +19,9 @@ from homeassistant.components.light import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
ATTR_COLOR_PRIMARY,
|
||||
ATTR_INTENSITY,
|
||||
ATTR_ON,
|
||||
ATTR_PALETTE,
|
||||
ATTR_PRESET,
|
||||
ATTR_REVERSE,
|
||||
ATTR_SEGMENT_ID,
|
||||
ATTR_SPEED,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
SERVICE_EFFECT,
|
||||
SERVICE_PRESET,
|
||||
)
|
||||
from .const import ATTR_COLOR_PRIMARY, ATTR_ON, ATTR_SEGMENT_ID, DOMAIN
|
||||
from .coordinator import WLEDDataUpdateCoordinator
|
||||
from .helpers import wled_exception_handler
|
||||
from .models import WLEDEntity
|
||||
@ -52,35 +36,6 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up WLED light based on a config entry."""
|
||||
coordinator: WLEDDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
vol.Optional(ATTR_EFFECT): vol.Any(cv.positive_int, cv.string),
|
||||
vol.Optional(ATTR_INTENSITY): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=0, max=255)
|
||||
),
|
||||
vol.Optional(ATTR_PALETTE): vol.Any(cv.positive_int, cv.string),
|
||||
vol.Optional(ATTR_REVERSE): cv.boolean,
|
||||
vol.Optional(ATTR_SPEED): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=0, max=255)
|
||||
),
|
||||
},
|
||||
"async_effect",
|
||||
)
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_PRESET,
|
||||
{
|
||||
vol.Required(ATTR_PRESET): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=-1, max=65535)
|
||||
),
|
||||
},
|
||||
"async_preset",
|
||||
)
|
||||
|
||||
if coordinator.keep_master_light:
|
||||
async_add_entities([WLEDMasterLight(coordinator=coordinator)])
|
||||
|
||||
@ -146,32 +101,6 @@ class WLEDMasterLight(WLEDEntity, LightEntity):
|
||||
on=True, brightness=kwargs.get(ATTR_BRIGHTNESS), transition=transition
|
||||
)
|
||||
|
||||
async def async_effect(
|
||||
self,
|
||||
effect: int | str | None = None,
|
||||
intensity: int | None = None,
|
||||
palette: int | str | None = None,
|
||||
reverse: bool | None = None,
|
||||
speed: int | None = None,
|
||||
) -> None:
|
||||
"""Set the effect of a WLED light."""
|
||||
# Master light does not have an effect setting.
|
||||
|
||||
@wled_exception_handler
|
||||
async def async_preset(
|
||||
self,
|
||||
preset: int,
|
||||
) -> None:
|
||||
"""Set a WLED light to a saved preset."""
|
||||
# The WLED preset service is replaced by a preset select entity
|
||||
# and marked deprecated as of Home Assistant 2021.8
|
||||
LOGGER.warning(
|
||||
"The 'wled.preset' service is deprecated and replaced by a "
|
||||
"dedicated preset select entity; Please use that entity to "
|
||||
"change presets instead"
|
||||
)
|
||||
await self.coordinator.wled.preset(preset=preset)
|
||||
|
||||
|
||||
class WLEDSegmentLight(WLEDEntity, LightEntity):
|
||||
"""Defines a WLED light based on a segment."""
|
||||
@ -323,33 +252,6 @@ class WLEDSegmentLight(WLEDEntity, LightEntity):
|
||||
|
||||
await self.coordinator.wled.segment(**data)
|
||||
|
||||
@wled_exception_handler
|
||||
async def async_effect(
|
||||
self,
|
||||
effect: int | str | None = None,
|
||||
intensity: int | None = None,
|
||||
palette: int | str | None = None,
|
||||
reverse: bool | None = None,
|
||||
speed: int | None = None,
|
||||
) -> None:
|
||||
"""Set the effect of a WLED light."""
|
||||
await self.coordinator.wled.segment(
|
||||
segment_id=self._segment,
|
||||
effect=effect,
|
||||
intensity=intensity,
|
||||
palette=palette,
|
||||
reverse=reverse,
|
||||
speed=speed,
|
||||
)
|
||||
|
||||
@wled_exception_handler
|
||||
async def async_preset(
|
||||
self,
|
||||
preset: int,
|
||||
) -> None:
|
||||
"""Set a WLED light to a saved preset."""
|
||||
await self.coordinator.wled.preset(preset=preset)
|
||||
|
||||
|
||||
@callback
|
||||
def async_update_segments(
|
||||
|
@ -14,18 +14,7 @@ from homeassistant.components.light import (
|
||||
ATTR_TRANSITION,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.wled.const import (
|
||||
ATTR_INTENSITY,
|
||||
ATTR_PALETTE,
|
||||
ATTR_PRESET,
|
||||
ATTR_REVERSE,
|
||||
ATTR_SPEED,
|
||||
CONF_KEEP_MASTER_LIGHT,
|
||||
DOMAIN,
|
||||
SCAN_INTERVAL,
|
||||
SERVICE_EFFECT,
|
||||
SERVICE_PRESET,
|
||||
)
|
||||
from homeassistant.components.wled.const import CONF_KEEP_MASTER_LIGHT, SCAN_INTERVAL
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_ICON,
|
||||
@ -390,229 +379,6 @@ async def test_rgbw_light(
|
||||
)
|
||||
|
||||
|
||||
async def test_effect_service(
|
||||
hass: HomeAssistant, init_integration: MockConfigEntry, mock_wled: MagicMock
|
||||
) -> None:
|
||||
"""Test the effect service of a WLED light."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
ATTR_EFFECT: "Rainbow",
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_INTENSITY: 200,
|
||||
ATTR_PALETTE: "Tiamat",
|
||||
ATTR_REVERSE: True,
|
||||
ATTR_SPEED: 100,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(
|
||||
effect="Rainbow",
|
||||
intensity=200,
|
||||
palette="Tiamat",
|
||||
reverse=True,
|
||||
segment_id=0,
|
||||
speed=100,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{ATTR_ENTITY_ID: "light.wled_rgb_light", ATTR_EFFECT: 9},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 2
|
||||
mock_wled.segment.assert_called_with(
|
||||
segment_id=0,
|
||||
effect=9,
|
||||
intensity=None,
|
||||
palette=None,
|
||||
reverse=None,
|
||||
speed=None,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_INTENSITY: 200,
|
||||
ATTR_REVERSE: True,
|
||||
ATTR_SPEED: 100,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 3
|
||||
mock_wled.segment.assert_called_with(
|
||||
intensity=200,
|
||||
reverse=True,
|
||||
segment_id=0,
|
||||
speed=100,
|
||||
effect=None,
|
||||
palette=None,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
ATTR_EFFECT: "Rainbow",
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_PALETTE: "Tiamat",
|
||||
ATTR_REVERSE: True,
|
||||
ATTR_SPEED: 100,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 4
|
||||
mock_wled.segment.assert_called_with(
|
||||
effect="Rainbow",
|
||||
palette="Tiamat",
|
||||
reverse=True,
|
||||
segment_id=0,
|
||||
speed=100,
|
||||
intensity=None,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
ATTR_EFFECT: "Rainbow",
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_INTENSITY: 200,
|
||||
ATTR_SPEED: 100,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 5
|
||||
mock_wled.segment.assert_called_with(
|
||||
effect="Rainbow",
|
||||
intensity=200,
|
||||
segment_id=0,
|
||||
speed=100,
|
||||
palette=None,
|
||||
reverse=None,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{
|
||||
ATTR_EFFECT: "Rainbow",
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_INTENSITY: 200,
|
||||
ATTR_REVERSE: True,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.segment.call_count == 6
|
||||
mock_wled.segment.assert_called_with(
|
||||
effect="Rainbow",
|
||||
intensity=200,
|
||||
reverse=True,
|
||||
segment_id=0,
|
||||
palette=None,
|
||||
speed=None,
|
||||
)
|
||||
|
||||
|
||||
async def test_effect_service_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED effect service."""
|
||||
mock_wled.segment.side_effect = WLEDError
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_EFFECT,
|
||||
{ATTR_ENTITY_ID: "light.wled_rgb_light", ATTR_EFFECT: 9},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.wled_rgb_light")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.segment.call_count == 1
|
||||
mock_wled.segment.assert_called_with(
|
||||
effect=9, segment_id=0, intensity=None, palette=None, reverse=None, speed=None
|
||||
)
|
||||
|
||||
|
||||
async def test_preset_service(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the preset service of a WLED light."""
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PRESET,
|
||||
{
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light",
|
||||
ATTR_PRESET: 1,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.preset.call_count == 1
|
||||
mock_wled.preset.assert_called_with(preset=1)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PRESET,
|
||||
{
|
||||
ATTR_ENTITY_ID: "light.wled_rgb_light_master",
|
||||
ATTR_PRESET: 2,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_wled.preset.call_count == 2
|
||||
mock_wled.preset.assert_called_with(preset=2)
|
||||
|
||||
assert "The 'wled.preset' service is deprecated" in caplog.text
|
||||
|
||||
|
||||
async def test_preset_service_error(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
mock_wled: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test error handling of the WLED preset service."""
|
||||
mock_wled.preset.side_effect = WLEDError
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PRESET,
|
||||
{ATTR_ENTITY_ID: "light.wled_rgb_light", ATTR_PRESET: 1},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.wled_rgb_light")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
assert "Invalid response from API" in caplog.text
|
||||
assert mock_wled.preset.call_count == 1
|
||||
mock_wled.preset.assert_called_with(preset=1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_wled", ["wled/rgb_single_segment.json"], indirect=True)
|
||||
async def test_single_segment_with_keep_master_light(
|
||||
hass: HomeAssistant,
|
||||
|
Loading…
x
Reference in New Issue
Block a user