Avoid probing brother devices that have an existing config entry (#57829)
parent
bdf96943ae
commit
0dcb8ca270
|
@ -86,6 +86,9 @@ class BrotherConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# Hostname is format: brother.local.
|
||||
self.host = discovery_info["hostname"].rstrip(".")
|
||||
|
||||
# Do not probe the device if the host is already configured
|
||||
self._async_abort_entries_match({CONF_HOST: self.host})
|
||||
|
||||
snmp_engine = get_snmp_engine(self.hass)
|
||||
|
||||
self.brother = Brother(self.host, snmp_engine=snmp_engine)
|
||||
|
|
|
@ -170,6 +170,23 @@ async def test_zeroconf_device_exists_abort(hass):
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_zeroconf_no_probe_existing_device(hass):
|
||||
"""Test we do not probe the device is the host is already configured."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id="0123456789", data=CONFIG)
|
||||
entry.add_to_hass(hass)
|
||||
with patch("brother.Brother._get_data") as mock_get_data:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_ZEROCONF},
|
||||
data={"hostname": "localhost", "name": "Brother Printer"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
assert len(mock_get_data.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_zeroconf_confirm_create_entry(hass):
|
||||
"""Test zeroconf confirmation and create config entry."""
|
||||
with patch(
|
||||
|
|
Loading…
Reference in New Issue