Allow dns hostnames to be retained for SMLIGHT user flow. (#142514)

* Dont overwrite host with local IP

* adjust test for user flow change
This commit is contained in:
TimL 2025-05-10 02:31:00 +10:00 committed by GitHub
parent 9537229c92
commit ad6f66c945
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 7 deletions

View File

@ -53,7 +53,6 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
try:
if not await self._async_check_auth_required(user_input):
info = await self.client.get_info()
self._host = str(info.device_ip)
self._device_name = str(info.hostname)
if info.model not in Devices:
@ -79,7 +78,6 @@ class SmlightConfigFlow(ConfigFlow, domain=DOMAIN):
try:
if not await self._async_check_auth_required(user_input):
info = await self.client.get_info()
self._host = str(info.device_ip)
self._device_name = str(info.hostname)
if info.model not in Devices:

View File

@ -21,6 +21,7 @@ from tests.common import (
MOCK_DEVICE_NAME = "slzb-06"
MOCK_HOST = "192.168.1.161"
MOCK_HOSTNAME = "slzb-06p7.lan"
MOCK_USERNAME = "test-user"
MOCK_PASSWORD = "test-pass"

View File

@ -15,7 +15,13 @@ from homeassistant.data_entry_flow import FlowResultType
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from .conftest import MOCK_DEVICE_NAME, MOCK_HOST, MOCK_PASSWORD, MOCK_USERNAME
from .conftest import (
MOCK_DEVICE_NAME,
MOCK_HOST,
MOCK_HOSTNAME,
MOCK_PASSWORD,
MOCK_USERNAME,
)
from tests.common import MockConfigEntry
@ -53,14 +59,14 @@ async def test_user_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_HOST: "slzb-06p7.local",
CONF_HOST: MOCK_HOSTNAME,
},
)
assert result2["type"] is FlowResultType.CREATE_ENTRY
assert result2["title"] == "SLZB-06p7"
assert result2["data"] == {
CONF_HOST: MOCK_HOST,
CONF_HOST: MOCK_HOSTNAME,
}
assert result2["context"]["unique_id"] == "aa:bb:cc:dd:ee:ff"
assert len(mock_setup_entry.mock_calls) == 1
@ -82,7 +88,7 @@ async def test_user_flow_auth(
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_HOST: "slzb-06p7.local",
CONF_HOST: MOCK_HOSTNAME,
},
)
assert result2["type"] is FlowResultType.FORM
@ -100,7 +106,7 @@ async def test_user_flow_auth(
assert result3["data"] == {
CONF_USERNAME: MOCK_USERNAME,
CONF_PASSWORD: MOCK_PASSWORD,
CONF_HOST: MOCK_HOST,
CONF_HOST: MOCK_HOSTNAME,
}
assert result3["context"]["unique_id"] == "aa:bb:cc:dd:ee:ff"
assert len(mock_setup_entry.mock_calls) == 1