mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
[WIP] Simplify zeroconf (#23890)
* Simplify zeroconf * Remove unused imports
This commit is contained in:
parent
7716e8fb68
commit
2f5d7d4522
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user