mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
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:
parent
42ee8eef50
commit
84baaa324c
@ -1,14 +1,16 @@
|
|||||||
"""Support for exposing Home Assistant via Zeroconf."""
|
"""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 logging
|
||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from aiozeroconf import (
|
from zeroconf import ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf
|
||||||
ServiceBrowser, ServiceInfo, ServiceStateChange, Zeroconf)
|
|
||||||
|
|
||||||
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP, __version__)
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Set up Zeroconf and make Home Assistant discoverable."""
|
"""Set up Zeroconf and make Home Assistant discoverable."""
|
||||||
zeroconf_name = '{}.{}'.format(hass.config.location_name, ZEROCONF_TYPE)
|
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,
|
info = ServiceInfo(ZEROCONF_TYPE, zeroconf_name,
|
||||||
port=hass.http.server_port, properties=params)
|
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):
|
def service_update(zeroconf, service_type, name, state_change):
|
||||||
"""Signal new service discovered."""
|
"""Service state changed."""
|
||||||
service_info = await zeroconf.get_service_info(service_type, name)
|
if state_change is ServiceStateChange.Added:
|
||||||
|
service_info = zeroconf.get_service_info(service_type, name)
|
||||||
info = info_from_service(service_info)
|
info = info_from_service(service_info)
|
||||||
_LOGGER.debug("Discovered new device %s %s", name, info)
|
_LOGGER.debug("Discovered new device %s %s", name, info)
|
||||||
|
|
||||||
for domain in zeroconf_manifest.SERVICE_TYPES[service_type]:
|
for domain in ZEROCONF[service_type]:
|
||||||
await hass.config_entries.flow.async_init(
|
hass.add_job(
|
||||||
|
hass.config_entries.flow.async_init(
|
||||||
domain, context={'source': DOMAIN}, data=info
|
domain, context={'source': DOMAIN}, data=info
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def service_update(_, service_type, name, state_change):
|
for service in ZEROCONF:
|
||||||
"""Service state changed."""
|
|
||||||
if state_change is ServiceStateChange.Added:
|
|
||||||
hass.async_create_task(new_service(service_type, name))
|
|
||||||
|
|
||||||
for service in zeroconf_manifest.SERVICE_TYPES:
|
|
||||||
ServiceBrowser(zeroconf, service, handlers=[service_update])
|
ServiceBrowser(zeroconf, service, handlers=[service_update])
|
||||||
|
|
||||||
async def stop_zeroconf(_):
|
def stop_zeroconf(_):
|
||||||
"""Stop Zeroconf."""
|
"""Stop Zeroconf."""
|
||||||
await zeroconf.unregister_service(info)
|
zeroconf.unregister_service(info)
|
||||||
await zeroconf.close()
|
zeroconf.close()
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_zeroconf)
|
hass.bus.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": [
|
||||||
"aiozeroconf==0.1.8"
|
"zeroconf==0.22.0"
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"api"
|
"api"
|
||||||
|
@ -4,7 +4,7 @@ To update, run python3 -m hassfest
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
SERVICE_TYPES = {
|
ZEROCONF = {
|
||||||
"_axis-video._tcp.local.": [
|
"_axis-video._tcp.local.": [
|
||||||
"axis"
|
"axis"
|
||||||
],
|
],
|
||||||
|
@ -162,9 +162,6 @@ 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
|
||||||
|
|
||||||
@ -1877,6 +1874,9 @@ 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.13
|
zha-quirks==0.0.13
|
||||||
|
|
||||||
|
@ -60,9 +60,6 @@ aioswitcher==2019.3.21
|
|||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==4
|
aiounifi==4
|
||||||
|
|
||||||
# homeassistant.components.zeroconf
|
|
||||||
aiozeroconf==0.1.8
|
|
||||||
|
|
||||||
# homeassistant.components.ambiclimate
|
# homeassistant.components.ambiclimate
|
||||||
ambiclimate==0.1.2
|
ambiclimate==0.1.2
|
||||||
|
|
||||||
@ -354,5 +351,8 @@ vultr==0.1.2
|
|||||||
# homeassistant.components.wake_on_lan
|
# homeassistant.components.wake_on_lan
|
||||||
wakeonlan==1.1.6
|
wakeonlan==1.1.6
|
||||||
|
|
||||||
|
# homeassistant.components.zeroconf
|
||||||
|
zeroconf==0.22.0
|
||||||
|
|
||||||
# homeassistant.components.zha
|
# homeassistant.components.zha
|
||||||
zigpy-homeassistant==0.3.3
|
zigpy-homeassistant==0.3.3
|
||||||
|
@ -51,7 +51,6 @@ TEST_REQUIREMENTS = (
|
|||||||
'aiohue',
|
'aiohue',
|
||||||
'aiounifi',
|
'aiounifi',
|
||||||
'aioswitcher',
|
'aioswitcher',
|
||||||
'aiozeroconf',
|
|
||||||
'apns2',
|
'apns2',
|
||||||
'av',
|
'av',
|
||||||
'axis',
|
'axis',
|
||||||
@ -150,6 +149,7 @@ TEST_REQUIREMENTS = (
|
|||||||
'vultr',
|
'vultr',
|
||||||
'YesssSMS',
|
'YesssSMS',
|
||||||
'ruamel.yaml',
|
'ruamel.yaml',
|
||||||
|
'zeroconf',
|
||||||
'zigpy-homeassistant',
|
'zigpy-homeassistant',
|
||||||
'bellows-homeassistant',
|
'bellows-homeassistant',
|
||||||
)
|
)
|
||||||
|
@ -12,7 +12,7 @@ To update, run python3 -m hassfest
|
|||||||
\"\"\"
|
\"\"\"
|
||||||
|
|
||||||
|
|
||||||
SERVICE_TYPES = {}
|
ZEROCONF = {}
|
||||||
""".strip()
|
""".strip()
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ from tests.common import MockDependency, mock_coro
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def aiozeroconf_mock():
|
def zeroconf_mock():
|
||||||
"""Mock aiozeroconf."""
|
"""Mock zeroconf."""
|
||||||
with MockDependency('aiozeroconf') as mocked_zeroconf:
|
with MockDependency('zeroconf') as mocked_zeroconf:
|
||||||
mocked_zeroconf.Zeroconf.return_value.register_service \
|
mocked_zeroconf.Zeroconf.return_value.register_service \
|
||||||
.return_value = mock_coro(True)
|
.return_value = mock_coro(True)
|
||||||
yield
|
yield
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Test Zeroconf component setup process."""
|
"""Test Zeroconf component setup process."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from aiozeroconf import ServiceInfo, ServiceStateChange
|
from zeroconf import ServiceInfo, ServiceStateChange
|
||||||
|
|
||||||
from homeassistant.generated import zeroconf as zc_gen
|
from homeassistant.generated import zeroconf as zc_gen
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -11,11 +11,11 @@ from homeassistant.components import zeroconf
|
|||||||
def service_update_mock(zeroconf, service, handlers):
|
def service_update_mock(zeroconf, service, handlers):
|
||||||
"""Call service update handler."""
|
"""Call service update handler."""
|
||||||
handlers[0](
|
handlers[0](
|
||||||
None, service, '{}.{}'.format('name', service),
|
zeroconf, service, '{}.{}'.format('name', service),
|
||||||
ServiceStateChange.Added)
|
ServiceStateChange.Added)
|
||||||
|
|
||||||
|
|
||||||
async def get_service_info_mock(service_type, name):
|
def get_service_info_mock(service_type, name):
|
||||||
"""Return service info for get_service_info."""
|
"""Return service info for get_service_info."""
|
||||||
return ServiceInfo(
|
return ServiceInfo(
|
||||||
service_type, name, address=b'\n\x00\x00\x14', port=80, weight=0,
|
service_type, name, address=b'\n\x00\x00\x14', port=80, weight=0,
|
||||||
@ -35,7 +35,6 @@ async def test_setup(hass):
|
|||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.SERVICE_TYPES)
|
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.ZEROCONF)
|
||||||
assert len(mock_config_flow.mock_calls) == len(zc_gen.SERVICE_TYPES)
|
assert len(mock_config_flow.mock_calls) == len(zc_gen.ZEROCONF) * 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user