From d0eb90274df6704afd686328d3aca6e0cd8977bd Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:00:20 +0100 Subject: [PATCH] Cleanup deprecated YAML import from vera (#165659) --- homeassistant/components/vera/__init__.py | 39 +------------- homeassistant/components/vera/common.py | 2 +- homeassistant/components/vera/config_flow.py | 27 ---------- tests/components/vera/common.py | 12 ----- tests/components/vera/test_config_flow.py | 57 +------------------- tests/components/vera/test_init.py | 36 ++----------- 6 files changed, 7 insertions(+), 166 deletions(-) diff --git a/homeassistant/components/vera/__init__.py b/homeassistant/components/vera/__init__.py index aedc174cb6d..8e4b7e35f43 100644 --- a/homeassistant/components/vera/__init__.py +++ b/homeassistant/components/vera/__init__.py @@ -8,9 +8,7 @@ import logging import pyvera as veraApi from requests.exceptions import RequestException -import voluptuous as vol -from homeassistant import config_entries from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_EXCLUDE, @@ -21,7 +19,6 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.typing import ConfigType from .common import ( ControllerData, @@ -35,41 +32,7 @@ from .const import CONF_CONTROLLER, DOMAIN _LOGGER = logging.getLogger(__name__) -VERA_ID_LIST_SCHEMA = vol.Schema([int]) - -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_CONTROLLER): cv.url, - vol.Optional(CONF_EXCLUDE, default=[]): VERA_ID_LIST_SCHEMA, - vol.Optional(CONF_LIGHTS, default=[]): VERA_ID_LIST_SCHEMA, - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) - - -async def async_setup(hass: HomeAssistant, base_config: ConfigType) -> bool: - """Set up for Vera controllers.""" - hass.data[DOMAIN] = {} - - if not (config := base_config.get(DOMAIN)): - return True - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=config, - ) - ) - - return True +CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/vera/common.py b/homeassistant/components/vera/common.py index 76adeeab1d2..a6e6e097b4a 100644 --- a/homeassistant/components/vera/common.py +++ b/homeassistant/components/vera/common.py @@ -46,7 +46,7 @@ def set_controller_data( hass: HomeAssistant, config_entry: ConfigEntry, data: ControllerData ) -> None: """Set controller data in hass data.""" - hass.data[DOMAIN][config_entry.entry_id] = data + hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = data class SubscriptionRegistry(pv.AbstractSubscriptionRegistry): diff --git a/homeassistant/components/vera/config_flow.py b/homeassistant/components/vera/config_flow.py index dfc0914e32e..7879d103595 100644 --- a/homeassistant/components/vera/config_flow.py +++ b/homeassistant/components/vera/config_flow.py @@ -12,7 +12,6 @@ from requests.exceptions import RequestException import voluptuous as vol from homeassistant.config_entries import ( - SOURCE_IMPORT, SOURCE_USER, ConfigEntry, ConfigFlow, @@ -21,7 +20,6 @@ from homeassistant.config_entries import ( ) from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE from homeassistant.core import callback -from homeassistant.helpers import entity_registry as er from homeassistant.helpers.typing import VolDictType from .const import CONF_CONTROLLER, CONF_LEGACY_UNIQUE_ID, DOMAIN @@ -131,31 +129,6 @@ class VeraFlowHandler(ConfigFlow, domain=DOMAIN): }, ) - async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult: - """Handle a flow initialized by import.""" - - # If there are entities with the legacy unique_id, then this imported config - # should also use the legacy unique_id for entity creation. - entity_registry = er.async_get(self.hass) - use_legacy_unique_id = ( - len( - [ - entry - for entry in entity_registry.entities.values() - if entry.platform == DOMAIN and entry.unique_id.isdigit() - ] - ) - > 0 - ) - - return await self.async_step_finish( - { - **import_data, - CONF_SOURCE: SOURCE_IMPORT, - CONF_LEGACY_UNIQUE_ID: use_legacy_unique_id, - } - ) - async def async_step_finish(self, config: dict[str, Any]) -> ConfigFlowResult: """Validate and create config entry.""" base_url = config[CONF_CONTROLLER] = config[CONF_CONTROLLER].rstrip("/") diff --git a/tests/components/vera/common.py b/tests/components/vera/common.py index c5e3a5d4931..78759e23602 100644 --- a/tests/components/vera/common.py +++ b/tests/components/vera/common.py @@ -16,7 +16,6 @@ from homeassistant.components.vera.const import ( DOMAIN, ) from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry @@ -39,7 +38,6 @@ class ComponentData(NamedTuple): class ConfigSource(Enum): """Source of configuration.""" - FILE = "file" CONFIG_FLOW = "config_flow" CONFIG_ENTRY = "config_entry" @@ -142,16 +140,6 @@ class ComponentFactory: self.vera_controller_class_mock.return_value = controller - hass_config = {} - - # Setup component through config file import. - if controller_config.config_source == ConfigSource.FILE: - hass_config[DOMAIN] = component_config - - # Setup Home Assistant. - assert await async_setup_component(hass, DOMAIN, hass_config) - await hass.async_block_till_done() - # Setup component through config flow. if controller_config.config_source == ConfigSource.CONFIG_FLOW: await hass.config_entries.flow.async_init( diff --git a/tests/components/vera/test_config_flow.py b/tests/components/vera/test_config_flow.py index f0210d58707..3458ce0b986 100644 --- a/tests/components/vera/test_config_flow.py +++ b/tests/components/vera/test_config_flow.py @@ -15,7 +15,6 @@ from homeassistant.components.vera.const import ( from homeassistant.const import CONF_EXCLUDE, CONF_LIGHTS, CONF_SOURCE from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry @@ -66,60 +65,6 @@ async def test_async_step_user_success(hass: HomeAssistant) -> None: assert entries -async def test_async_step_import_success(hass: HomeAssistant) -> None: - """Test import step success.""" - with patch("pyvera.VeraController") as vera_controller_class_mock: - controller = MagicMock() - controller.refresh_data = MagicMock() - controller.serial_number = "serial_number_1" - vera_controller_class_mock.return_value = controller - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={CONF_CONTROLLER: "http://127.0.0.1:123/"}, - ) - - assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "http://127.0.0.1:123" - assert result["data"] == { - CONF_CONTROLLER: "http://127.0.0.1:123", - CONF_SOURCE: config_entries.SOURCE_IMPORT, - CONF_LEGACY_UNIQUE_ID: False, - } - assert result["result"].unique_id == controller.serial_number - - -async def test_async_step_import_success_with_legacy_unique_id( - hass: HomeAssistant, entity_registry: er.EntityRegistry -) -> None: - """Test import step success with legacy unique id.""" - entity_registry.async_get_or_create( - domain="switch", platform=DOMAIN, unique_id="12" - ) - - with patch("pyvera.VeraController") as vera_controller_class_mock: - controller = MagicMock() - controller.refresh_data = MagicMock() - controller.serial_number = "serial_number_1" - vera_controller_class_mock.return_value = controller - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={CONF_CONTROLLER: "http://127.0.0.1:123/"}, - ) - - assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "http://127.0.0.1:123" - assert result["data"] == { - CONF_CONTROLLER: "http://127.0.0.1:123", - CONF_SOURCE: config_entries.SOURCE_IMPORT, - CONF_LEGACY_UNIQUE_ID: True, - } - assert result["result"].unique_id == controller.serial_number - - async def test_async_step_finish_error(hass: HomeAssistant) -> None: """Test finish step with error.""" with patch("pyvera.VeraController") as vera_controller_class_mock: @@ -129,7 +74,7 @@ async def test_async_step_finish_error(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, + context={"source": config_entries.SOURCE_USER}, data={CONF_CONTROLLER: "http://127.0.0.1:123/"}, ) diff --git a/tests/components/vera/test_init.py b/tests/components/vera/test_init.py index 47890c4e70a..3acb1982ca7 100644 --- a/tests/components/vera/test_init.py +++ b/tests/components/vera/test_init.py @@ -49,40 +49,12 @@ async def test_init( assert entry1.unique_id == "vera_first_serial_1" -async def test_init_from_file( +async def test_multiple_controllers( hass: HomeAssistant, entity_registry: er.EntityRegistry, vera_component_factory: ComponentFactory, ) -> None: - """Test function.""" - vera_device1: pv.VeraBinarySensor = MagicMock(spec=pv.VeraBinarySensor) - vera_device1.device_id = 1 - vera_device1.vera_device_id = vera_device1.device_id - vera_device1.name = "first_dev" - vera_device1.is_tripped = False - entity1_id = "binary_sensor.first_dev_1" - - await vera_component_factory.configure_component( - hass=hass, - controller_config=new_simple_controller_config( - config={CONF_CONTROLLER: "http://127.0.0.1:111"}, - config_source=ConfigSource.FILE, - serial_number="first_serial", - devices=(vera_device1,), - ), - ) - - entry1 = entity_registry.async_get(entity1_id) - assert entry1 - assert entry1.unique_id == "vera_first_serial_1" - - -async def test_multiple_controllers_with_legacy_one( - hass: HomeAssistant, - entity_registry: er.EntityRegistry, - vera_component_factory: ComponentFactory, -) -> None: - """Test multiple controllers with one legacy controller.""" + """Test multiple controllers.""" vera_device1: pv.VeraBinarySensor = MagicMock(spec=pv.VeraBinarySensor) vera_device1.device_id = 1 vera_device1.vera_device_id = vera_device1.device_id @@ -106,7 +78,7 @@ async def test_multiple_controllers_with_legacy_one( hass=hass, controller_config=new_simple_controller_config( config={CONF_CONTROLLER: "http://127.0.0.1:111"}, - config_source=ConfigSource.FILE, + config_source=ConfigSource.CONFIG_FLOW, serial_number="first_serial", devices=(vera_device1,), ), @@ -124,7 +96,7 @@ async def test_multiple_controllers_with_legacy_one( entry1 = entity_registry.async_get(entity1_id) assert entry1 - assert entry1.unique_id == "1" + assert entry1.unique_id == "vera_first_serial_1" entry2 = entity_registry.async_get(entity2_id) assert entry2