mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix Konnected multiple discovery of panels (#59953)
* Konnected - Fix multiple discovery of panels. This resolves an issue which creates multiple discoveries of a Konnected panel if it is restarted and fails to connect to home assistant. See #57467. * Revert changes to user step, add handling to ssdp step. * Add abort reason string to strings.json * Abort ssdp discovery if device is already known. * Add test for multiple discovery fix. * Remove unrelated file change. * Add ssdp discovery abort tests. * Add missing abort reason check. * Add "already_configured" to strings. * Use "cannot_connect" abort reason.
This commit is contained in:
@@ -109,6 +109,7 @@ async def test_ssdp(hass, mock_panel):
|
||||
"model": "Konnected",
|
||||
}
|
||||
|
||||
# Test success
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
@@ -128,6 +129,82 @@ async def test_ssdp(hass, mock_panel):
|
||||
"port": 1234,
|
||||
}
|
||||
|
||||
# Test abort if connection failed
|
||||
mock_panel.get_status.side_effect = config_flow.CannotConnect
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"ssdp_location": "http://1.2.3.4:1234/Device.xml",
|
||||
"manufacturer": config_flow.KONN_MANUFACTURER,
|
||||
"modelName": config_flow.KONN_MODEL,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
# Test abort if invalid data
|
||||
mock_panel.get_status.side_effect = KeyError
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"ssdp_location": "http://1.2.3.4:1234/Device.xml",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
# Test abort if invalid manufacturer
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"ssdp_location": "http://1.2.3.4:1234/Device.xml",
|
||||
"manufacturer": "SHOULD_FAIL",
|
||||
"modelName": config_flow.KONN_MODEL,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_konn_panel"
|
||||
|
||||
# Test abort if invalid model
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"ssdp_location": "http://1.2.3.4:1234/Device.xml",
|
||||
"manufacturer": config_flow.KONN_MANUFACTURER,
|
||||
"modelName": "SHOULD_FAIL",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "not_konn_panel"
|
||||
|
||||
# Test abort if already configured
|
||||
config_entry = MockConfigEntry(
|
||||
domain=config_flow.DOMAIN,
|
||||
data={config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_PORT: 1234},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_SSDP},
|
||||
data={
|
||||
"ssdp_location": "http://1.2.3.4:1234/Device.xml",
|
||||
"manufacturer": config_flow.KONN_MANUFACTURER,
|
||||
"modelName": config_flow.KONN_MODEL,
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_import_no_host_user_finish(hass, mock_panel):
|
||||
"""Test importing a panel with no host info."""
|
||||
|
||||
Reference in New Issue
Block a user