From ee92d64088c4f51ff6ddf4c3059216954560b5aa Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 20 May 2020 08:37:32 +0200 Subject: [PATCH] Add UUID to ZeroConf service info (#35623) --- homeassistant/components/zeroconf/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index d699160eed4..6c7e0ff8103 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -1,4 +1,5 @@ """Support for exposing Home Assistant via Zeroconf.""" +import asyncio import ipaddress import logging import socket @@ -116,9 +117,15 @@ def setup(hass, config): zeroconf = hass.data[DOMAIN] = _get_instance( hass, config.get(DOMAIN, {}).get(CONF_DEFAULT_INTERFACE) ) - zeroconf_name = f"{hass.config.location_name}.{ZEROCONF_TYPE}" + + # Get instance UUID + uuid = asyncio.run_coroutine_threadsafe( + hass.helpers.instance_id.async_get(), hass.loop + ).result() params = { + "location_name": hass.config.location_name, + "uuid": uuid, "version": __version__, "external_url": None, "internal_url": None, @@ -128,6 +135,7 @@ def setup(hass, config): "requires_api_password": True, } + # Get instance URL's try: params["external_url"] = get_url(hass, allow_internal=False) except NoURLAvailableError: @@ -150,8 +158,8 @@ def setup(hass, config): info = ServiceInfo( ZEROCONF_TYPE, - zeroconf_name, - None, + name=f"{hass.config.location_name}.{ZEROCONF_TYPE}", + server=f"{uuid}.local.", addresses=[host_ip_pton], port=hass.http.server_port, properties=params,