Adax, unique id and title should be string (#63132)
This commit is contained in:
parent
b379acc119
commit
8e5c8c516d
3 changed files with 21 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue