Smhi reverse change of unique id change (#74176)
This commit is contained in:
parent
4e079c4417
commit
97dcfe4445
5 changed files with 39 additions and 31 deletions
|
@ -9,11 +9,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components.smhi.const import DOMAIN
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LOCATION, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -27,7 +23,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
|
@ -48,7 +44,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result2["title"] == "Home"
|
||||
assert result2["data"] == {
|
||||
"location": {
|
||||
|
@ -81,7 +77,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result4["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result4["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result4["title"] == "Weather 1.0 1.0"
|
||||
assert result4["data"] == {
|
||||
"location": {
|
||||
|
@ -113,7 +109,7 @@ async def test_form_invalid_coordinates(hass: HomeAssistant) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == RESULT_TYPE_FORM
|
||||
assert result2["type"] == FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": "wrong_location"}
|
||||
|
||||
# Continue flow with new coordinates
|
||||
|
@ -135,7 +131,7 @@ async def test_form_invalid_coordinates(hass: HomeAssistant) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result3["title"] == "Weather 2.0 2.0"
|
||||
assert result3["data"] == {
|
||||
"location": {
|
||||
|
@ -150,7 +146,7 @@ async def test_form_unique_id_exist(hass: HomeAssistant) -> None:
|
|||
"""Test we handle unique id already exist."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="smhi-1.0-1.0",
|
||||
unique_id="1.0-1.0",
|
||||
data={
|
||||
"location": {
|
||||
"latitude": 1.0,
|
||||
|
@ -179,5 +175,5 @@ async def test_form_unique_id_exist(hass: HomeAssistant) -> None:
|
|||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == RESULT_TYPE_ABORT
|
||||
assert result2["type"] == FlowResultType.ABORT
|
||||
assert result2["reason"] == "already_configured"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Test SMHI component setup process."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from smhi.smhi_lib import APIURL_TEMPLATE
|
||||
|
||||
from homeassistant.components.smhi.const import DOMAIN
|
||||
|
@ -56,7 +58,7 @@ async def test_remove_entry(
|
|||
async def test_migrate_entry(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str
|
||||
) -> None:
|
||||
"""Test migrate entry and entities unique id."""
|
||||
"""Test migrate entry data."""
|
||||
uri = APIURL_TEMPLATE.format(
|
||||
TEST_CONFIG_MIGRATE["longitude"], TEST_CONFIG_MIGRATE["latitude"]
|
||||
)
|
||||
|
@ -82,7 +84,29 @@ async def test_migrate_entry(
|
|||
assert state
|
||||
|
||||
assert entry.version == 2
|
||||
assert entry.unique_id == "smhi-17.84197-17.84197"
|
||||
assert entry.unique_id == "17.84197-17.84197"
|
||||
|
||||
entity_get = entity_reg.async_get(entity.entity_id)
|
||||
assert entity_get.unique_id == "smhi-17.84197-17.84197"
|
||||
assert entity_get.unique_id == "17.84197, 17.84197"
|
||||
|
||||
|
||||
async def test_migrate_entry_failed(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, api_response: str
|
||||
) -> None:
|
||||
"""Test migrate entry data that fails."""
|
||||
uri = APIURL_TEMPLATE.format(
|
||||
TEST_CONFIG_MIGRATE["longitude"], TEST_CONFIG_MIGRATE["latitude"]
|
||||
)
|
||||
aioclient_mock.get(uri, text=api_response)
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=TEST_CONFIG_MIGRATE)
|
||||
entry.add_to_hass(hass)
|
||||
assert entry.version == 1
|
||||
|
||||
with patch(
|
||||
"homeassistant.config_entries.ConfigEntries.async_update_entry",
|
||||
return_value=False,
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.version == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue