Fix zeroconf when location name has a period (#81022)
parent
8645e47b07
commit
a72e906ac1
|
@ -234,12 +234,20 @@ def _get_announced_addresses(
|
|||
return address_list
|
||||
|
||||
|
||||
def _filter_disallowed_characters(name: str) -> str:
|
||||
"""Filter disallowed characters from a string.
|
||||
|
||||
. is a reversed character for zeroconf.
|
||||
"""
|
||||
return name.replace(".", " ")
|
||||
|
||||
|
||||
async def _async_register_hass_zc_service(
|
||||
hass: HomeAssistant, aio_zc: HaAsyncZeroconf, uuid: str
|
||||
) -> None:
|
||||
# Get instance UUID
|
||||
valid_location_name = _truncate_location_name_to_valid(
|
||||
hass.config.location_name or "Home"
|
||||
_filter_disallowed_characters(hass.config.location_name or "Home")
|
||||
)
|
||||
|
||||
params = {
|
||||
|
|
|
@ -1162,6 +1162,25 @@ async def test_no_name(hass, mock_async_zeroconf):
|
|||
assert info.name == "Home._home-assistant._tcp.local."
|
||||
|
||||
|
||||
async def test_setup_with_disallowed_characters_in_local_name(
|
||||
hass, mock_async_zeroconf, caplog
|
||||
):
|
||||
"""Test we still setup with disallowed characters in the location name."""
|
||||
with patch.object(hass.config_entries.flow, "async_init"), patch.object(
|
||||
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
|
||||
), patch.object(
|
||||
hass.config,
|
||||
"location_name",
|
||||
"My.House",
|
||||
):
|
||||
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
calls = mock_async_zeroconf.async_register_service.mock_calls
|
||||
assert calls[0][1][0].name == "My House._home-assistant._tcp.local."
|
||||
|
||||
|
||||
async def test_start_with_frontend(hass, mock_async_zeroconf):
|
||||
"""Test we start with the frontend."""
|
||||
with patch("homeassistant.components.zeroconf.HaZeroconf"):
|
||||
|
|
Loading…
Reference in New Issue