mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Remove deprecated Switchbot import (#69002)
This commit is contained in:
parent
3bc2586874
commit
88c9233d50
@ -131,19 +131,6 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="user", data_schema=data_schema, errors=errors
|
step_id="user", data_schema=data_schema, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Handle config import from yaml."""
|
|
||||||
_LOGGER.debug("import config: %s", import_config)
|
|
||||||
|
|
||||||
import_config[CONF_MAC] = import_config[CONF_MAC].replace("-", ":").lower()
|
|
||||||
|
|
||||||
await self.async_set_unique_id(import_config[CONF_MAC].replace(":", ""))
|
|
||||||
self._abort_if_unique_id_configured()
|
|
||||||
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=import_config[CONF_NAME], data=import_config
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SwitchbotOptionsFlowHandler(OptionsFlow):
|
class SwitchbotOptionsFlowHandler(OptionsFlow):
|
||||||
"""Handle Switchbot options."""
|
"""Handle Switchbot options."""
|
||||||
|
@ -5,27 +5,15 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from switchbot import Switchbot # pylint: disable=import-error
|
from switchbot import Switchbot # pylint: disable=import-error
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||||
PLATFORM_SCHEMA,
|
from homeassistant.config_entries import ConfigEntry
|
||||||
SwitchDeviceClass,
|
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, STATE_ON
|
||||||
SwitchEntity,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_MAC,
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_SENSOR_TYPE,
|
|
||||||
STATE_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import ATTR_BOT, CONF_RETRY_COUNT, DATA_COORDINATOR, DEFAULT_NAME, DOMAIN
|
from .const import CONF_RETRY_COUNT, DATA_COORDINATOR, DOMAIN
|
||||||
from .coordinator import SwitchbotDataUpdateCoordinator
|
from .coordinator import SwitchbotDataUpdateCoordinator
|
||||||
from .entity import SwitchbotEntity
|
from .entity import SwitchbotEntity
|
||||||
|
|
||||||
@ -33,46 +21,6 @@ from .entity import SwitchbotEntity
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_MAC): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_PASSWORD): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: entity_platform.AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Import yaml config and initiates config flow for Switchbot devices."""
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Configuration of the Switchbot switch platform 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"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check if entry config exists and skips import if it does.
|
|
||||||
if hass.config_entries.async_entries(DOMAIN):
|
|
||||||
return
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_NAME: config[CONF_NAME],
|
|
||||||
CONF_PASSWORD: config.get(CONF_PASSWORD, None),
|
|
||||||
CONF_MAC: config[CONF_MAC].replace("-", ":").lower(),
|
|
||||||
CONF_SENSOR_TYPE: ATTR_BOT,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Tests for the switchbot integration."""
|
"""Tests for the switchbot integration."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE
|
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -38,15 +38,9 @@ USER_INPUT_INVALID = {
|
|||||||
CONF_MAC: "invalid-mac",
|
CONF_MAC: "invalid-mac",
|
||||||
}
|
}
|
||||||
|
|
||||||
YAML_CONFIG = {
|
|
||||||
CONF_NAME: "test-name",
|
|
||||||
CONF_PASSWORD: "test-password",
|
|
||||||
CONF_MAC: "e7:89:43:99:99:99",
|
|
||||||
CONF_SENSOR_TYPE: "bot",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
def patch_async_setup_entry(return_value=True):
|
||||||
def _patch_async_setup_entry(return_value=True):
|
"""Patch async setup entry to return True."""
|
||||||
return patch(
|
return patch(
|
||||||
"homeassistant.components.switchbot.async_setup_entry",
|
"homeassistant.components.switchbot.async_setup_entry",
|
||||||
return_value=return_value,
|
return_value=return_value,
|
||||||
|
@ -7,7 +7,7 @@ from homeassistant.components.switchbot.const import (
|
|||||||
CONF_SCAN_TIMEOUT,
|
CONF_SCAN_TIMEOUT,
|
||||||
CONF_TIME_BETWEEN_UPDATE_COMMAND,
|
CONF_TIME_BETWEEN_UPDATE_COMMAND,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE
|
from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE
|
||||||
from homeassistant.data_entry_flow import (
|
from homeassistant.data_entry_flow import (
|
||||||
RESULT_TYPE_ABORT,
|
RESULT_TYPE_ABORT,
|
||||||
@ -15,13 +15,7 @@ from homeassistant.data_entry_flow import (
|
|||||||
RESULT_TYPE_FORM,
|
RESULT_TYPE_FORM,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import (
|
from . import USER_INPUT, USER_INPUT_CURTAIN, init_integration, patch_async_setup_entry
|
||||||
USER_INPUT,
|
|
||||||
USER_INPUT_CURTAIN,
|
|
||||||
YAML_CONFIG,
|
|
||||||
_patch_async_setup_entry,
|
|
||||||
init_integration,
|
|
||||||
)
|
|
||||||
|
|
||||||
DOMAIN = "switchbot"
|
DOMAIN = "switchbot"
|
||||||
|
|
||||||
@ -36,7 +30,7 @@ async def test_user_form_valid_mac(hass):
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with _patch_async_setup_entry() as mock_setup_entry:
|
with patch_async_setup_entry() as mock_setup_entry:
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
USER_INPUT,
|
USER_INPUT,
|
||||||
@ -63,7 +57,7 @@ async def test_user_form_valid_mac(hass):
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
with _patch_async_setup_entry() as mock_setup_entry:
|
with patch_async_setup_entry() as mock_setup_entry:
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
USER_INPUT_CURTAIN,
|
USER_INPUT_CURTAIN,
|
||||||
@ -90,24 +84,6 @@ async def test_user_form_valid_mac(hass):
|
|||||||
assert result["reason"] == "no_unconfigured_devices"
|
assert result["reason"] == "no_unconfigured_devices"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_import(hass):
|
|
||||||
"""Test the config import flow."""
|
|
||||||
|
|
||||||
with _patch_async_setup_entry() as mock_setup_entry:
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG
|
|
||||||
)
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["data"] == {
|
|
||||||
CONF_MAC: "e7:89:43:99:99:99",
|
|
||||||
CONF_NAME: "test-name",
|
|
||||||
CONF_PASSWORD: "test-password",
|
|
||||||
CONF_SENSOR_TYPE: "bot",
|
|
||||||
}
|
|
||||||
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_form_exception(hass, switchbot_config_flow):
|
async def test_user_form_exception(hass, switchbot_config_flow):
|
||||||
"""Test we handle exception on user form."""
|
"""Test we handle exception on user form."""
|
||||||
|
|
||||||
@ -132,7 +108,7 @@ async def test_user_form_exception(hass, switchbot_config_flow):
|
|||||||
|
|
||||||
async def test_options_flow(hass):
|
async def test_options_flow(hass):
|
||||||
"""Test updating options."""
|
"""Test updating options."""
|
||||||
with _patch_async_setup_entry() as mock_setup_entry:
|
with patch_async_setup_entry() as mock_setup_entry:
|
||||||
entry = await init_integration(hass)
|
entry = await init_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||||
@ -161,7 +137,7 @@ async def test_options_flow(hass):
|
|||||||
|
|
||||||
# Test changing of entry options.
|
# Test changing of entry options.
|
||||||
|
|
||||||
with _patch_async_setup_entry() as mock_setup_entry:
|
with patch_async_setup_entry() as mock_setup_entry:
|
||||||
entry = await init_integration(hass)
|
entry = await init_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user