From d88047a75078cf1e4001e70262fb0672f74c6ea8 Mon Sep 17 00:00:00 2001 From: cdutr Date: Fri, 12 Dec 2025 09:49:19 -0300 Subject: [PATCH] Migrate Blink component to use hardware_id instead of device_id (#158765) --- homeassistant/components/blink/__init__.py | 6 ++++ homeassistant/components/blink/config_flow.py | 6 ++-- homeassistant/components/blink/const.py | 2 +- tests/components/blink/conftest.py | 4 +-- .../blink/snapshots/test_diagnostics.ambr | 4 +-- tests/components/blink/test_init.py | 29 +++++++++++++++++++ 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/blink/__init__.py b/homeassistant/components/blink/__init__.py index f903065a124..3519766e0bf 100644 --- a/homeassistant/components/blink/__init__.py +++ b/homeassistant/components/blink/__init__.py @@ -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 diff --git a/homeassistant/components/blink/config_flow.py b/homeassistant/components/blink/config_flow.py index f4d393ed8b5..896226327af 100644 --- a/homeassistant/components/blink/config_flow.py +++ b/homeassistant/components/blink/config_flow.py @@ -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), ) diff --git a/homeassistant/components/blink/const.py b/homeassistant/components/blink/const.py index 3e4ffeeea07..e57a05822e4 100644 --- a/homeassistant/components/blink/const.py +++ b/homeassistant/components/blink/const.py @@ -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" diff --git a/tests/components/blink/conftest.py b/tests/components/blink/conftest.py index 7c46d13437b..1a7f4f6f2cd 100644 --- a/tests/components/blink/conftest.py +++ b/tests/components/blink/conftest.py @@ -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, ) diff --git a/tests/components/blink/snapshots/test_diagnostics.ambr b/tests/components/blink/snapshots/test_diagnostics.ambr index 54df2b48cdb..bf2d38ac473 100644 --- a/tests/components/blink/snapshots/test_diagnostics.ambr +++ b/tests/components/blink/snapshots/test_diagnostics.ambr @@ -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, }), }) # --- diff --git a/tests/components/blink/test_init.py b/tests/components/blink/test_init.py index a4629a9b461..5c30e575b5e 100644 --- a/tests/components/blink/test_init.py +++ b/tests/components/blink/test_init.py @@ -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"