mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Migrate Blink component to use hardware_id instead of device_id (#158765)
This commit is contained in:
@@ -64,6 +64,12 @@ async def async_migrate_entry(hass: HomeAssistant, entry: BlinkConfigEntry) -> b
|
||||
if entry.version == 2:
|
||||
await _reauth_flow_wrapper(hass, entry, data)
|
||||
return False
|
||||
if entry.version == 3:
|
||||
# Migrate device_id to hardware_id for blinkpy 0.25.x OAuth2 compatibility
|
||||
if "device_id" in data:
|
||||
data["hardware_id"] = data.pop("device_id")
|
||||
hass.config_entries.async_update_entry(entry, data=data, version=4)
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DEVICE_ID, DOMAIN
|
||||
from .const import DOMAIN, HARDWARE_ID
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -43,7 +43,7 @@ async def _send_blink_2fa_pin(blink: Blink, pin: str | None) -> bool:
|
||||
class BlinkConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Blink config flow."""
|
||||
|
||||
VERSION = 3
|
||||
VERSION = 4
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the blink flow."""
|
||||
@@ -53,7 +53,7 @@ class BlinkConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
async def _handle_user_input(self, user_input: dict[str, Any]):
|
||||
"""Handle user input."""
|
||||
self.auth = Auth(
|
||||
{**user_input, "device_id": DEVICE_ID},
|
||||
{**user_input, "hardware_id": HARDWARE_ID},
|
||||
no_prompt=True,
|
||||
session=async_get_clientsession(self.hass),
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from homeassistant.const import Platform
|
||||
|
||||
DOMAIN = "blink"
|
||||
DEVICE_ID = "Home Assistant"
|
||||
HARDWARE_ID = "Home Assistant"
|
||||
|
||||
CONF_MIGRATE = "migrate"
|
||||
CONF_CAMERA = "camera"
|
||||
|
||||
@@ -85,7 +85,7 @@ def mock_config_fixture():
|
||||
data={
|
||||
CONF_USERNAME: "test_user",
|
||||
CONF_PASSWORD: "Password",
|
||||
"device_id": "Home Assistant",
|
||||
"hardware_id": "Home Assistant",
|
||||
"uid": "BlinkCamera_e1233333e2-0909-09cd-777a-123456789012",
|
||||
"token": "A_token",
|
||||
"unique_id": "an_email@email.com",
|
||||
@@ -95,5 +95,5 @@ def mock_config_fixture():
|
||||
"account_id": 654321,
|
||||
},
|
||||
entry_id=str(uuid4()),
|
||||
version=3,
|
||||
version=4,
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
'data': dict({
|
||||
'account_id': 654321,
|
||||
'client_id': 123456,
|
||||
'device_id': 'Home Assistant',
|
||||
'hardware_id': 'Home Assistant',
|
||||
'host': 'u034.immedia-semi.com',
|
||||
'password': '**REDACTED**',
|
||||
'region_id': 'u034',
|
||||
@@ -52,7 +52,7 @@
|
||||
]),
|
||||
'title': 'Mock Title',
|
||||
'unique_id': None,
|
||||
'version': 3,
|
||||
'version': 4,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -113,3 +113,32 @@ async def test_migrate(
|
||||
await hass.async_block_till_done()
|
||||
entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.MIGRATION_ERROR
|
||||
|
||||
|
||||
async def test_migrate_v3_to_v4(
|
||||
hass: HomeAssistant,
|
||||
mock_blink_api: MagicMock,
|
||||
mock_blink_auth_api: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test migration from version 3 to 4 (device_id to hardware_id)."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
# Set up v3 config entry with device_id
|
||||
data = {**mock_config_entry.data}
|
||||
data.pop("hardware_id", None)
|
||||
data["device_id"] = "Home Assistant"
|
||||
hass.config_entries.async_update_entry(
|
||||
mock_config_entry,
|
||||
version=3,
|
||||
data=data,
|
||||
)
|
||||
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
entry = hass.config_entries.async_get_entry(mock_config_entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert entry.version == 4
|
||||
assert "hardware_id" in entry.data
|
||||
assert "device_id" not in entry.data
|
||||
assert entry.data["hardware_id"] == "Home Assistant"
|
||||
|
||||
Reference in New Issue
Block a user