1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Tests for zwave setup features (#7570)

* Tests for zwave setup features

* Add test for frontend panel register
This commit is contained in:
Adam Mills
2017-05-12 20:27:44 -07:00
committed by Paulus Schoutsen
parent c118be6639
commit 189023821b
3 changed files with 88 additions and 3 deletions

View File

@@ -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."""