Add WLED preset service (#42217)

Co-authored-by: djtimca <60706061+djtimca@users.noreply.github.com>
This commit is contained in:
Alex Popoutsisanddjtimca authored and GitHub committed 2020-10-25 12:44:26 +01:00
1 parent dc37368440
commit 64b1ccd8f6
4 files changed
+75

No files matched your search

+44
View File
@@ -23,6 +23,7 @@ from homeassistant.components.wled.const import (
ATTR_SPEED,
DOMAIN,
SERVICE_EFFECT,
SERVICE_PRESET,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@@ -587,3 +588,46 @@ async def test_effect_service_error(
state = hass.states.get("light.wled_rgb_light_segment_0")
assert state.state == STATE_ON
assert "Invalid response from API" in caplog.text
async def test_preset_service(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test the preset service of a WLED light."""
await init_integration(hass, aioclient_mock)
with patch("wled.WLED.preset") as light_mock:
await hass.services.async_call(
DOMAIN,
SERVICE_PRESET,
{
ATTR_ENTITY_ID: "light.wled_rgb_light_segment_0",
ATTR_PRESET: 1,
},
blocking=True,
)
await hass.async_block_till_done()
light_mock.assert_called_once_with(
preset=1,
)
async def test_preset_service_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, caplog
) -> None:
"""Test error handling of the WLED preset service."""
aioclient_mock.post("http://192.168.1.123:80/json/state", text="", status=400)
await init_integration(hass, aioclient_mock)
with patch("homeassistant.components.wled.WLED.update"):
await hass.services.async_call(
DOMAIN,
SERVICE_PRESET,
{ATTR_ENTITY_ID: "light.wled_rgb_light_segment_0", ATTR_PRESET: 1},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get("light.wled_rgb_light_segment_0")
assert state.state == STATE_ON
assert "Invalid response from API" in caplog.text