Remove deprecated yaml config from flux_led (#61844)
Co-authored-by: J. Nick Koston <nick@koston.org>pull/61072/head
parent
443003795b
commit
1baba2a807
|
@ -10,8 +10,8 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import FluxLedUpdateCoordinator
|
||||
from .const import DOMAIN
|
||||
from .coordinator import FluxLedUpdateCoordinator
|
||||
from .entity import FluxBaseEntity
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Config flow for Flux LED/MagicLight."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, Final, cast
|
||||
|
||||
from flux_led.const import ATTR_ID, ATTR_IPADDR, ATTR_MODEL, ATTR_MODEL_DESCRIPTION
|
||||
|
@ -10,7 +9,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_PROTOCOL
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
@ -40,9 +39,6 @@ from .discovery import (
|
|||
CONF_DEVICE: Final = "device"
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Magic Home Integration."""
|
||||
|
||||
|
@ -59,30 +55,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Get the options flow for the Flux LED component."""
|
||||
return OptionsFlow(config_entry)
|
||||
|
||||
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
|
||||
"""Handle configuration via YAML import."""
|
||||
_LOGGER.debug("Importing configuration from YAML for flux_led")
|
||||
host = user_input[CONF_HOST]
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
if mac := user_input[CONF_MAC]:
|
||||
await self.async_set_unique_id(dr.format_mac(mac), raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: host})
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_NAME],
|
||||
data={
|
||||
CONF_HOST: host,
|
||||
CONF_NAME: user_input[CONF_NAME],
|
||||
CONF_PROTOCOL: user_input.get(CONF_PROTOCOL),
|
||||
},
|
||||
options={
|
||||
CONF_CUSTOM_EFFECT_COLORS: user_input[CONF_CUSTOM_EFFECT_COLORS],
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: user_input[CONF_CUSTOM_EFFECT_SPEED_PCT],
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: user_input[
|
||||
CONF_CUSTOM_EFFECT_TRANSITION
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
|
||||
"""Handle discovery via dhcp."""
|
||||
self._discovered_device = FluxLEDDiscovery(
|
||||
|
|
|
@ -33,7 +33,6 @@ API: Final = "flux_api"
|
|||
|
||||
SIGNAL_STATE_UPDATED = "flux_led_{}_state_updated"
|
||||
|
||||
CONF_AUTOMATIC_ADD: Final = "automatic_add"
|
||||
DEFAULT_NETWORK_SCAN_INTERVAL: Final = 120
|
||||
DEFAULT_SCAN_INTERVAL: Final = 5
|
||||
DEFAULT_EFFECT_SPEED: Final = 50
|
||||
|
@ -50,22 +49,12 @@ FLUX_LED_EXCEPTIONS: Final = (
|
|||
STARTUP_SCAN_TIMEOUT: Final = 5
|
||||
DISCOVER_SCAN_TIMEOUT: Final = 10
|
||||
|
||||
CONF_DEVICES: Final = "devices"
|
||||
CONF_CUSTOM_EFFECT: Final = "custom_effect"
|
||||
CONF_MODEL: Final = "model"
|
||||
CONF_MINOR_VERSION: Final = "minor_version"
|
||||
CONF_REMOTE_ACCESS_ENABLED: Final = "remote_access_enabled"
|
||||
CONF_REMOTE_ACCESS_HOST: Final = "remote_access_host"
|
||||
CONF_REMOTE_ACCESS_PORT: Final = "remote_access_port"
|
||||
|
||||
MODE_AUTO: Final = "auto"
|
||||
MODE_RGB: Final = "rgb"
|
||||
MODE_RGBW: Final = "rgbw"
|
||||
|
||||
# This mode enables white value to be controlled by brightness.
|
||||
# RGB value is ignored when this mode is specified.
|
||||
MODE_WHITE: Final = "w"
|
||||
|
||||
TRANSITION_GRADUAL: Final = "gradual"
|
||||
TRANSITION_JUMP: Final = "jump"
|
||||
TRANSITION_STROBE: Final = "strobe"
|
||||
|
|
|
@ -5,7 +5,6 @@ import ast
|
|||
import logging
|
||||
from typing import Any, Final
|
||||
|
||||
from flux_led.const import ATTR_ID, ATTR_IPADDR
|
||||
from flux_led.utils import (
|
||||
color_temp_to_white_levels,
|
||||
rgbcw_brightness,
|
||||
|
@ -24,24 +23,15 @@ from homeassistant.components.light import (
|
|||
ATTR_RGBWW_COLOR,
|
||||
ATTR_WHITE,
|
||||
COLOR_MODE_RGBWW,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_EFFECT,
|
||||
SUPPORT_TRANSITION,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_MODE,
|
||||
CONF_DEVICES,
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
CONF_NAME,
|
||||
CONF_PROTOCOL,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.color import (
|
||||
color_temperature_kelvin_to_mired,
|
||||
|
@ -49,9 +39,7 @@ from homeassistant.util.color import (
|
|||
)
|
||||
|
||||
from .const import (
|
||||
CONF_AUTOMATIC_ADD,
|
||||
CONF_COLORS,
|
||||
CONF_CUSTOM_EFFECT,
|
||||
CONF_CUSTOM_EFFECT_COLORS,
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION,
|
||||
|
@ -59,11 +47,6 @@ from .const import (
|
|||
CONF_TRANSITION,
|
||||
DEFAULT_EFFECT_SPEED,
|
||||
DOMAIN,
|
||||
FLUX_LED_DISCOVERY,
|
||||
MODE_AUTO,
|
||||
MODE_RGB,
|
||||
MODE_RGBW,
|
||||
MODE_WHITE,
|
||||
TRANSITION_GRADUAL,
|
||||
TRANSITION_JUMP,
|
||||
TRANSITION_STROBE,
|
||||
|
@ -105,70 +88,6 @@ CUSTOM_EFFECT_DICT: Final = {
|
|||
),
|
||||
}
|
||||
|
||||
CUSTOM_EFFECT_SCHEMA: Final = vol.Schema(CUSTOM_EFFECT_DICT)
|
||||
|
||||
DEVICE_SCHEMA: Final = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(ATTR_MODE, default=MODE_AUTO): vol.All(
|
||||
cv.string, vol.In([MODE_AUTO, MODE_RGBW, MODE_RGB, MODE_WHITE])
|
||||
),
|
||||
vol.Optional(CONF_PROTOCOL): vol.All(cv.string, vol.In(["ledenet"])),
|
||||
vol.Optional(CONF_CUSTOM_EFFECT): CUSTOM_EFFECT_SCHEMA,
|
||||
}
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_DEVICES, default={}): {cv.string: DEVICE_SCHEMA},
|
||||
vol.Optional(CONF_AUTOMATIC_ADD, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> bool:
|
||||
"""Set up the flux led platform."""
|
||||
domain_data = hass.data[DOMAIN]
|
||||
discovered_mac_by_host = {
|
||||
device[ATTR_IPADDR]: device[ATTR_ID]
|
||||
for device in domain_data[FLUX_LED_DISCOVERY]
|
||||
}
|
||||
for host, device_config in config.get(CONF_DEVICES, {}).items():
|
||||
_LOGGER.warning(
|
||||
"Configuring flux_led via yaml is deprecated; the configuration for"
|
||||
" %s has been migrated to a config entry and can be safely removed",
|
||||
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,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_HOST: host,
|
||||
CONF_MAC: discovered_mac_by_host.get(host),
|
||||
CONF_NAME: device_config[CONF_NAME],
|
||||
CONF_PROTOCOL: device_config.get(CONF_PROTOCOL),
|
||||
CONF_CUSTOM_EFFECT_COLORS: custom_effect_colors,
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: custom_effects.get(
|
||||
CONF_SPEED_PCT, DEFAULT_EFFECT_SPEED
|
||||
),
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: custom_effects.get(
|
||||
CONF_TRANSITION, TRANSITION_GRADUAL
|
||||
),
|
||||
},
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -17,17 +17,10 @@ from homeassistant.components.flux_led.const import (
|
|||
CONF_REMOTE_ACCESS_HOST,
|
||||
CONF_REMOTE_ACCESS_PORT,
|
||||
DOMAIN,
|
||||
MODE_RGB,
|
||||
TRANSITION_JUMP,
|
||||
TRANSITION_STROBE,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE,
|
||||
CONF_HOST,
|
||||
CONF_MAC,
|
||||
CONF_NAME,
|
||||
CONF_PROTOCOL,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_FORM
|
||||
|
||||
|
@ -217,56 +210,6 @@ async def test_discovery_no_device(hass: HomeAssistant):
|
|||
assert result2["reason"] == "no_devices_found"
|
||||
|
||||
|
||||
async def test_import(hass: HomeAssistant):
|
||||
"""Test import from yaml."""
|
||||
config = {
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_MAC: MAC_ADDRESS,
|
||||
CONF_NAME: "floor lamp",
|
||||
CONF_PROTOCOL: "ledenet",
|
||||
CONF_MODEL: MODE_RGB,
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[255,0,0], [0,0,255]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 30,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_STROBE,
|
||||
}
|
||||
|
||||
# Success
|
||||
with _patch_discovery(), _patch_wifibulb(), patch(
|
||||
f"{MODULE}.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
f"{MODULE}.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "floor lamp"
|
||||
assert result["data"] == {
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: "floor lamp",
|
||||
CONF_PROTOCOL: "ledenet",
|
||||
}
|
||||
assert result["options"] == {
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[255,0,0], [0,0,255]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 30,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_STROBE,
|
||||
}
|
||||
mock_setup.assert_called_once()
|
||||
mock_setup_entry.assert_called_once()
|
||||
|
||||
# Duplicate
|
||||
with _patch_discovery(), _patch_wifibulb():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_manual_working_discovery(hass: HomeAssistant):
|
||||
"""Test manually setup."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -584,7 +527,6 @@ async def test_options(hass: HomeAssistant):
|
|||
domain=DOMAIN,
|
||||
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
|
||||
options={
|
||||
CONF_MODEL: MODE_RGB,
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[255,0,0], [0,0,255]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 30,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_STROBE,
|
||||
|
|
|
@ -101,7 +101,7 @@ async def test_config_entry_retry(hass: HomeAssistant) -> None:
|
|||
"discovery,title",
|
||||
[
|
||||
(FLUX_DISCOVERY, DEFAULT_ENTRY_TITLE),
|
||||
(FLUX_DISCOVERY_PARTIAL, "AZ120444 ddeeff"),
|
||||
(FLUX_DISCOVERY_PARTIAL, DEFAULT_ENTRY_TITLE),
|
||||
],
|
||||
)
|
||||
async def test_config_entry_fills_unique_id_with_directed_discovery(
|
||||
|
@ -112,17 +112,24 @@ async def test_config_entry_fills_unique_id_with_directed_discovery(
|
|||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=None
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
last_address = None
|
||||
|
||||
async def _discovery(self, *args, address=None, **kwargs):
|
||||
# Only return discovery results when doing directed discovery
|
||||
return [discovery] if address == IP_ADDRESS else []
|
||||
nonlocal last_address
|
||||
last_address = address
|
||||
return [FLUX_DISCOVERY] if address == IP_ADDRESS else []
|
||||
|
||||
def _mock_getBulbInfo(*args, **kwargs):
|
||||
nonlocal last_address
|
||||
return [FLUX_DISCOVERY] if last_address == IP_ADDRESS else []
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.async_scan",
|
||||
new=_discovery,
|
||||
), patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.getBulbInfo",
|
||||
return_value=[discovery],
|
||||
new=_mock_getBulbInfo,
|
||||
), _patch_wifibulb():
|
||||
await async_setup_component(hass, flux_led.DOMAIN, {flux_led.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Tests for light platform."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from flux_led.const import (
|
||||
COLOR_MODE_ADDRESSABLE as FLUX_COLOR_MODE_ADDRESSABLE,
|
||||
|
@ -16,20 +16,12 @@ import pytest
|
|||
from homeassistant.components import flux_led
|
||||
from homeassistant.components.flux_led.const import (
|
||||
CONF_COLORS,
|
||||
CONF_CUSTOM_EFFECT,
|
||||
CONF_CUSTOM_EFFECT_COLORS,
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION,
|
||||
CONF_DEVICES,
|
||||
CONF_MINOR_VERSION,
|
||||
CONF_MODEL,
|
||||
CONF_REMOTE_ACCESS_ENABLED,
|
||||
CONF_REMOTE_ACCESS_HOST,
|
||||
CONF_REMOTE_ACCESS_PORT,
|
||||
CONF_SPEED_PCT,
|
||||
CONF_TRANSITION,
|
||||
DOMAIN,
|
||||
MODE_AUTO,
|
||||
TRANSITION_JUMP,
|
||||
)
|
||||
from homeassistant.components.light import (
|
||||
|
@ -51,8 +43,6 @@ from homeassistant.const import (
|
|||
CONF_HOST,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_PLATFORM,
|
||||
CONF_PROTOCOL,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
|
@ -64,10 +54,8 @@ from homeassistant.util.dt import utcnow
|
|||
|
||||
from . import (
|
||||
DEFAULT_ENTRY_TITLE,
|
||||
FLUX_DISCOVERY,
|
||||
IP_ADDRESS,
|
||||
MAC_ADDRESS,
|
||||
MODEL,
|
||||
_mocked_bulb,
|
||||
_patch_discovery,
|
||||
_patch_wifibulb,
|
||||
|
@ -971,7 +959,7 @@ async def test_rgb_light_custom_effects(hass: HomeAssistant) -> None:
|
|||
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
|
||||
unique_id=MAC_ADDRESS,
|
||||
options={
|
||||
CONF_MODE: MODE_AUTO,
|
||||
CONF_MODE: "auto",
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[0,0,255], [255,0,0]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 88,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_JUMP,
|
||||
|
@ -1047,7 +1035,7 @@ async def test_rgb_light_custom_effects_invalid_colors(
|
|||
) -> None:
|
||||
"""Test an rgb light with a invalid effect."""
|
||||
options = {
|
||||
CONF_MODE: MODE_AUTO,
|
||||
CONF_MODE: "auto",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 88,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: TRANSITION_JUMP,
|
||||
}
|
||||
|
@ -1132,145 +1120,6 @@ async def test_rgb_light_custom_effect_via_service(
|
|||
bulb.async_set_custom_pattern.reset_mock()
|
||||
|
||||
|
||||
async def test_migrate_from_yaml_with_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",
|
||||
CONF_CUSTOM_EFFECT: {
|
||||
CONF_SPEED_PCT: 30,
|
||||
CONF_TRANSITION: "strobe",
|
||||
CONF_COLORS: [[255, 0, 0], [255, 255, 0], [0, 255, 0]],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
last_address = None
|
||||
|
||||
async def _discovery(self, *args, address=None, **kwargs):
|
||||
# Only return discovery results when doing directed discovery
|
||||
nonlocal last_address
|
||||
last_address = address
|
||||
return [FLUX_DISCOVERY] if address == IP_ADDRESS else []
|
||||
|
||||
def _mock_getBulbInfo(*args, **kwargs):
|
||||
nonlocal last_address
|
||||
return [FLUX_DISCOVERY] if last_address == IP_ADDRESS else []
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.async_scan",
|
||||
new=_discovery,
|
||||
), patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.getBulbInfo",
|
||||
new=_mock_getBulbInfo,
|
||||
), _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",
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_REMOTE_ACCESS_ENABLED: True,
|
||||
CONF_REMOTE_ACCESS_HOST: "the.cloud",
|
||||
CONF_REMOTE_ACCESS_PORT: 8816,
|
||||
CONF_MINOR_VERSION: 0x04,
|
||||
}
|
||||
assert migrated_entry.options == {
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[(255, 0, 0), (255, 255, 0), (0, 255, 0)]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 30,
|
||||
CONF_CUSTOM_EFFECT_TRANSITION: "strobe",
|
||||
}
|
||||
|
||||
|
||||
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",
|
||||
}
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
last_address = None
|
||||
|
||||
async def _discovery(self, *args, address=None, **kwargs):
|
||||
# Only return discovery results when doing directed discovery
|
||||
nonlocal last_address
|
||||
last_address = address
|
||||
return [FLUX_DISCOVERY] if address == IP_ADDRESS else []
|
||||
|
||||
def _mock_getBulbInfo(*args, **kwargs):
|
||||
nonlocal last_address
|
||||
return [FLUX_DISCOVERY] if last_address == IP_ADDRESS else []
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.async_scan",
|
||||
new=_discovery,
|
||||
), patch(
|
||||
"homeassistant.components.flux_led.discovery.AIOBulbScanner.getBulbInfo",
|
||||
new=_mock_getBulbInfo,
|
||||
), _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",
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_REMOTE_ACCESS_ENABLED: True,
|
||||
CONF_REMOTE_ACCESS_HOST: "the.cloud",
|
||||
CONF_REMOTE_ACCESS_PORT: 8816,
|
||||
CONF_MINOR_VERSION: 0x04,
|
||||
}
|
||||
assert migrated_entry.options == {
|
||||
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(
|
||||
|
|
Loading…
Reference in New Issue