mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Tests for zwave setup features (#7570)
* Tests for zwave setup features * Add test for frontend panel register
This commit is contained in:
parent
c118be6639
commit
189023821b
@ -1,6 +1,7 @@
|
||||
"""Tests for the Z-Wave init."""
|
||||
import asyncio
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.const import ATTR_ENTITY_ID, EVENT_HOMEASSISTANT_START
|
||||
@ -14,7 +15,8 @@ import pytest
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from tests.common import (
|
||||
get_test_home_assistant, async_fire_time_changed, mock_http_component)
|
||||
from tests.mock.zwave import MockNetwork, MockNode, MockValue, MockEntityValues
|
||||
|
||||
|
||||
@ -69,6 +71,70 @@ def test_config_access_error():
|
||||
assert result is None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_network_options(hass, mock_openzwave):
|
||||
"""Test network options."""
|
||||
result = yield from async_setup_component(hass, 'zwave', {
|
||||
'zwave': {
|
||||
'usb_path': 'mock_usb_path',
|
||||
'config_path': 'mock_config_path',
|
||||
}})
|
||||
|
||||
assert result
|
||||
|
||||
network = hass.data[zwave.ZWAVE_NETWORK]
|
||||
assert network.options.device == 'mock_usb_path'
|
||||
assert network.options.config_path == 'mock_config_path'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_auto_heal_midnight(hass, mock_openzwave):
|
||||
"""Test network auto-heal at midnight."""
|
||||
assert (yield from async_setup_component(hass, 'zwave', {
|
||||
'zwave': {
|
||||
'autoheal': True,
|
||||
}}))
|
||||
network = hass.data[zwave.ZWAVE_NETWORK]
|
||||
assert not network.heal.called
|
||||
|
||||
time = datetime(2017, 5, 6, 0, 0, 0)
|
||||
async_fire_time_changed(hass, time)
|
||||
yield from hass.async_block_till_done()
|
||||
assert network.heal.called
|
||||
assert len(network.heal.mock_calls) == 1
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_auto_heal_disabled(hass, mock_openzwave):
|
||||
"""Test network auto-heal disabled."""
|
||||
assert (yield from async_setup_component(hass, 'zwave', {
|
||||
'zwave': {
|
||||
'autoheal': False,
|
||||
}}))
|
||||
network = hass.data[zwave.ZWAVE_NETWORK]
|
||||
assert not network.heal.called
|
||||
|
||||
time = datetime(2017, 5, 6, 0, 0, 0)
|
||||
async_fire_time_changed(hass, time)
|
||||
yield from hass.async_block_till_done()
|
||||
assert not network.heal.called
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_frontend_panel_register(hass, mock_openzwave):
|
||||
"""Test network auto-heal disabled."""
|
||||
mock_http_component(hass)
|
||||
hass.config.components |= set(['frontend'])
|
||||
with patch('homeassistant.components.zwave.'
|
||||
'register_built_in_panel') as mock_register:
|
||||
assert (yield from async_setup_component(hass, 'zwave', {
|
||||
'zwave': {
|
||||
'autoheal': False,
|
||||
}}))
|
||||
assert mock_register.called
|
||||
assert len(mock_register.mock_calls) == 1
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_setup_platform(hass, mock_openzwave):
|
||||
"""Test invalid device config."""
|
||||
|
@ -14,7 +14,7 @@ from homeassistant.components import mqtt
|
||||
|
||||
from tests.common import async_test_home_assistant, mock_coro
|
||||
from tests.test_util.aiohttp import mock_aiohttp_client
|
||||
from tests.mock.zwave import MockNetwork
|
||||
from tests.mock.zwave import MockNetwork, MockOption
|
||||
|
||||
if os.environ.get('UVLOOP') == '1':
|
||||
import uvloop
|
||||
@ -101,6 +101,7 @@ def mock_openzwave():
|
||||
libopenzwave = base_mock.libopenzwave
|
||||
libopenzwave.__file__ = 'test'
|
||||
base_mock.network.ZWaveNetwork = MockNetwork
|
||||
base_mock.option.ZWaveOption = MockOption
|
||||
|
||||
with patch.dict('sys.modules', {
|
||||
'libopenzwave': libopenzwave,
|
||||
|
@ -32,6 +32,23 @@ def notification(node_id, network=None):
|
||||
)
|
||||
|
||||
|
||||
class MockOption(MagicMock):
|
||||
"""Mock Z-Wave options."""
|
||||
|
||||
def __init__(self, device=None, config_path=None, user_path=None,
|
||||
cmd_line=None):
|
||||
"""Initialize a Z-Wave mock options."""
|
||||
super().__init__()
|
||||
self.device = device
|
||||
self.config_path = config_path
|
||||
self.user_path = user_path
|
||||
self.cmd_line = cmd_line
|
||||
|
||||
def _get_child_mock(self, **kw):
|
||||
"""Create child mocks with right MagicMock class."""
|
||||
return MagicMock(**kw)
|
||||
|
||||
|
||||
class MockNetwork(MagicMock):
|
||||
"""Mock Z-Wave network."""
|
||||
|
||||
@ -84,9 +101,10 @@ class MockNetwork(MagicMock):
|
||||
STATE_AWAKED = 7
|
||||
STATE_READY = 10
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, options=None, *args, **kwargs):
|
||||
"""Initialize a Z-Wave mock network."""
|
||||
super().__init__()
|
||||
self.options = options
|
||||
self.state = MockNetwork.STATE_STOPPED
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user