From 2f5d7d4522474e45dce4fac4b24c9cbd415009c0 Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Thu, 16 May 2019 12:04:20 -0700 Subject: [PATCH] [WIP] Simplify zeroconf (#23890) * Simplify zeroconf * Remove unused imports --- homeassistant/components/zeroconf/__init__.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index a14efb70411..e745cb53f6b 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -1,10 +1,8 @@ """Support for exposing Home Assistant via Zeroconf.""" import logging -import socket import voluptuous as vol -from homeassistant import util from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) _LOGGER = logging.getLogger(__name__) @@ -23,8 +21,6 @@ async def async_setup(hass, config): """Set up Zeroconf and make Home Assistant discoverable.""" from aiozeroconf import Zeroconf, ServiceInfo - zeroconf = Zeroconf(hass.loop) - zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE) params = { @@ -34,18 +30,10 @@ async def async_setup(hass, config): 'requires_api_password': True, } - host_ip = util.get_local_ip() + info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, + port=hass.http.server_port, properties=params) - try: - host_ip_pton = socket.inet_pton(socket.AF_INET, host_ip) - info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, address=host_ip_pton, - port=hass.http.server_port, weight=0, priority=0, - properties=params) - except socket.error: - host_ip_pton = socket.inet_pton(socket.AF_INET6, host_ip) - info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, address6=host_ip_pton, - port=hass.http.server_port, weight=0, priority=0, - properties=params) + zeroconf = Zeroconf(hass.loop) await zeroconf.register_service(info)