mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
commit
9c386c68dd
@ -13,6 +13,7 @@ import logging
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||||
@ -105,7 +106,7 @@ def async_setup(hass, config):
|
|||||||
hass, component, platform, info, config)
|
hass, component, platform, info, config)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def scan_devices(_):
|
def scan_devices(now):
|
||||||
"""Scan for devices."""
|
"""Scan for devices."""
|
||||||
results = yield from hass.loop.run_in_executor(
|
results = yield from hass.loop.run_in_executor(
|
||||||
None, _discover, netdisco)
|
None, _discover, netdisco)
|
||||||
@ -116,7 +117,12 @@ def async_setup(hass, config):
|
|||||||
async_track_point_in_utc_time(hass, scan_devices,
|
async_track_point_in_utc_time(hass, scan_devices,
|
||||||
dt_util.utcnow() + SCAN_INTERVAL)
|
dt_util.utcnow() + SCAN_INTERVAL)
|
||||||
|
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, scan_devices)
|
@callback
|
||||||
|
def schedule_first(event):
|
||||||
|
"""Schedule the first discovery when Home Assistant starts up."""
|
||||||
|
async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow())
|
||||||
|
|
||||||
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_first)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 42
|
MINOR_VERSION = 42
|
||||||
PATCH_VERSION = '0'
|
PATCH_VERSION = '1'
|
||||||
__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)
|
||||||
|
@ -5,5 +5,5 @@ pip>=7.1.0
|
|||||||
jinja2>=2.9.5
|
jinja2>=2.9.5
|
||||||
voluptuous==0.9.3
|
voluptuous==0.9.3
|
||||||
typing>=3,<4
|
typing>=3,<4
|
||||||
aiohttp==2.0.5
|
aiohttp==2.0.6
|
||||||
async_timeout==1.2.0
|
async_timeout==1.2.0
|
||||||
|
@ -6,7 +6,7 @@ pip>=7.1.0
|
|||||||
jinja2>=2.9.5
|
jinja2>=2.9.5
|
||||||
voluptuous==0.9.3
|
voluptuous==0.9.3
|
||||||
typing>=3,<4
|
typing>=3,<4
|
||||||
aiohttp==2.0.5
|
aiohttp==2.0.6
|
||||||
async_timeout==1.2.0
|
async_timeout==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.nuimo_controller
|
# homeassistant.components.nuimo_controller
|
||||||
|
2
setup.py
2
setup.py
@ -22,7 +22,7 @@ REQUIRES = [
|
|||||||
'jinja2>=2.9.5',
|
'jinja2>=2.9.5',
|
||||||
'voluptuous==0.9.3',
|
'voluptuous==0.9.3',
|
||||||
'typing>=3,<4',
|
'typing>=3,<4',
|
||||||
'aiohttp==2.0.5',
|
'aiohttp==2.0.6',
|
||||||
'async_timeout==1.2.0',
|
'async_timeout==1.2.0',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components import discovery
|
from homeassistant.components import discovery
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from tests.common import mock_coro
|
from tests.common import mock_coro, fire_time_changed
|
||||||
|
|
||||||
# One might consider to "mock" services, but it's easy enough to just use
|
# One might consider to "mock" services, but it's easy enough to just use
|
||||||
# what is already available.
|
# what is already available.
|
||||||
@ -34,24 +34,34 @@ IGNORE_CONFIG = {
|
|||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_unknown_service(hass):
|
def mock_discovery(hass, discoveries, config=BASE_CONFIG):
|
||||||
"""Test that unknown service is ignored."""
|
"""Helper to mock discoveries."""
|
||||||
result = yield from async_setup_component(hass, 'discovery', {
|
result = yield from async_setup_component(hass, 'discovery', config)
|
||||||
'discovery': {},
|
|
||||||
})
|
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
def discover(netdisco):
|
yield from hass.async_start()
|
||||||
"""Fake discovery."""
|
|
||||||
return [('this_service_will_never_be_supported', {'info': 'some'})]
|
|
||||||
|
|
||||||
with patch.object(discovery, '_discover', discover), \
|
with patch.object(discovery, '_discover', discoveries), \
|
||||||
patch('homeassistant.components.discovery.async_discover',
|
patch('homeassistant.components.discovery.async_discover',
|
||||||
return_value=mock_coro()) as mock_discover, \
|
return_value=mock_coro()) as mock_discover, \
|
||||||
patch('homeassistant.components.discovery.async_load_platform',
|
patch('homeassistant.components.discovery.async_load_platform',
|
||||||
return_value=mock_coro()) as mock_platform:
|
return_value=mock_coro()) as mock_platform:
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
fire_time_changed(hass, utcnow())
|
||||||
|
# Work around an issue where our loop.call_soon not get caught
|
||||||
yield from hass.async_block_till_done()
|
yield from hass.async_block_till_done()
|
||||||
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
|
return mock_discover, mock_platform
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_unknown_service(hass):
|
||||||
|
"""Test that unknown service is ignored."""
|
||||||
|
def discover(netdisco):
|
||||||
|
"""Fake discovery."""
|
||||||
|
return [('this_service_will_never_be_supported', {'info': 'some'})]
|
||||||
|
|
||||||
|
mock_discover, mock_platform = yield from mock_discovery(hass, discover)
|
||||||
|
|
||||||
assert not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
@ -60,20 +70,11 @@ def test_unknown_service(hass):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_load_platform(hass):
|
def test_load_platform(hass):
|
||||||
"""Test load a platform."""
|
"""Test load a platform."""
|
||||||
result = yield from async_setup_component(hass, 'discovery', BASE_CONFIG)
|
|
||||||
assert result
|
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE, SERVICE_INFO)]
|
return [(SERVICE, SERVICE_INFO)]
|
||||||
|
|
||||||
with patch.object(discovery, '_discover', discover), \
|
mock_discover, mock_platform = yield from mock_discovery(hass, 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 not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert mock_platform.called
|
assert mock_platform.called
|
||||||
@ -84,20 +85,11 @@ def test_load_platform(hass):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_load_component(hass):
|
def test_load_component(hass):
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
result = yield from async_setup_component(hass, 'discovery', BASE_CONFIG)
|
|
||||||
assert result
|
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
with patch.object(discovery, '_discover', discover), \
|
mock_discover, mock_platform = yield from mock_discovery(hass, 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.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
@ -109,20 +101,12 @@ def test_load_component(hass):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_ignore_service(hass):
|
def test_ignore_service(hass):
|
||||||
"""Test ignore service."""
|
"""Test ignore service."""
|
||||||
result = yield from async_setup_component(hass, 'discovery', IGNORE_CONFIG)
|
|
||||||
assert result
|
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
with patch.object(discovery, '_discover', discover), \
|
mock_discover, mock_platform = yield from mock_discovery(hass, discover,
|
||||||
patch('homeassistant.components.discovery.async_discover',
|
IGNORE_CONFIG)
|
||||||
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 not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
@ -131,21 +115,12 @@ def test_ignore_service(hass):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_discover_duplicates(hass):
|
def test_discover_duplicates(hass):
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
result = yield from async_setup_component(hass, 'discovery', BASE_CONFIG)
|
|
||||||
assert result
|
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||||
(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
with patch.object(discovery, '_discover', discover), \
|
mock_discover, mock_platform = yield from mock_discovery(hass, 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.called
|
||||||
assert mock_discover.call_count == 1
|
assert mock_discover.call_count == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user