1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Fix issue parsing color effect None in flux_led (#57979)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Brian Egge 2021-10-19 02:36:25 -04:00 committed by GitHub
parent 9a26a8cfd8
commit 708f2ae089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 9 deletions

View File

@ -214,6 +214,9 @@ async def async_setup_platform(
host,
)
custom_effects = device_config.get(CONF_CUSTOM_EFFECT, {})
custom_effect_colors = None
if CONF_COLORS in custom_effects:
custom_effect_colors = str(custom_effects[CONF_COLORS])
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
@ -224,7 +227,7 @@ async def async_setup_platform(
CONF_NAME: device_config[CONF_NAME],
CONF_PROTOCOL: device_config.get(CONF_PROTOCOL),
CONF_MODE: device_config.get(ATTR_MODE, MODE_AUTO),
CONF_CUSTOM_EFFECT_COLORS: str(custom_effects.get(CONF_COLORS)),
CONF_CUSTOM_EFFECT_COLORS: custom_effect_colors,
CONF_CUSTOM_EFFECT_SPEED_PCT: custom_effects.get(
CONF_SPEED_PCT, DEFAULT_EFFECT_SPEED
),

View File

@ -741,18 +741,23 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
assert attributes[ATTR_EFFECT] == "custom"
async def test_rgb_light_custom_effects_invalid_colors(hass: HomeAssistant) -> None:
@pytest.mark.parametrize("effect_colors", [":: CANNOT BE PARSED ::", None])
async def test_rgb_light_custom_effects_invalid_colors(
hass: HomeAssistant, effect_colors: str
) -> None:
"""Test an rgb light with a invalid effect."""
options = {
CONF_MODE: MODE_AUTO,
CONF_CUSTOM_EFFECT_SPEED_PCT: 88,
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_JUMP,
}
if effect_colors:
options[CONF_CUSTOM_EFFECT_COLORS] = effect_colors
config_entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
options=options,
unique_id=MAC_ADDRESS,
options={
CONF_MODE: MODE_AUTO,
CONF_CUSTOM_EFFECT_COLORS: ":: CANNOT BE PARSED ::",
CONF_CUSTOM_EFFECT_SPEED_PCT: 88,
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_JUMP,
},
)
config_entry.add_to_hass(hass)
bulb = _mocked_bulb()
@ -827,7 +832,7 @@ async def test_rgb_light_custom_effect_via_service(
bulb.async_set_custom_pattern.reset_mock()
async def test_migrate_from_yaml(hass: HomeAssistant) -> None:
async def test_migrate_from_yaml_with_custom_effect(hass: HomeAssistant) -> None:
"""Test migrate from yaml."""
config = {
LIGHT_DOMAIN: [
@ -876,6 +881,50 @@ async def test_migrate_from_yaml(hass: HomeAssistant) -> None:
}
async def test_migrate_from_yaml_no_custom_effect(hass: HomeAssistant) -> None:
"""Test migrate from yaml."""
config = {
LIGHT_DOMAIN: [
{
CONF_PLATFORM: DOMAIN,
CONF_DEVICES: {
IP_ADDRESS: {
CONF_NAME: "flux_lamppost",
CONF_PROTOCOL: "ledenet",
}
},
}
],
}
with _patch_discovery(), _patch_wifibulb():
await async_setup_component(hass, LIGHT_DOMAIN, config)
await hass.async_block_till_done()
await hass.async_block_till_done()
await hass.async_block_till_done()
entries = hass.config_entries.async_entries(DOMAIN)
assert entries
migrated_entry = None
for entry in entries:
if entry.unique_id == MAC_ADDRESS:
migrated_entry = entry
break
assert migrated_entry is not None
assert migrated_entry.data == {
CONF_HOST: IP_ADDRESS,
CONF_NAME: "flux_lamppost",
CONF_PROTOCOL: "ledenet",
}
assert migrated_entry.options == {
CONF_MODE: "auto",
CONF_CUSTOM_EFFECT_COLORS: None,
CONF_CUSTOM_EFFECT_SPEED_PCT: 50,
CONF_CUSTOM_EFFECT_TRANSITION: "gradual",
}
async def test_addressable_light(hass: HomeAssistant) -> None:
"""Test an addressable light."""
config_entry = MockConfigEntry(