diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index d2dcd907885..a14efb70411 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -19,11 +19,11 @@ CONFIG_SCHEMA = vol.Schema({ }, extra=vol.ALLOW_EXTRA) -def setup(hass, config): +async def async_setup(hass, config): """Set up Zeroconf and make Home Assistant discoverable.""" - from zeroconf import Zeroconf, ServiceInfo + from aiozeroconf import Zeroconf, ServiceInfo - zeroconf = Zeroconf() + zeroconf = Zeroconf(hass.loop) zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE) @@ -38,19 +38,22 @@ def setup(hass, config): 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) - info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name, host_ip_pton, - hass.http.server_port, 0, 0, params) + await zeroconf.register_service(info) - zeroconf.register_service(info) - - def stop_zeroconf(event): + async def stop_zeroconf(event): """Stop Zeroconf.""" - zeroconf.unregister_service(info) - zeroconf.close() + await zeroconf.unregister_service(info) + await zeroconf.close() - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf) + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf) return True diff --git a/homeassistant/components/zeroconf/manifest.json b/homeassistant/components/zeroconf/manifest.json index 7ef9b250363..5979ea12a58 100644 --- a/homeassistant/components/zeroconf/manifest.json +++ b/homeassistant/components/zeroconf/manifest.json @@ -3,7 +3,7 @@ "name": "Zeroconf", "documentation": "https://www.home-assistant.io/components/zeroconf", "requirements": [ - "zeroconf==0.22.0" + "aiozeroconf==0.1.8" ], "dependencies": [ "api" diff --git a/requirements_all.txt b/requirements_all.txt index 43d66a4c01b..1f28157235e 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -154,6 +154,9 @@ aioswitcher==2019.3.21 # homeassistant.components.unifi aiounifi==4 +# homeassistant.components.zeroconf +aiozeroconf==0.1.8 + # homeassistant.components.aladdin_connect aladdin_connect==0.3 @@ -1850,9 +1853,6 @@ youtube_dl==2019.05.11 # homeassistant.components.zengge zengge==0.2 -# homeassistant.components.zeroconf -zeroconf==0.22.0 - # homeassistant.components.zha zha-quirks==0.0.12 diff --git a/tests/components/default_config/test_init.py b/tests/components/default_config/test_init.py index 94adf53cb2d..8e2766a857b 100644 --- a/tests/components/default_config/test_init.py +++ b/tests/components/default_config/test_init.py @@ -5,7 +5,16 @@ from homeassistant.setup import async_setup_component import pytest -from tests.common import MockDependency +from tests.common import MockDependency, mock_coro + + +@pytest.fixture(autouse=True) +def aiozeroconf_mock(): + """Mock aiozeroconf.""" + with MockDependency('aiozeroconf') as mocked_zeroconf: + mocked_zeroconf.Zeroconf.return_value.register_service \ + .return_value = mock_coro(True) + yield @pytest.fixture(autouse=True)