Use chip id in Konnected pro boards (#36940)

* use chip id in pro boards

* cleaner failover
pull/36948/head
Kit Klein 2020-06-20 02:39:04 -04:00 committed by GitHub
parent 2fd6431cff
commit a074cf4afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -185,7 +185,7 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.data[CONF_PORT] = port
try:
status = await get_status(self.hass, host, port)
self.data[CONF_ID] = status["mac"].replace(":", "")
self.data[CONF_ID] = status.get("chipId", status["mac"].replace(":", ""))
except (CannotConnect, KeyError):
raise CannotConnect
else:
@ -293,7 +293,9 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except CannotConnect:
errors["base"] = "cannot_connect"
else:
self.data[CONF_ID] = status["mac"].replace(":", "")
self.data[CONF_ID] = status.get(
"chipId", status["mac"].replace(":", "")
)
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
# save off our discovered host info

View File

@ -76,7 +76,7 @@ class AlarmPanel:
@property
def device_id(self):
"""Device id is the MAC address as string with punctuation removed."""
"""Device id is the chipId (pro) or MAC address as string with punctuation removed."""
return self.config.get(CONF_ID)
@property

View File

@ -69,7 +69,9 @@ async def test_pro_flow_works(hass, mock_panel):
assert result["type"] == "form"
assert result["step_id"] == "user"
# pro uses chipId instead of MAC as unique id
mock_panel.get_status.return_value = {
"chipId": "1234567",
"mac": "11:22:33:44:55:66",
"model": "Konnected Pro",
}
@ -80,7 +82,7 @@ async def test_pro_flow_works(hass, mock_panel):
assert result["step_id"] == "confirm"
assert result["description_placeholders"] == {
"model": "Konnected Alarm Panel Pro",
"id": "112233445566",
"id": "1234567",
"host": "1.2.3.4",
"port": 1234,
}
@ -192,8 +194,9 @@ async def test_import_no_host_user_finish(hass, mock_panel):
async def test_import_ssdp_host_user_finish(hass, mock_panel):
"""Test importing a panel with no host info which ssdp discovers."""
"""Test importing a pro panel with no host info which ssdp discovers."""
mock_panel.get_status.return_value = {
"chipId": "somechipid",
"mac": "11:22:33:44:55:66",
"model": "Konnected Pro",
}
@ -224,12 +227,12 @@ async def test_import_ssdp_host_user_finish(hass, mock_panel):
"out1": "Disabled",
},
},
"id": "112233445566",
"id": "somechipid",
},
)
assert result["type"] == "form"
assert result["step_id"] == "import_confirm"
assert result["description_placeholders"]["id"] == "112233445566"
assert result["description_placeholders"]["id"] == "somechipid"
# discover the panel via ssdp
ssdp_result = await hass.config_entries.flow.async_init(
@ -251,7 +254,7 @@ async def test_import_ssdp_host_user_finish(hass, mock_panel):
assert result["step_id"] == "confirm"
assert result["description_placeholders"] == {
"model": "Konnected Alarm Panel Pro",
"id": "112233445566",
"id": "somechipid",
"host": "0.0.0.0",
"port": 1234,
}