Add unique ID to coronavirus (#32423)
parent
aacdc1bc2d
commit
c62961f40c
|
@ -42,6 +42,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||
hass, entry.entry_id, _async_migrator
|
||||
)
|
||||
|
||||
if not entry.unique_id:
|
||||
hass.config_entries.async_update_entry(entry, unique_id=entry.data["country"])
|
||||
|
||||
for component in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||
|
|
|
@ -32,6 +32,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._options[case.country] = case.country
|
||||
|
||||
if user_input is not None:
|
||||
await self.async_set_unique_id(user_input["country"])
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=self._options[user_input["country"]], data=user_input
|
||||
)
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
"country": "Country"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "This country is already configured."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ async def test_form(hass):
|
|||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], {"country": OPTION_WORLDWIDE},
|
||||
)
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "Worldwide"
|
||||
assert result2["result"].unique_id == OPTION_WORLDWIDE
|
||||
assert result2["data"] == {
|
||||
"country": OPTION_WORLDWIDE,
|
||||
}
|
||||
|
|
|
@ -53,3 +53,6 @@ async def test_migration(hass):
|
|||
|
||||
assert hass.states.get("sensor.netherlands_confirmed").state == "10"
|
||||
assert hass.states.get("sensor.worldwide_confirmed").state == "11"
|
||||
|
||||
assert nl_entry.unique_id == "Netherlands"
|
||||
assert worldwide_entry.unique_id == OPTION_WORLDWIDE
|
||||
|
|
Loading…
Reference in New Issue