mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix reconfigure flow for lamarzocco (#143152)
This commit is contained in:
parent
c34e280fc2
commit
44450f9d7d
@ -49,6 +49,7 @@ from .const import CONF_USE_BLUETOOTH, DOMAIN
|
||||
from .coordinator import LaMarzoccoConfigEntry
|
||||
|
||||
CONF_MACHINE = "machine"
|
||||
BT_MODEL_PREFIXES = ("MICRA", "MINI", "GS3")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -105,7 +106,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
self._config = data
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reauth_entry(), data=data
|
||||
self._get_reauth_entry(), data_updates=data
|
||||
)
|
||||
if self._discovered:
|
||||
if self._discovered[CONF_MACHINE] not in self._things:
|
||||
@ -169,10 +170,15 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if not errors:
|
||||
if self.source == SOURCE_RECONFIGURE:
|
||||
for service_info in async_discovered_service_info(self.hass):
|
||||
self._discovered[service_info.name] = service_info.address
|
||||
if service_info.name.startswith(BT_MODEL_PREFIXES):
|
||||
self._discovered[service_info.name] = service_info.address
|
||||
|
||||
if self._discovered:
|
||||
return await self.async_step_bluetooth_selection()
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reconfigure_entry(),
|
||||
data_updates=self._config,
|
||||
)
|
||||
|
||||
return self.async_create_entry(
|
||||
title=selected_device.name,
|
||||
@ -217,8 +223,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
return self.async_update_reload_and_abort(
|
||||
self._get_reconfigure_entry(),
|
||||
data={
|
||||
**self._config,
|
||||
data_updates={
|
||||
CONF_MAC: user_input[CONF_MAC],
|
||||
},
|
||||
)
|
||||
|
@ -20,6 +20,7 @@ from homeassistant.config_entries import (
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_MAC, CONF_PASSWORD, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
|
||||
|
||||
from . import USER_INPUT, async_init_integration, get_bluetooth_service_info
|
||||
@ -259,6 +260,61 @@ async def test_reconfigure_flow(
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"discovered",
|
||||
[
|
||||
[],
|
||||
[
|
||||
BluetoothServiceInfo(
|
||||
name="SomeDevice",
|
||||
address="aa:bb:cc:dd:ee:ff",
|
||||
rssi=-63,
|
||||
manufacturer_data={},
|
||||
service_data={},
|
||||
service_uuids=[],
|
||||
source="local",
|
||||
)
|
||||
],
|
||||
],
|
||||
)
|
||||
async def test_reconfigure_flow_no_machines(
|
||||
hass: HomeAssistant,
|
||||
mock_cloud_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
discovered: list[BluetoothServiceInfo],
|
||||
) -> None:
|
||||
"""Testing reconfgure flow."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
data = deepcopy(dict(mock_config_entry.data))
|
||||
result = await mock_config_entry.start_reconfigure_flow(hass)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "reconfigure"
|
||||
|
||||
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.lamarzocco.config_flow.async_discovered_service_info",
|
||||
return_value=discovered,
|
||||
),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
CONF_MACHINE: "GS012345",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
assert mock_config_entry.title == "My LaMarzocco"
|
||||
assert CONF_MAC not in mock_config_entry.data
|
||||
assert dict(mock_config_entry.data) == data
|
||||
|
||||
|
||||
async def test_bluetooth_discovery(
|
||||
hass: HomeAssistant,
|
||||
mock_lamarzocco: MagicMock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user