Don't let zeroconf be smart with addresses (#24321)

pull/24322/head
Robert Svensson 2019-06-05 17:13:40 +02:00 committed by Paulus Schoutsen
parent 4c6ddd435c
commit c311e480fd
1 changed files with 12 additions and 2 deletions

View File

@ -3,12 +3,14 @@
# https://github.com/PyCQA/pylint/issues/1931 # https://github.com/PyCQA/pylint/issues/1931
# pylint: disable=no-name-in-module # pylint: disable=no-name-in-module
import logging import logging
import socket
import ipaddress import ipaddress
import voluptuous as vol import voluptuous as vol
from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf
from homeassistant import util
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
from homeassistant.generated.zeroconf import ZEROCONF, HOMEKIT from homeassistant.generated.zeroconf import ZEROCONF, HOMEKIT
@ -42,8 +44,16 @@ def setup(hass, config):
'requires_api_password': True, 'requires_api_password': True,
} }
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, host_ip = util.get_local_ip()
port=hass.http.server_port, properties=params)
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() zeroconf = Zeroconf()