-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate wolflink config_entry unique_id to string (#125653)
* Migrate wolflink config_entry unique_id to string * Move CONFIG to const * isinstance * Migrate identifiers * Use async_migrate_entry
- Loading branch information
Showing
6 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Constants for the Wolf SmartSet Service tests.""" | ||
|
||
from homeassistant.components.wolflink.const import ( | ||
DEVICE_GATEWAY, | ||
DEVICE_ID, | ||
DEVICE_NAME, | ||
) | ||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME | ||
|
||
CONFIG = { | ||
DEVICE_NAME: "test-device", | ||
DEVICE_ID: 1234, | ||
DEVICE_GATEWAY: 5678, | ||
CONF_USERNAME: "test-username", | ||
CONF_PASSWORD: "test-password", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Test the Wolf SmartSet Service.""" | ||
|
||
from unittest.mock import patch | ||
|
||
from httpx import RequestError | ||
|
||
from homeassistant.components.wolflink.const import DEVICE_ID, DOMAIN, MANUFACTURER | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import device_registry as dr | ||
|
||
from .const import CONFIG | ||
|
||
from tests.common import MockConfigEntry | ||
|
||
|
||
async def test_unique_id_migration( | ||
hass: HomeAssistant, device_registry: dr.DeviceRegistry | ||
) -> None: | ||
"""Test already configured while creating entry.""" | ||
config_entry = MockConfigEntry( | ||
domain=DOMAIN, unique_id=CONFIG[DEVICE_ID], data=CONFIG | ||
) | ||
config_entry.add_to_hass(hass) | ||
|
||
device_id = device_registry.async_get_or_create( | ||
config_entry_id=config_entry.entry_id, | ||
identifiers={(DOMAIN, CONFIG[DEVICE_ID])}, | ||
configuration_url="https://www.wolf-smartset.com/", | ||
manufacturer=MANUFACTURER, | ||
).id | ||
|
||
assert config_entry.version == 1 | ||
assert config_entry.minor_version == 1 | ||
assert config_entry.unique_id == 1234 | ||
assert ( | ||
hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, 1234) | ||
is config_entry | ||
) | ||
assert hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, "1234") is None | ||
assert device_registry.async_get(device_id).identifiers == {(DOMAIN, 1234)} | ||
|
||
with ( | ||
patch( | ||
"homeassistant.components.wolflink.fetch_parameters", | ||
side_effect=RequestError("Unable to fetch parameters"), | ||
), | ||
): | ||
await hass.config_entries.async_setup(config_entry.entry_id) | ||
|
||
assert config_entry.version == 1 | ||
assert config_entry.minor_version == 2 | ||
assert config_entry.unique_id == "1234" | ||
assert ( | ||
hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, "1234") | ||
is config_entry | ||
) | ||
assert hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, 1234) is None | ||
|
||
assert device_registry.async_get(device_id).identifiers == {(DOMAIN, "1234")} |