From 8e5c8c516d1d6e315dffced6fcdf0bfd1cc4f849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hjelseth=20H=C3=B8yer?= Date: Fri, 31 Dec 2021 23:22:47 +0100 Subject: [PATCH] Adax, unique id and title should be string (#63132) --- homeassistant/components/adax/__init__.py | 15 +++++++++++++++ homeassistant/components/adax/config_flow.py | 8 ++++---- tests/components/adax/test_config_flow.py | 4 ++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/adax/__init__.py b/homeassistant/components/adax/__init__.py index bf339e810c6..dc24e741c89 100644 --- a/homeassistant/components/adax/__init__.py +++ b/homeassistant/components/adax/__init__.py @@ -17,3 +17,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + + +async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: + """Migrate old entry.""" + # convert title and unique_id to string + if config_entry.version == 1: + if isinstance(config_entry.unique_id, int): + + hass.config_entries.async_update_entry( + config_entry, + unique_id=str(config_entry.unique_id), + title=str(config_entry.title), + ) + + return True diff --git a/homeassistant/components/adax/config_flow.py b/homeassistant/components/adax/config_flow.py index e3921258426..b9e8ef1abca 100644 --- a/homeassistant/components/adax/config_flow.py +++ b/homeassistant/components/adax/config_flow.py @@ -34,7 +34,7 @@ _LOGGER = logging.getLogger(__name__) class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Handle a config flow for Adax.""" - VERSION = 1 + VERSION = 2 async def async_step_user(self, user_input=None): """Handle the initial step.""" @@ -90,7 +90,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors={"base": "cannot_connect"}, ) - unique_id = configurator.mac_id + unique_id = str(configurator.mac_id) await self.async_set_unique_id(unique_id) self._abort_if_unique_id_configured() @@ -116,7 +116,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors = {} - await self.async_set_unique_id(user_input[ACCOUNT_ID]) + await self.async_set_unique_id(str(user_input[ACCOUNT_ID])) self._abort_if_unique_id_configured() account_id = user_input[ACCOUNT_ID] @@ -135,7 +135,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) return self.async_create_entry( - title=user_input[ACCOUNT_ID], + title=str(user_input[ACCOUNT_ID]), data={ ACCOUNT_ID: account_id, CONF_PASSWORD: password, diff --git a/tests/components/adax/test_config_flow.py b/tests/components/adax/test_config_flow.py index d35a18cdacc..998e4df8b15 100644 --- a/tests/components/adax/test_config_flow.py +++ b/tests/components/adax/test_config_flow.py @@ -52,7 +52,7 @@ async def test_form(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert result3["type"] == "create_entry" - assert result3["title"] == TEST_DATA["account_id"] + assert result3["title"] == str(TEST_DATA["account_id"]) assert result3["data"] == { ACCOUNT_ID: TEST_DATA["account_id"], CONF_PASSWORD: TEST_DATA["password"], @@ -93,7 +93,7 @@ async def test_flow_entry_already_exists(hass: HomeAssistant) -> None: first_entry = MockConfigEntry( domain="adax", data=TEST_DATA, - unique_id=TEST_DATA[ACCOUNT_ID], + unique_id=str(TEST_DATA[ACCOUNT_ID]), ) first_entry.add_to_hass(hass)