Remove YAML import support for plum_lightpad (#108114)
parent
ef7ebcffd6
commit
b46d0fb07c
|
@ -3,75 +3,25 @@ import logging
|
|||
|
||||
from aiohttp import ContentTypeError
|
||||
from requests.exceptions import ConnectTimeout, HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import DOMAIN
|
||||
from .utils import load_plum
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
PLATFORMS = [Platform.LIGHT]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Plum Lightpad Platform initialization."""
|
||||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
conf = config[DOMAIN]
|
||||
|
||||
_LOGGER.debug("Found Plum Lightpad configuration in config, importing")
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
|
||||
)
|
||||
)
|
||||
async_create_issue(
|
||||
hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
breaks_in_ha_version="2024.2.0",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": "Plum Lightpad",
|
||||
},
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Plum Lightpad from a config entry."""
|
||||
_LOGGER.debug("Setting up config entry with ID = %s", entry.unique_id)
|
||||
|
|
|
@ -58,9 +58,3 @@ class PlumLightpadConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
return self.async_create_entry(
|
||||
title=username, data={CONF_USERNAME: username, CONF_PASSWORD: password}
|
||||
)
|
||||
|
||||
async def async_step_import(
|
||||
self, import_config: dict[str, Any] | None
|
||||
) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
return await self.async_step_user(import_config)
|
||||
|
|
|
@ -22,8 +22,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
|
@ -39,7 +37,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
"username": "test-plum-username",
|
||||
"password": "test-plum-password",
|
||||
}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
@ -76,7 +73,7 @@ async def test_form_one_entry_per_email_allowed(hass: HomeAssistant) -> None:
|
|||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch("homeassistant.components.plum_lightpad.async_setup") as mock_setup, patch(
|
||||
), patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry"
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -86,32 +83,4 @@ async def test_form_one_entry_per_email_allowed(hass: HomeAssistant) -> None:
|
|||
|
||||
assert result2["type"] == "abort"
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_import(hass: HomeAssistant) -> None:
|
||||
"""Test configuring the flow using configuration.yaml."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.plum_lightpad.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={"username": "test-plum-username", "password": "test-plum-password"},
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "test-plum-username"
|
||||
assert result["data"] == {
|
||||
"username": "test-plum-username",
|
||||
"password": "test-plum-password",
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
|
|
@ -19,31 +19,6 @@ async def test_async_setup_no_domain_config(hass: HomeAssistant) -> None:
|
|||
assert DOMAIN not in hass.data
|
||||
|
||||
|
||||
async def test_async_setup_imports_from_config(hass: HomeAssistant) -> None:
|
||||
"""Test that specifying config will setup an entry."""
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
) as mock_loadCloudData, patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_async_setup_entry:
|
||||
result = await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: {
|
||||
"username": "test-plum-username",
|
||||
"password": "test-plum-password",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result is True
|
||||
assert len(mock_loadCloudData.mock_calls) == 1
|
||||
assert len(mock_async_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_setup_entry_sets_up_light(hass: HomeAssistant) -> None:
|
||||
"""Test that configuring entry sets up light domain."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
|
Loading…
Reference in New Issue