Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Blebox light scenes #75106

Merged
merged 5 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions homeassistant/components/blebox/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,20 @@ async def async_turn_on(self, **kwargs):
else:
value = feature.apply_brightness(value, brightness)

try:
await self._feature.async_on(value)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
except ValueError as exc:
raise ValueError(
f"Turning on '{self.name}' failed: Bad value {value}"
) from exc

if effect is not None:
effect_value = self.effect_list.index(effect)
await self._feature.async_api_command("effect", effect_value)
else:
try:
await self._feature.async_on(value)
effect_value = self.effect_list.index(effect)
await self._feature.async_api_command("effect", effect_value)
except ValueError as exc:
raise ValueError(
f"Turning on '{self.name}' failed: Bad value {value}"
f"Turning on with effect '{self.name}' failed: {effect} not in effect list."
) from exc

async def async_turn_off(self, **kwargs):
Expand Down
48 changes: 48 additions & 0 deletions tests/components/blebox/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ATTR_RGBW_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
ColorMode,
Expand Down Expand Up @@ -524,3 +525,50 @@ async def test_turn_on_failure(feature, hass, config, caplog):
assert f"Turning on '{feature_mock.full_name}' failed: Bad value 123" in str(
info.value
)


async def test_wlightbox_on_effect(wlightbox, hass, config):
"""Test light on."""

feature_mock, entity_id = wlightbox

def initial_update():
feature_mock.is_on = False

feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()

state = hass.states.get(entity_id)
assert state.state == STATE_OFF

def turn_on(value):
feature_mock.is_on = True
feature_mock.effect = "POLICE"

feature_mock.async_on = AsyncMock(side_effect=turn_on)

with pytest.raises(ValueError) as info:
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_EFFECT: "NOT IN LIST"},
blocking=True,
)

assert (
f"Turning on with effect '{feature_mock.full_name}' failed: NOT IN LIST not in effect list."
in str(info.value)
)

await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_EFFECT: "POLICE"},
blocking=True,
)

feature_mock.async_on = AsyncMock(side_effect=turn_on)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

state = hass.states.get(entity_id)
assert state.attributes[ATTR_EFFECT] == "POLICE"