Use smlight discovery hostname as device name (#125359)

* Use smlight discovery hostname as device name

* Update reauth flow name

* Drop host from description
pull/125419/head
Shay Levy 2024-09-06 12:49:10 +03:00 committed by GitHub
parent ccbc300b68
commit ff20131af1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 10 deletions

View File

@ -139,10 +139,6 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
self.context["entry_id"]
)
host = entry_data[CONF_HOST]
self.context["title_placeholders"] = {
"host": host,
"name": entry_data.get(CONF_USERNAME, "unknown"),
}
self.client = Api2(host, session=async_get_clientsession(self.hass))
self.host = host
@ -166,7 +162,8 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
assert self._reauth_entry is not None
return self.async_update_reload_and_abort(
self._reauth_entry, data={**user_input, CONF_HOST: self.host}
self._reauth_entry,
data={**self._reauth_entry.data, **user_input},
)
return self.async_show_form(
@ -197,4 +194,5 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
user_input[CONF_HOST] = self.host
assert info.model is not None
return self.async_create_entry(title=info.model, data=user_input)
title = self.context.get("title_placeholders", {}).get(CONF_NAME) or info.model
return self.async_create_entry(title=title, data=user_input)

View File

@ -19,7 +19,7 @@
},
"reauth_confirm": {
"title": "[%key:common::config_flow::title::reauth%]",
"description": "Please enter the correct username and password for host: {host}",
"description": "Please enter the correct username and password",
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"

View File

@ -91,7 +91,7 @@ async def test_zeroconf_flow(
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["context"]["source"] == "zeroconf"
assert result2["context"]["unique_id"] == "aa:bb:cc:dd:ee:ff"
assert result2["title"] == "SLZB-06p7"
assert result2["title"] == "slzb-06"
assert result2["data"] == {
CONF_HOST: MOCK_HOST,
}
@ -143,7 +143,7 @@ async def test_zeroconf_flow_auth(
assert result3["type"] is FlowResultType.CREATE_ENTRY
assert result3["context"]["source"] == "zeroconf"
assert result3["context"]["unique_id"] == "aa:bb:cc:dd:ee:ff"
assert result3["title"] == "SLZB-06p7"
assert result3["title"] == "slzb-06"
assert result3["data"] == {
CONF_USERNAME: MOCK_USERNAME,
CONF_PASSWORD: MOCK_PASSWORD,
@ -356,7 +356,7 @@ async def test_zeroconf_legacy_mac(
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["context"]["source"] == "zeroconf"
assert result2["context"]["unique_id"] == "aa:bb:cc:dd:ee:ff"
assert result2["title"] == "SLZB-06p7"
assert result2["title"] == "slzb-06"
assert result2["data"] == {
CONF_HOST: MOCK_HOST,
}