Fix serialization of Xiaomi BLE reauth flow (#76095)

* Use data instead of context to fix serialisation bug

* Test change to async_start_reauth
This commit is contained in:
Jc2k 2022-08-02 21:38:38 +01:00 committed by GitHub
parent a628be4db8
commit a0adfb9e62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 8 deletions

View file

@ -260,7 +260,7 @@ class XiaomiConfigFlow(ConfigFlow, domain=DOMAIN):
entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
assert entry is not None
device: DeviceData = self.context["device"]
device: DeviceData = entry_data["device"]
self._discovered_device = device
self._discovery_info = device.last_service_info

View file

@ -181,7 +181,7 @@ def process_service_info(
and data.encryption_scheme != EncryptionScheme.NONE
and not data.bindkey_verified
):
entry.async_start_reauth(hass, context={"device": data})
entry.async_start_reauth(hass, data={"device": data})
return sensor_update_to_bluetooth_data_update(update)

View file

@ -641,7 +641,10 @@ class ConfigEntry:
@callback
def async_start_reauth(
self, hass: HomeAssistant, context: dict[str, Any] | None = None
self,
hass: HomeAssistant,
context: dict[str, Any] | None = None,
data: dict[str, Any] | None = None,
) -> None:
"""Start a reauth flow."""
flow_context = {
@ -662,7 +665,7 @@ class ConfigEntry:
hass.config_entries.flow.async_init(
self.domain,
context=flow_context,
data=self.data,
data=self.data | (data or {}),
)
)

View file

@ -1033,9 +1033,8 @@ async def test_async_step_reauth_abort_early(hass):
"entry_id": entry.entry_id,
"title_placeholders": {"name": entry.title},
"unique_id": entry.unique_id,
"device": device,
},
data=entry.data,
data=entry.data | {"device": device},
)
assert result["type"] == FlowResultType.ABORT

View file

@ -3286,8 +3286,14 @@ async def test_reauth(hass):
await entry.async_setup(hass)
await hass.async_block_till_done()
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
await hass.async_block_till_done()
flow = hass.config_entries.flow
with patch.object(flow, "async_init", wraps=flow.async_init) as mock_init:
entry.async_start_reauth(
hass,
context={"extra_context": "some_extra_context"},
data={"extra_data": 1234},
)
await hass.async_block_till_done()
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
@ -3296,6 +3302,8 @@ async def test_reauth(hass):
assert flows[0]["context"]["title_placeholders"] == {"name": "test_title"}
assert flows[0]["context"]["extra_context"] == "some_extra_context"
assert mock_init.call_args.kwargs["data"]["extra_data"] == 1234
# Check we can't start duplicate flows
entry.async_start_reauth(hass, {"extra_context": "some_extra_context"})
await hass.async_block_till_done()