Nanoleaf: remove deprecated YAML import (#69004)
This commit is contained in:
parent
d5f4e512e9
commit
513b05c927
3 changed files with 2 additions and 100 deletions
|
@ -184,17 +184,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return await self.async_setup_finish()
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle Nanoleaf configuration import."""
|
||||
self._async_abort_entries_match({CONF_HOST: config[CONF_HOST]})
|
||||
_LOGGER.debug(
|
||||
"Importing Nanoleaf on %s from your configuration.yaml", config[CONF_HOST]
|
||||
)
|
||||
self.nanoleaf = Nanoleaf(
|
||||
async_get_clientsession(self.hass), config[CONF_HOST], config[CONF_TOKEN]
|
||||
)
|
||||
return await self.async_setup_finish()
|
||||
|
||||
async def async_setup_finish(
|
||||
self, discovery_integration_import: bool = False
|
||||
) -> FlowResult:
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
"""Support for Nanoleaf Lights."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
from aionanoleaf import Nanoleaf
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
|
@ -14,7 +12,6 @@ from homeassistant.components.light import (
|
|||
ATTR_EFFECT,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_TRANSITION,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_COLOR_TEMP,
|
||||
|
@ -22,12 +19,9 @@ from homeassistant.components.light import (
|
|||
SUPPORT_TRANSITION,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
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 DataUpdateCoordinator
|
||||
from homeassistant.util.color import (
|
||||
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
||||
|
@ -41,38 +35,6 @@ from .entity import NanoleafEntity
|
|||
RESERVED_EFFECTS = ("*Solid*", "*Static*", "*Dynamic*")
|
||||
DEFAULT_NAME = "Nanoleaf"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_TOKEN): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Import Nanoleaf light platform."""
|
||||
_LOGGER.warning(
|
||||
"Configuration of the Nanoleaf integration in YAML is deprecated and "
|
||||
"will be removed in Home Assistant 2022.4; Your existing configuration "
|
||||
"has been imported into the UI automatically and can be safely removed "
|
||||
"from your configuration.yaml file"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_HOST: config[CONF_HOST], CONF_TOKEN: config[CONF_TOKEN]},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from aionanoleaf import InvalidToken, NanoleafException, Unauthorized, Unavailable
|
||||
from aionanoleaf import InvalidToken, Unauthorized, Unavailable
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
@ -302,55 +302,6 @@ async def test_reauth(hass: HomeAssistant) -> None:
|
|||
assert entry.data[CONF_TOKEN] == TEST_TOKEN
|
||||
|
||||
|
||||
async def test_import_config(hass: HomeAssistant) -> None:
|
||||
"""Test configuration import."""
|
||||
with patch(
|
||||
"homeassistant.components.nanoleaf.config_flow.Nanoleaf",
|
||||
return_value=_mock_nanoleaf(TEST_HOST, TEST_TOKEN),
|
||||
), patch(
|
||||
"homeassistant.components.nanoleaf.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={CONF_HOST: TEST_HOST, CONF_TOKEN: TEST_TOKEN},
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == TEST_NAME
|
||||
assert result["data"] == {
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_TOKEN: TEST_TOKEN,
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error, reason",
|
||||
[
|
||||
(Unavailable, "cannot_connect"),
|
||||
(InvalidToken, "invalid_token"),
|
||||
(Exception, "unknown"),
|
||||
],
|
||||
)
|
||||
async def test_import_config_error(
|
||||
hass: HomeAssistant, error: NanoleafException, reason: str
|
||||
) -> None:
|
||||
"""Test configuration import with errors in setup_finish."""
|
||||
with patch(
|
||||
"homeassistant.components.nanoleaf.config_flow.Nanoleaf.get_info",
|
||||
side_effect=error,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_HOST: TEST_HOST, CONF_TOKEN: TEST_TOKEN},
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source, type_in_discovery",
|
||||
[
|
||||
|
|
Loading…
Add table
Reference in a new issue