mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
commit
6cca127bbf
@ -7,6 +7,7 @@ Knows which components handle certain types, will make sure they are
|
|||||||
loaded before the EVENT_PLATFORM_DISCOVERED is fired.
|
loaded before the EVENT_PLATFORM_DISCOVERED is fired.
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ def async_setup(hass, config):
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
netdisco = NetworkDiscovery()
|
netdisco = NetworkDiscovery()
|
||||||
|
already_discovered = set()
|
||||||
|
|
||||||
# Disable zeroconf logging, it spams
|
# Disable zeroconf logging, it spams
|
||||||
logging.getLogger('zeroconf').setLevel(logging.CRITICAL)
|
logging.getLogger('zeroconf').setLevel(logging.CRITICAL)
|
||||||
@ -79,14 +81,20 @@ def async_setup(hass, config):
|
|||||||
logger.info("Ignoring service: %s %s", service, info)
|
logger.info("Ignoring service: %s %s", service, info)
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info("Found new service: %s %s", service, info)
|
|
||||||
|
|
||||||
comp_plat = SERVICE_HANDLERS.get(service)
|
comp_plat = SERVICE_HANDLERS.get(service)
|
||||||
|
|
||||||
# We do not know how to handle this service.
|
# We do not know how to handle this service.
|
||||||
if not comp_plat:
|
if not comp_plat:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
discovery_hash = json.dumps([service, info], sort_keys=True)
|
||||||
|
if discovery_hash in already_discovered:
|
||||||
|
return
|
||||||
|
|
||||||
|
already_discovered.add(discovery_hash)
|
||||||
|
|
||||||
|
logger.info("Found new service: %s %s", service, info)
|
||||||
|
|
||||||
component, platform = comp_plat
|
component, platform = comp_plat
|
||||||
|
|
||||||
if platform is None:
|
if platform is None:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 39
|
MINOR_VERSION = 39
|
||||||
PATCH_VERSION = '2'
|
PATCH_VERSION = '3'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 4, 2)
|
REQUIRED_PYTHON_VER = (3, 4, 2)
|
||||||
|
@ -126,3 +126,30 @@ def test_ignore_service(hass):
|
|||||||
|
|
||||||
assert not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_discover_duplicates(hass):
|
||||||
|
"""Test load a component."""
|
||||||
|
result = yield from async_setup_component(hass, 'discovery', BASE_CONFIG)
|
||||||
|
assert result
|
||||||
|
|
||||||
|
def discover(netdisco):
|
||||||
|
"""Fake discovery."""
|
||||||
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||||
|
(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
|
with patch.object(discovery, '_discover', discover), \
|
||||||
|
patch('homeassistant.components.discovery.async_discover',
|
||||||
|
return_value=mock_coro()) as mock_discover, \
|
||||||
|
patch('homeassistant.components.discovery.async_load_platform',
|
||||||
|
return_value=mock_coro()) as mock_platform:
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||||
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert mock_discover.called
|
||||||
|
assert mock_discover.call_count == 1
|
||||||
|
assert not mock_platform.called
|
||||||
|
mock_discover.assert_called_with(
|
||||||
|
hass, SERVICE_NO_PLATFORM, SERVICE_INFO,
|
||||||
|
SERVICE_NO_PLATFORM_COMPONENT, BASE_CONFIG)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user