From 20d93b4b298085547258831a76a2c4a0fac2ed1d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 15 Feb 2021 21:37:43 -1000 Subject: [PATCH] Remove support for migrating pre-config entry homekit (#46616) HomeKit pairings and accessory ids from versions 0.109 and earlier are no longer migrated on upgrade. Users upgrading directly to 2021.3 from 0.109 and older should upgrade to 2021.2 first if they wish to preserve HomeKit configuration and avoid re-pairing the bridge. This change does not affect upgrades from 0.110 and later. --- homeassistant/components/homekit/__init__.py | 9 --- homeassistant/components/homekit/util.py | 19 ------ tests/components/homekit/test_homekit.py | 71 +------------------- 3 files changed, 1 insertion(+), 98 deletions(-) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 34044742703..396f36f7c03 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -99,7 +99,6 @@ from .const import ( from .util import ( dismiss_setup_message, get_persist_fullpath_for_entry_id, - migrate_filesystem_state_data_for_primary_imported_entry_id, port_is_available, remove_state_files_for_entry_id, show_setup_message, @@ -238,14 +237,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): port = conf[CONF_PORT] _LOGGER.debug("Begin setup HomeKit for %s", name) - if CONF_ENTRY_INDEX in conf and conf[CONF_ENTRY_INDEX] == 0: - _LOGGER.debug("Migrating legacy HomeKit data for %s", name) - await hass.async_add_executor_job( - migrate_filesystem_state_data_for_primary_imported_entry_id, - hass, - entry.entry_id, - ) - aid_storage = AccessoryAidStorage(hass, entry.entry_id) await aid_storage.async_initialize() diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index 83a9a0a0353..c23b8c1baaf 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -66,7 +66,6 @@ from .const import ( FEATURE_PLAY_PAUSE, FEATURE_PLAY_STOP, FEATURE_TOGGLE_MUTE, - HOMEKIT_FILE, HOMEKIT_PAIRING_QR, HOMEKIT_PAIRING_QR_SECRET, TYPE_FAUCET, @@ -410,24 +409,6 @@ def format_sw_version(version): return None -def migrate_filesystem_state_data_for_primary_imported_entry_id( - hass: HomeAssistant, entry_id: str -): - """Migrate the old paths to the storage directory.""" - legacy_persist_file_path = hass.config.path(HOMEKIT_FILE) - if os.path.exists(legacy_persist_file_path): - os.rename( - legacy_persist_file_path, get_persist_fullpath_for_entry_id(hass, entry_id) - ) - - legacy_aid_storage_path = hass.config.path(STORAGE_DIR, "homekit.aids") - if os.path.exists(legacy_aid_storage_path): - os.rename( - legacy_aid_storage_path, - get_aid_storage_fullpath_for_entry_id(hass, entry_id), - ) - - def remove_state_files_for_entry_id(hass: HomeAssistant, entry_id: str): """Remove the state files from disk.""" persist_file_path = get_persist_fullpath_for_entry_id(hass, entry_id) diff --git a/tests/components/homekit/test_homekit.py b/tests/components/homekit/test_homekit.py index 1fff55db195..b0213ee7e8b 100644 --- a/tests/components/homekit/test_homekit.py +++ b/tests/components/homekit/test_homekit.py @@ -27,20 +27,15 @@ from homeassistant.components.homekit.const import ( BRIDGE_NAME, BRIDGE_SERIAL_NUMBER, CONF_AUTO_START, - CONF_ENTRY_INDEX, DEFAULT_PORT, DOMAIN, HOMEKIT, - HOMEKIT_FILE, HOMEKIT_MODE_ACCESSORY, HOMEKIT_MODE_BRIDGE, SERVICE_HOMEKIT_RESET_ACCESSORY, SERVICE_HOMEKIT_START, ) -from homeassistant.components.homekit.util import ( - get_aid_storage_fullpath_for_entry_id, - get_persist_fullpath_for_entry_id, -) +from homeassistant.components.homekit.util import get_persist_fullpath_for_entry_id from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import ( ATTR_DEVICE_CLASS, @@ -60,7 +55,6 @@ from homeassistant.const import ( from homeassistant.core import State from homeassistant.helpers import device_registry from homeassistant.helpers.entityfilter import generate_filter -from homeassistant.helpers.storage import STORAGE_DIR from homeassistant.setup import async_setup_component from homeassistant.util import json as json_util @@ -909,69 +903,6 @@ async def test_homekit_async_get_integration_fails( ) -async def test_setup_imported(hass, mock_zeroconf): - """Test async_setup with imported config options.""" - legacy_persist_file_path = hass.config.path(HOMEKIT_FILE) - legacy_aid_storage_path = hass.config.path(STORAGE_DIR, "homekit.aids") - legacy_homekit_state_contents = {"homekit.state": 1} - legacy_homekit_aids_contents = {"homekit.aids": 1} - await hass.async_add_executor_job( - _write_data, legacy_persist_file_path, legacy_homekit_state_contents - ) - await hass.async_add_executor_job( - _write_data, legacy_aid_storage_path, legacy_homekit_aids_contents - ) - - entry = MockConfigEntry( - domain=DOMAIN, - source=SOURCE_IMPORT, - data={CONF_NAME: BRIDGE_NAME, CONF_PORT: DEFAULT_PORT, CONF_ENTRY_INDEX: 0}, - options={}, - ) - entry.add_to_hass(hass) - - with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit: - mock_homekit.return_value = homekit = Mock() - type(homekit).async_start = AsyncMock() - assert await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - - mock_homekit.assert_any_call( - hass, - BRIDGE_NAME, - DEFAULT_PORT, - None, - ANY, - {}, - HOMEKIT_MODE_BRIDGE, - None, - entry.entry_id, - ) - assert mock_homekit().setup.called is True - - # Test auto start enabled - mock_homekit.reset_mock() - hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED) - await hass.async_block_till_done() - - mock_homekit().async_start.assert_called() - - migrated_persist_file_path = get_persist_fullpath_for_entry_id(hass, entry.entry_id) - assert ( - await hass.async_add_executor_job( - json_util.load_json, migrated_persist_file_path - ) - == legacy_homekit_state_contents - ) - os.unlink(migrated_persist_file_path) - migrated_aid_file_path = get_aid_storage_fullpath_for_entry_id(hass, entry.entry_id) - assert ( - await hass.async_add_executor_job(json_util.load_json, migrated_aid_file_path) - == legacy_homekit_aids_contents - ) - os.unlink(migrated_aid_file_path) - - async def test_yaml_updates_update_config_entry_for_name(hass, mock_zeroconf): """Test async_setup with imported config.""" entry = MockConfigEntry(