55from homeassistant .helpers import aiohttp_client , config_validation as cv
66from homeassistant .helpers .typing import ConfigType
77
8- from .const import _LOGGER , CONF_LOGIN_DATA , COUNTRY_DOMAINS , DOMAIN
8+ from .const import _LOGGER , CONF_LOGIN_DATA , CONF_SITE , COUNTRY_DOMAINS , DOMAIN
99from .coordinator import AmazonConfigEntry , AmazonDevicesCoordinator
1010from .services import async_setup_services
1111
@@ -42,7 +42,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: AmazonConfigEntry) -> bo
4242
4343async def async_migrate_entry (hass : HomeAssistant , entry : AmazonConfigEntry ) -> bool :
4444 """Migrate old entry."""
45- if entry .version == 1 and entry .minor_version == 1 :
45+
46+ if entry .version == 1 and entry .minor_version < 3 :
47+ if CONF_SITE in entry .data :
48+ # Site in data (wrong place), just move to login data
49+ new_data = entry .data .copy ()
50+ new_data [CONF_LOGIN_DATA ][CONF_SITE ] = new_data [CONF_SITE ]
51+ new_data .pop (CONF_SITE )
52+ hass .config_entries .async_update_entry (
53+ entry , data = new_data , version = 1 , minor_version = 3
54+ )
55+ return True
56+
57+ if CONF_SITE in entry .data [CONF_LOGIN_DATA ]:
58+ # Site is there, just update version to avoid future migrations
59+ hass .config_entries .async_update_entry (entry , version = 1 , minor_version = 3 )
60+ return True
61+
4662 _LOGGER .debug (
4763 "Migrating from version %s.%s" , entry .version , entry .minor_version
4864 )
@@ -53,10 +69,10 @@ async def async_migrate_entry(hass: HomeAssistant, entry: AmazonConfigEntry) ->
5369
5470 # Add site to login data
5571 new_data = entry .data .copy ()
56- new_data [CONF_LOGIN_DATA ]["site" ] = f"https://www.amazon.{ domain } "
72+ new_data [CONF_LOGIN_DATA ][CONF_SITE ] = f"https://www.amazon.{ domain } "
5773
5874 hass .config_entries .async_update_entry (
59- entry , data = new_data , version = 1 , minor_version = 2
75+ entry , data = new_data , version = 1 , minor_version = 3
6076 )
6177
6278 _LOGGER .info (
0 commit comments