Revert Zeroconf back to previously used library (#24139)

* Revert back to previously used library

* Fix test

* Remove unused import

* Fix import

* Update __init__.py

* Update __init__.py

* Fix test after rebase
This commit is contained in:
Robert Svensson authored and Paulus Schoutsen committed 2019-05-29 14:20:06 -07:00
1 parent 42ee8eef50
commit 84baaa324c
9 files changed
+42 -43

No files matched your search

+24 -24
View File
@@ -1,14 +1,16 @@
"""Support for exposing Home Assistant via Zeroconf."""
# PyLint bug confuses absolute/relative imports
# https://github.com/PyCQA/pylint/issues/1931
# pylint: disable=no-name-in-module
import logging
import ipaddress
import voluptuous as vol
from aiozeroconf import (
ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf)
from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
from homeassistant.generated import zeroconf as zeroconf_manifest
from homeassistant.generated.zeroconf import ZEROCONF
_LOGGER = logging.getLogger(__name__)
@@ -28,7 +30,7 @@ CONFIG_SCHEMA = vol.Schema({
}, extra=vol.ALLOW_EXTRA)
async def async_setup(hass, config):
def setup(hass, config):
"""Set up Zeroconf and make Home Assistant discoverable."""
zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
@@ -42,35 +44,33 @@ async def async_setup(hass, config):
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
port=hass.http.server_port, properties=params)
zeroconf = Zeroconf(hass.loop)
zeroconf = Zeroconf()
await zeroconf.register_service(info)
zeroconf.register_service(info)
async def new_service(service_type, name):
"""Signal new service discovered."""
service_info = await zeroconf.get_service_info(service_type, name)
info = info_from_service(service_info)
_LOGGER.debug("Discovered new device %s %s", name, info)
for domain in zeroconf_manifest.SERVICE_TYPES[service_type]:
await hass.config_entries.flow.async_init(
domain, context={'source': DOMAIN}, data=info
)
def service_update(_, service_type, name, state_change):
def service_update(zeroconf, service_type, name, state_change):
"""Service state changed."""
if state_change is ServiceStateChange.Added:
hass.async_create_task(new_service(service_type, name))
service_info = zeroconf.get_service_info(service_type, name)
info = info_from_service(service_info)
_LOGGER.debug("Discovered new device %s %s", name, info)
for service in zeroconf_manifest.SERVICE_TYPES:
for domain in ZEROCONF[service_type]:
hass.add_job(
hass.config_entries.flow.async_init(
domain, context={'source': DOMAIN}, data=info
)
)
for service in ZEROCONF:
ServiceBrowser(zeroconf, service, handlers=[service_update])
async def stop_zeroconf(_):
def stop_zeroconf(_):
"""Stop Zeroconf."""
await zeroconf.unregister_service(info)
await zeroconf.close()
zeroconf.unregister_service(info)
zeroconf.close()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
return True