mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Zeroconf - replace library (#23835)
* Use aiozeroconf in preparation for new zeroconf discovery * Update requirements * Remove sleep * Make stop zeroconf a coroutine * Remove unused import * Fix aiozeroconf dependency in default_config tests
This commit is contained in:
parent
45085dd97f
commit
0d96095646
@ -19,11 +19,11 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up Zeroconf and make Home Assistant discoverable."""
|
"""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)
|
zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
|
||||||
|
|
||||||
@ -38,19 +38,22 @@ def setup(hass, config):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
host_ip_pton = socket.inet_pton(socket.AF_INET, host_ip)
|
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:
|
except socket.error:
|
||||||
host_ip_pton = socket.inet_pton(socket.AF_INET6, host_ip)
|
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,
|
await zeroconf.register_service(info)
|
||||||
hass.http.server_port, 0, 0, params)
|
|
||||||
|
|
||||||
zeroconf.register_service(info)
|
async def stop_zeroconf(event):
|
||||||
|
|
||||||
def stop_zeroconf(event):
|
|
||||||
"""Stop Zeroconf."""
|
"""Stop Zeroconf."""
|
||||||
zeroconf.unregister_service(info)
|
await zeroconf.unregister_service(info)
|
||||||
zeroconf.close()
|
await zeroconf.close()
|
||||||
|
|
||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Zeroconf",
|
"name": "Zeroconf",
|
||||||
"documentation": "https://www.home-assistant.io/components/zeroconf",
|
"documentation": "https://www.home-assistant.io/components/zeroconf",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"zeroconf==0.22.0"
|
"aiozeroconf==0.1.8"
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"api"
|
"api"
|
||||||
|
@ -154,6 +154,9 @@ aioswitcher==2019.3.21
|
|||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==4
|
aiounifi==4
|
||||||
|
|
||||||
|
# homeassistant.components.zeroconf
|
||||||
|
aiozeroconf==0.1.8
|
||||||
|
|
||||||
# homeassistant.components.aladdin_connect
|
# homeassistant.components.aladdin_connect
|
||||||
aladdin_connect==0.3
|
aladdin_connect==0.3
|
||||||
|
|
||||||
@ -1850,9 +1853,6 @@ youtube_dl==2019.05.11
|
|||||||
# homeassistant.components.zengge
|
# homeassistant.components.zengge
|
||||||
zengge==0.2
|
zengge==0.2
|
||||||
|
|
||||||
# homeassistant.components.zeroconf
|
|
||||||
zeroconf==0.22.0
|
|
||||||
|
|
||||||
# homeassistant.components.zha
|
# homeassistant.components.zha
|
||||||
zha-quirks==0.0.12
|
zha-quirks==0.0.12
|
||||||
|
|
||||||
|
@ -5,7 +5,16 @@ from homeassistant.setup import async_setup_component
|
|||||||
|
|
||||||
import pytest
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user