Remove Switcher YAML import support (#117994)

This commit is contained in:
Shay Levy 2024-05-23 22:12:19 +03:00 committed by GitHub
parent 4ee1460eec
commit c0bcf00bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 7 additions and 106 deletions

View file

@ -5,21 +5,12 @@ from __future__ import annotations
import logging import logging
from aioswitcher.device import SwitcherBase from aioswitcher.device import SwitcherBase
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICE_ID, EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
from homeassistant.core import Event, HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import ( from .const import DATA_DEVICE, DATA_DISCOVERY, DOMAIN
CONF_DEVICE_PASSWORD,
CONF_PHONE_ID,
DATA_DEVICE,
DATA_DISCOVERY,
DOMAIN,
)
from .coordinator import SwitcherDataUpdateCoordinator from .coordinator import SwitcherDataUpdateCoordinator
from .utils import async_start_bridge, async_stop_bridge from .utils import async_start_bridge, async_stop_bridge
@ -33,40 +24,10 @@ PLATFORMS = [
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_PHONE_ID): cv.string,
vol.Required(CONF_DEVICE_ID): cv.string,
vol.Required(CONF_DEVICE_PASSWORD): cv.string,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the switcher component."""
hass.data.setdefault(DOMAIN, {})
if DOMAIN not in config:
return True
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data={}
)
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Switcher from a config entry.""" """Set up Switcher from a config entry."""
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][DATA_DEVICE] = {} hass.data[DOMAIN][DATA_DEVICE] = {}
@callback @callback

View file

@ -13,15 +13,6 @@ from .utils import async_discover_devices
class SwitcherFlowHandler(ConfigFlow, domain=DOMAIN): class SwitcherFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle Switcher config flow.""" """Handle Switcher config flow."""
async def async_step_import(
self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Handle a flow initiated by import."""
if self._async_current_entries(True):
return self.async_abort(reason="single_instance_allowed")
return self.async_create_entry(title="Switcher", data={})
async def async_step_user( async def async_step_user(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult: ) -> ConfigFlowResult:

View file

@ -2,9 +2,6 @@
DOMAIN = "switcher_kis" DOMAIN = "switcher_kis"
CONF_DEVICE_PASSWORD = "device_password"
CONF_PHONE_ID = "phone_id"
DATA_BRIDGE = "bridge" DATA_BRIDGE = "bridge"
DATA_DEVICE = "device" DATA_DEVICE = "device"
DATA_DISCOVERY = "discovery" DATA_DISCOVERY = "discovery"

View file

@ -13,13 +13,6 @@ from aioswitcher.device import (
ThermostatSwing, ThermostatSwing,
) )
from homeassistant.components.switcher_kis import (
CONF_DEVICE_ID,
CONF_DEVICE_PASSWORD,
CONF_PHONE_ID,
DOMAIN,
)
DUMMY_AUTO_OFF_SET = "01:30:00" DUMMY_AUTO_OFF_SET = "01:30:00"
DUMMY_AUTO_SHUT_DOWN = "02:00:00" DUMMY_AUTO_SHUT_DOWN = "02:00:00"
DUMMY_DEVICE_ID1 = "a123bc" DUMMY_DEVICE_ID1 = "a123bc"
@ -59,14 +52,6 @@ DUMMY_REMOTE_ID = "ELEC7001"
DUMMY_POSITION = 54 DUMMY_POSITION = 54
DUMMY_DIRECTION = ShutterDirection.SHUTTER_STOP DUMMY_DIRECTION = ShutterDirection.SHUTTER_STOP
YAML_CONFIG = {
DOMAIN: {
CONF_PHONE_ID: DUMMY_PHONE_ID,
CONF_DEVICE_ID: DUMMY_DEVICE_ID1,
CONF_DEVICE_PASSWORD: DUMMY_DEVICE_PASSWORD,
}
}
DUMMY_PLUG_DEVICE = SwitcherPowerPlug( DUMMY_PLUG_DEVICE = SwitcherPowerPlug(
DeviceType.POWER_PLUG, DeviceType.POWER_PLUG,
DeviceState.ON, DeviceState.ON,

View file

@ -14,20 +14,6 @@ from .consts import DUMMY_PLUG_DEVICE, DUMMY_WATER_HEATER_DEVICE
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
async def test_import(hass: HomeAssistant) -> None:
"""Test import step."""
with patch(
"homeassistant.components.switcher_kis.async_setup_entry", return_value=True
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Switcher"
assert result["data"] == {}
@pytest.mark.parametrize( @pytest.mark.parametrize(
"mock_bridge", "mock_bridge",
[ [
@ -88,20 +74,13 @@ async def test_user_setup_abort_no_devices_found(
assert result2["reason"] == "no_devices_found" assert result2["reason"] == "no_devices_found"
@pytest.mark.parametrize( async def test_single_instance(hass: HomeAssistant) -> None:
"source",
[
config_entries.SOURCE_IMPORT,
config_entries.SOURCE_USER,
],
)
async def test_single_instance(hass: HomeAssistant, source) -> None:
"""Test we only allow a single config flow.""" """Test we only allow a single config flow."""
MockConfigEntry(domain=DOMAIN).add_to_hass(hass) MockConfigEntry(domain=DOMAIN).add_to_hass(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": source} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT

View file

@ -14,26 +14,14 @@ from homeassistant.components.switcher_kis.const import (
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util, slugify from homeassistant.util import dt as dt_util, slugify
from . import init_integration from . import init_integration
from .consts import DUMMY_SWITCHER_DEVICES, YAML_CONFIG from .consts import DUMMY_SWITCHER_DEVICES
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
@pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True)
async def test_async_setup_yaml_config(hass: HomeAssistant, mock_bridge) -> None:
"""Test setup started by configuration from YAML."""
assert await async_setup_component(hass, DOMAIN, YAML_CONFIG)
await hass.async_block_till_done()
assert mock_bridge.is_running is True
assert len(hass.data[DOMAIN]) == 2
assert len(hass.data[DOMAIN][DATA_DEVICE]) == 2
@pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True) @pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True)
async def test_async_setup_user_config_flow(hass: HomeAssistant, mock_bridge) -> None: async def test_async_setup_user_config_flow(hass: HomeAssistant, mock_bridge) -> None:
"""Test setup started by user config flow.""" """Test setup started by user config flow."""