From c311e480fd370df93a926b1a385a801167b17b7b Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Wed, 5 Jun 2019 17:13:40 +0200 Subject: [PATCH] Don't let zeroconf be smart with addresses (#24321) --- homeassistant/components/zeroconf/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index bdb1d52159c..289aba6ef56 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -3,12 +3,14 @@ # https://github.com/PyCQA/pylint/issues/1931 # pylint: disable=no-name-in-module import logging +import socket import ipaddress import voluptuous as vol from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf +from homeassistant import util from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) from homeassistant.generated.zeroconf import ZEROCONF, HOMEKIT @@ -42,8 +44,16 @@ def setup(hass, config): 'requires_api_password': True, } - info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, - port=hass.http.server_port, properties=params) + host_ip = util.get_local_ip() + + try: + host_ip_pton = socket.inet_pton(socket.AF_INET, host_ip) + except socket.error: + host_ip_pton = socket.inet_pton(socket.AF_INET6, host_ip) + + info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, None, + addresses=[host_ip_pton], port=hass.http.server_port, + properties=params) zeroconf = Zeroconf()