From f1d4a3cd6ef68257b8b3e605baff631e13fd01c6 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 23 Nov 2019 16:46:06 +0100 Subject: [PATCH] Catch Zeroconf exception (#28728) * Catch Zeroconf exception * Make it an error --- homeassistant/components/zeroconf/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index 2f9fb7b4580..41a6c7510f9 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -8,7 +8,13 @@ import socket import ipaddress import voluptuous as vol -from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf +from zeroconf import ( + ServiceBrowser, + ServiceInfo, + ServiceStateChange, + Zeroconf, + NonUniqueNameException, +) from homeassistant import util from homeassistant.const import ( @@ -43,7 +49,7 @@ def setup(hass, config): params = { "version": __version__, "base_url": hass.config.api.base_url, - # always needs authentication + # Always needs authentication "requires_api_password": True, } @@ -69,7 +75,12 @@ def setup(hass, config): Wait till started or otherwise HTTP is not up and running. """ _LOGGER.info("Starting Zeroconf broadcast") - zeroconf.register_service(info) + try: + zeroconf.register_service(info) + except NonUniqueNameException: + _LOGGER.error( + "Home Assistant instance with identical name present in the local network" + ) hass.bus.listen_once(EVENT_HOMEASSISTANT_START, zeroconf_hass_start)