mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +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."""
|
||||
# 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
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"name": "Zeroconf",
|
||||
"documentation": "https://www.home-assistant.io/components/zeroconf",
|
||||
"requirements": [
|
||||
"aiozeroconf==0.1.8"
|
||||
"zeroconf==0.22.0"
|
||||
],
|
||||
"dependencies": [
|
||||
"api"
|
||||
|
@ -4,7 +4,7 @@ To update, run python3 -m hassfest
|
||||
"""
|
||||
|
||||
|
||||
SERVICE_TYPES = {
|
||||
ZEROCONF = {
|
||||
"_axis-video._tcp.local.": [
|
||||
"axis"
|
||||
],
|
||||
|
@ -162,9 +162,6 @@ aioswitcher==2019.3.21
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==4
|
||||
|
||||
# homeassistant.components.zeroconf
|
||||
aiozeroconf==0.1.8
|
||||
|
||||
# homeassistant.components.aladdin_connect
|
||||
aladdin_connect==0.3
|
||||
|
||||
@ -1877,6 +1874,9 @@ 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.13
|
||||
|
||||
|
@ -60,9 +60,6 @@ aioswitcher==2019.3.21
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==4
|
||||
|
||||
# homeassistant.components.zeroconf
|
||||
aiozeroconf==0.1.8
|
||||
|
||||
# homeassistant.components.ambiclimate
|
||||
ambiclimate==0.1.2
|
||||
|
||||
@ -354,5 +351,8 @@ vultr==0.1.2
|
||||
# homeassistant.components.wake_on_lan
|
||||
wakeonlan==1.1.6
|
||||
|
||||
# homeassistant.components.zeroconf
|
||||
zeroconf==0.22.0
|
||||
|
||||
# homeassistant.components.zha
|
||||
zigpy-homeassistant==0.3.3
|
||||
|
@ -51,7 +51,6 @@ TEST_REQUIREMENTS = (
|
||||
'aiohue',
|
||||
'aiounifi',
|
||||
'aioswitcher',
|
||||
'aiozeroconf',
|
||||
'apns2',
|
||||
'av',
|
||||
'axis',
|
||||
@ -150,6 +149,7 @@ TEST_REQUIREMENTS = (
|
||||
'vultr',
|
||||
'YesssSMS',
|
||||
'ruamel.yaml',
|
||||
'zeroconf',
|
||||
'zigpy-homeassistant',
|
||||
'bellows-homeassistant',
|
||||
)
|
||||
|
@ -12,7 +12,7 @@ To update, run python3 -m hassfest
|
||||
\"\"\"
|
||||
|
||||
|
||||
SERVICE_TYPES = {}
|
||||
ZEROCONF = {}
|
||||
""".strip()
|
||||
|
||||
|
||||
|
@ -9,9 +9,9 @@ from tests.common import MockDependency, mock_coro
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def aiozeroconf_mock():
|
||||
"""Mock aiozeroconf."""
|
||||
with MockDependency('aiozeroconf') as mocked_zeroconf:
|
||||
def zeroconf_mock():
|
||||
"""Mock zeroconf."""
|
||||
with MockDependency('zeroconf') as mocked_zeroconf:
|
||||
mocked_zeroconf.Zeroconf.return_value.register_service \
|
||||
.return_value = mock_coro(True)
|
||||
yield
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Test Zeroconf component setup process."""
|
||||
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.setup import async_setup_component
|
||||
@ -11,11 +11,11 @@ from homeassistant.components import zeroconf
|
||||
def service_update_mock(zeroconf, service, handlers):
|
||||
"""Call service update handler."""
|
||||
handlers[0](
|
||||
None, service, '{}.{}'.format('name', service),
|
||||
zeroconf, service, '{}.{}'.format('name', service),
|
||||
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 ServiceInfo(
|
||||
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(
|
||||
hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(MockServiceBrowser.mock_calls) == len(zc_gen.SERVICE_TYPES)
|
||||
assert len(mock_config_flow.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.ZEROCONF) * 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user