Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use smlight discovery hostname as device name #125359

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions homeassistant/components/smlight/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ async def async_step_reauth(
self.context["entry_id"]
)
host = entry_data[CONF_HOST]
self.context["title_placeholders"] = {
"host": host,
thecode marked this conversation as resolved.
Show resolved Hide resolved
"name": entry_data.get(CONF_USERNAME, "unknown"),
}
self.client = Api2(host, session=async_get_clientsession(self.hass))
self.host = host

Expand All @@ -166,7 +162,8 @@ async def async_step_reauth_confirm(
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(
Expand Down Expand Up @@ -197,4 +194,5 @@ async def _async_complete_entry(
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)
2 changes: 1 addition & 1 deletion homeassistant/components/smlight/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%]"
Expand Down
6 changes: 3 additions & 3 deletions tests/components/smlight/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down