Fix Blebox light scenes (#75106)

* Bug fix for light platform, when async_turn_on recieves multiple keys.

* Changes according to @MartinHjelmare suggestion.

* Moved effect set call in BleBoxLightEntity.async_turn_on method.

* Added tests for effect in light platform. Added ValueError raise if effect not in effect list.

* Removed duplicated line from test as @MartinHjelmare suggested.
pull/75162/head
Michał Huryn 2022-07-14 11:21:01 +02:00 committed by GitHub
parent c9df5888c2
commit 169264db66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 5 deletions

View File

@ -159,15 +159,20 @@ class BleBoxLightEntity(BleBoxEntity, LightEntity):
else:
value = feature.apply_brightness(value, brightness)
try:
await self._feature.async_on(value)
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):

View File

@ -7,6 +7,7 @@ import pytest
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ATTR_RGBW_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
ColorMode,
@ -524,3 +525,48 @@ 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,
)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_EFFECT] == "POLICE"