[WIP] Simplify zeroconf (#23890)

* Simplify zeroconf

* Remove unused imports
This commit is contained in:
Robbie Trencheny 2019-05-16 12:04:20 -07:00 committed by GitHub
parent 7716e8fb68
commit 2f5d7d4522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,8 @@
"""Support for exposing Home Assistant via Zeroconf.""" """Support for exposing Home Assistant via Zeroconf."""
import logging import logging
import socket
import voluptuous as vol import voluptuous as vol
from homeassistant import util
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__) from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -23,8 +21,6 @@ async def async_setup(hass, config):
"""Set up Zeroconf and make Home Assistant discoverable.""" """Set up Zeroconf and make Home Assistant discoverable."""
from aiozeroconf import Zeroconf, ServiceInfo from aiozeroconf import Zeroconf, ServiceInfo
zeroconf = Zeroconf(hass.loop)
zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE) zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
params = { params = {
@ -34,18 +30,10 @@ async def async_setup(hass, config):
'requires_api_password': True, 'requires_api_password': True,
} }
host_ip = util.get_local_ip() info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
port=hass.http.server_port, properties=params)
try: zeroconf = Zeroconf(hass.loop)
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)
await zeroconf.register_service(info) await zeroconf.register_service(info)