2017-02-14 05:34:36 +00:00
|
|
|
"""Test Z-Wave config panel."""
|
|
|
|
import asyncio
|
|
|
|
import json
|
2017-08-06 19:05:34 +00:00
|
|
|
from unittest.mock import MagicMock, patch
|
2017-02-14 05:34:36 +00:00
|
|
|
|
2018-02-15 21:06:14 +00:00
|
|
|
import pytest
|
|
|
|
|
2017-02-14 05:34:36 +00:00
|
|
|
from homeassistant.bootstrap import async_setup_component
|
|
|
|
from homeassistant.components import config
|
|
|
|
|
2017-08-06 19:05:34 +00:00
|
|
|
from homeassistant.components.zwave import DATA_NETWORK, const
|
|
|
|
from tests.mock.zwave import MockNode, MockValue, MockEntityValues
|
|
|
|
|
2017-02-14 05:34:36 +00:00
|
|
|
|
2017-02-21 05:53:55 +00:00
|
|
|
VIEW_NAME = 'api:config:zwave:device_config'
|
|
|
|
|
|
|
|
|
2018-02-15 21:06:14 +00:00
|
|
|
@pytest.fixture
|
2018-03-15 20:49:49 +00:00
|
|
|
def client(loop, hass, aiohttp_client):
|
2018-02-15 21:06:14 +00:00
|
|
|
"""Client to communicate with Z-Wave config views."""
|
2017-02-14 05:34:36 +00:00
|
|
|
with patch.object(config, 'SECTIONS', ['zwave']):
|
2018-02-15 21:06:14 +00:00
|
|
|
loop.run_until_complete(async_setup_component(hass, 'config', {}))
|
2017-02-14 05:34:36 +00:00
|
|
|
|
2018-03-15 20:49:49 +00:00
|
|
|
return loop.run_until_complete(aiohttp_client(hass.http.app))
|
2017-02-14 05:34:36 +00:00
|
|
|
|
2018-02-15 21:06:14 +00:00
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def test_get_device_config(client):
|
|
|
|
"""Test getting device config."""
|
2017-02-14 05:34:36 +00:00
|
|
|
def mock_read(path):
|
|
|
|
"""Mock reading data."""
|
|
|
|
return {
|
|
|
|
'hello.beer': {
|
|
|
|
'free': 'beer',
|
|
|
|
},
|
|
|
|
'other.entity': {
|
|
|
|
'do': 'something',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-02-21 05:53:55 +00:00
|
|
|
with patch('homeassistant.components.config._read', mock_read):
|
2017-02-14 05:34:36 +00:00
|
|
|
resp = yield from client.get(
|
|
|
|
'/api/config/zwave/device_config/hello.beer')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'free': 'beer'}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_update_device_config(client):
|
2017-02-14 05:34:36 +00:00
|
|
|
"""Test updating device config."""
|
|
|
|
orig_data = {
|
|
|
|
'hello.beer': {
|
|
|
|
'ignored': True,
|
|
|
|
},
|
|
|
|
'other.entity': {
|
|
|
|
'polling_intensity': 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def mock_read(path):
|
|
|
|
"""Mock reading data."""
|
|
|
|
return orig_data
|
|
|
|
|
|
|
|
written = []
|
|
|
|
|
|
|
|
def mock_write(path, data):
|
|
|
|
"""Mock writing data."""
|
|
|
|
written.append(data)
|
|
|
|
|
2017-02-21 05:53:55 +00:00
|
|
|
with patch('homeassistant.components.config._read', mock_read), \
|
|
|
|
patch('homeassistant.components.config._write', mock_write):
|
2017-02-14 05:34:36 +00:00
|
|
|
resp = yield from client.post(
|
|
|
|
'/api/config/zwave/device_config/hello.beer', data=json.dumps({
|
|
|
|
'polling_intensity': 2
|
|
|
|
}))
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
assert result == {'result': 'ok'}
|
|
|
|
|
|
|
|
orig_data['hello.beer']['polling_intensity'] = 2
|
|
|
|
|
|
|
|
assert written[0] == orig_data
|
2017-02-21 05:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_update_device_config_invalid_key(client):
|
2017-02-21 05:53:55 +00:00
|
|
|
"""Test updating device config."""
|
|
|
|
resp = yield from client.post(
|
|
|
|
'/api/config/zwave/device_config/invalid_entity', data=json.dumps({
|
|
|
|
'polling_intensity': 2
|
|
|
|
}))
|
|
|
|
|
|
|
|
assert resp.status == 400
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_update_device_config_invalid_data(client):
|
2017-02-21 05:53:55 +00:00
|
|
|
"""Test updating device config."""
|
|
|
|
resp = yield from client.post(
|
|
|
|
'/api/config/zwave/device_config/hello.beer', data=json.dumps({
|
|
|
|
'invalid_option': 2
|
|
|
|
}))
|
|
|
|
|
|
|
|
assert resp.status == 400
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_update_device_config_invalid_json(client):
|
2017-02-21 05:53:55 +00:00
|
|
|
"""Test updating device config."""
|
|
|
|
resp = yield from client.post(
|
|
|
|
'/api/config/zwave/device_config/hello.beer', data='not json')
|
|
|
|
|
|
|
|
assert resp.status == 400
|
2017-08-06 19:05:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_values(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting values on node."""
|
|
|
|
node = MockNode(node_id=1)
|
|
|
|
value = MockValue(value_id=123456, node=node, label='Test Label',
|
2017-09-11 18:30:48 +00:00
|
|
|
instance=1, index=2, poll_intensity=4)
|
2017-08-06 19:05:34 +00:00
|
|
|
values = MockEntityValues(primary=value)
|
|
|
|
node2 = MockNode(node_id=2)
|
|
|
|
value2 = MockValue(value_id=234567, node=node2, label='Test Label 2')
|
|
|
|
values2 = MockEntityValues(primary=value2)
|
|
|
|
hass.data[const.DATA_ENTITY_VALUES] = [values, values2]
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/values/1')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {
|
|
|
|
'123456': {
|
|
|
|
'label': 'Test Label',
|
|
|
|
'instance': 1,
|
|
|
|
'index': 2,
|
2017-09-11 18:30:48 +00:00
|
|
|
'poll_intensity': 4,
|
2017-08-06 19:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_groups(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting groupdata on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=2)
|
|
|
|
node.groups.associations = 'assoc'
|
|
|
|
node.groups.associations_instances = 'inst'
|
|
|
|
node.groups.label = 'the label'
|
|
|
|
node.groups.max_associations = 'max'
|
|
|
|
node.groups = {1: node.groups}
|
|
|
|
network.nodes = {2: node}
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/groups/2')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {
|
|
|
|
'1': {
|
|
|
|
'association_instances': 'inst',
|
|
|
|
'associations': 'assoc',
|
|
|
|
'label': 'the label',
|
|
|
|
'max_associations': 'max'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_groups_nogroups(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting groupdata on node with no groups."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=2)
|
|
|
|
|
|
|
|
network.nodes = {2: node}
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/groups/2')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_groups_nonode(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting groupdata on nonexisting node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
network.nodes = {1: 1, 5: 5}
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/groups/2')
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'message': 'Node not found'}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_config(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting config on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=2)
|
|
|
|
value = MockValue(
|
|
|
|
index=12,
|
|
|
|
command_class=const.COMMAND_CLASS_CONFIGURATION)
|
|
|
|
value.label = 'label'
|
|
|
|
value.help = 'help'
|
|
|
|
value.type = 'type'
|
|
|
|
value.data = 'data'
|
|
|
|
value.data_items = ['item1', 'item2']
|
|
|
|
value.max = 'max'
|
|
|
|
value.min = 'min'
|
|
|
|
node.values = {12: value}
|
|
|
|
network.nodes = {2: node}
|
|
|
|
node.get_values.return_value = node.values
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/config/2')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'12': {'data': 'data',
|
|
|
|
'data_items': ['item1', 'item2'],
|
|
|
|
'help': 'help',
|
|
|
|
'label': 'label',
|
|
|
|
'max': 'max',
|
|
|
|
'min': 'min',
|
|
|
|
'type': 'type'}}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_config_noconfig_node(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting config on node without config."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=2)
|
|
|
|
|
|
|
|
network.nodes = {2: node}
|
|
|
|
node.get_values.return_value = node.values
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/config/2')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_config_nonode(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting config on nonexisting node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
network.nodes = {1: 1, 5: 5}
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/config/2')
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'message': 'Node not found'}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_usercodes_nonode(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting usercodes on nonexisting node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
network.nodes = {1: 1, 5: 5}
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/usercodes/2')
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'message': 'Node not found'}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_usercodes(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting usercodes on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_USER_CODE])
|
|
|
|
value = MockValue(
|
|
|
|
index=0,
|
|
|
|
command_class=const.COMMAND_CLASS_USER_CODE)
|
|
|
|
value.genre = const.GENRE_USER
|
|
|
|
value.label = 'label'
|
|
|
|
value.data = '1234'
|
|
|
|
node.values = {0: value}
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.get_values.return_value = node.values
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/usercodes/18')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {'0': {'code': '1234',
|
|
|
|
'label': 'label',
|
|
|
|
'length': 4}}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_usercode_nousercode_node(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting usercodes on node without usercodes."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18)
|
|
|
|
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.get_values.return_value = node.values
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/usercodes/18')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_get_usercodes_no_genreuser(hass, client):
|
2017-08-06 19:05:34 +00:00
|
|
|
"""Test getting usercodes on node missing genre user."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_USER_CODE])
|
|
|
|
value = MockValue(
|
|
|
|
index=0,
|
|
|
|
command_class=const.COMMAND_CLASS_USER_CODE)
|
|
|
|
value.genre = const.GENRE_SYSTEM
|
|
|
|
value.label = 'label'
|
|
|
|
value.data = '1234'
|
|
|
|
node.values = {0: value}
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.get_values.return_value = node.values
|
|
|
|
|
|
|
|
resp = yield from client.get('/api/zwave/usercodes/18')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
|
|
|
|
assert result == {}
|
2017-11-06 14:15:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_save_config_no_network(hass, client):
|
2017-11-06 14:15:52 +00:00
|
|
|
"""Test saving configuration without network data."""
|
|
|
|
resp = yield from client.post('/api/zwave/saveconfig')
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = yield from resp.json()
|
|
|
|
assert result == {'message': 'No Z-Wave network data found'}
|
|
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
2018-02-15 21:06:14 +00:00
|
|
|
def test_save_config(hass, client):
|
2017-11-06 14:15:52 +00:00
|
|
|
"""Test saving configuration."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
|
|
|
|
resp = yield from client.post('/api/zwave/saveconfig')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = yield from resp.json()
|
|
|
|
assert network.write_config.called
|
|
|
|
assert result == {'message': 'Z-Wave configuration saved to file.'}
|
2018-07-23 13:31:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_get_protection_values(hass, client):
|
|
|
|
"""Test getting protection values on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_PROTECTION])
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1,
|
|
|
|
command_class=const.COMMAND_CLASS_PROTECTION)
|
|
|
|
value.label = 'Protection Test'
|
|
|
|
value.data_items = ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
value.data = 'Unprotected'
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.value = value
|
|
|
|
|
|
|
|
node.get_protection_item.return_value = "Unprotected"
|
|
|
|
node.get_protection_items.return_value = value.data_items
|
|
|
|
node.get_protections.return_value = {value.value_id: 'Object'}
|
|
|
|
|
|
|
|
resp = await client.get('/api/zwave/protection/18')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = await resp.json()
|
|
|
|
assert node.get_protections.called
|
|
|
|
assert node.get_protection_item.called
|
|
|
|
assert node.get_protection_items.called
|
|
|
|
assert result == {
|
|
|
|
'value_id': '123456',
|
|
|
|
'selected': 'Unprotected',
|
|
|
|
'options': ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_protection_values_nonexisting_node(hass, client):
|
|
|
|
"""Test getting protection values on node with wrong nodeid."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_PROTECTION])
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1,
|
|
|
|
command_class=const.COMMAND_CLASS_PROTECTION)
|
|
|
|
value.label = 'Protection Test'
|
|
|
|
value.data_items = ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
value.data = 'Unprotected'
|
|
|
|
network.nodes = {17: node}
|
|
|
|
node.value = value
|
|
|
|
|
|
|
|
resp = await client.get('/api/zwave/protection/18')
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = await resp.json()
|
|
|
|
assert not node.get_protections.called
|
|
|
|
assert not node.get_protection_item.called
|
|
|
|
assert not node.get_protection_items.called
|
|
|
|
assert result == {'message': 'Node not found'}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_protection_values_without_protectionclass(hass, client):
|
|
|
|
"""Test getting protection values on node without protectionclass."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18)
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1)
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.value = value
|
|
|
|
|
|
|
|
resp = await client.get('/api/zwave/protection/18')
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = await resp.json()
|
|
|
|
assert not node.get_protections.called
|
|
|
|
assert not node.get_protection_item.called
|
|
|
|
assert not node.get_protection_items.called
|
|
|
|
assert result == {}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_protection_value(hass, client):
|
|
|
|
"""Test setting protection value on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_PROTECTION])
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1,
|
|
|
|
command_class=const.COMMAND_CLASS_PROTECTION)
|
|
|
|
value.label = 'Protection Test'
|
|
|
|
value.data_items = ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
value.data = 'Unprotected'
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.value = value
|
|
|
|
|
|
|
|
resp = await client.post(
|
|
|
|
'/api/zwave/protection/18', data=json.dumps({
|
|
|
|
'value_id': '123456', 'selection': 'Protection by Sequence'}))
|
|
|
|
|
|
|
|
assert resp.status == 200
|
|
|
|
result = await resp.json()
|
|
|
|
assert node.set_protection.called
|
|
|
|
assert result == {'message': 'Protection setting succsessfully set'}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_protection_value_failed(hass, client):
|
|
|
|
"""Test setting protection value failed on node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=18,
|
|
|
|
command_classes=[const.COMMAND_CLASS_PROTECTION])
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1,
|
|
|
|
command_class=const.COMMAND_CLASS_PROTECTION)
|
|
|
|
value.label = 'Protection Test'
|
|
|
|
value.data_items = ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
value.data = 'Unprotected'
|
|
|
|
network.nodes = {18: node}
|
|
|
|
node.value = value
|
|
|
|
node.set_protection.return_value = False
|
|
|
|
|
|
|
|
resp = await client.post(
|
|
|
|
'/api/zwave/protection/18', data=json.dumps({
|
|
|
|
'value_id': '123456', 'selection': 'Protecton by Seuence'}))
|
|
|
|
|
|
|
|
assert resp.status == 202
|
|
|
|
result = await resp.json()
|
|
|
|
assert node.set_protection.called
|
|
|
|
assert result == {'message': 'Protection setting did not complete'}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_protection_value_nonexisting_node(hass, client):
|
|
|
|
"""Test setting protection value on nonexisting node."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=17,
|
|
|
|
command_classes=[const.COMMAND_CLASS_PROTECTION])
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1,
|
|
|
|
command_class=const.COMMAND_CLASS_PROTECTION)
|
|
|
|
value.label = 'Protection Test'
|
|
|
|
value.data_items = ['Unprotected', 'Protection by Sequence',
|
|
|
|
'No Operation Possible']
|
|
|
|
value.data = 'Unprotected'
|
|
|
|
network.nodes = {17: node}
|
|
|
|
node.value = value
|
|
|
|
node.set_protection.return_value = False
|
|
|
|
|
|
|
|
resp = await client.post(
|
|
|
|
'/api/zwave/protection/18', data=json.dumps({
|
|
|
|
'value_id': '123456', 'selection': 'Protecton by Seuence'}))
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = await resp.json()
|
|
|
|
assert not node.set_protection.called
|
|
|
|
assert result == {'message': 'Node not found'}
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_protection_value_missing_class(hass, client):
|
|
|
|
"""Test setting protection value on node without protectionclass."""
|
|
|
|
network = hass.data[DATA_NETWORK] = MagicMock()
|
|
|
|
node = MockNode(node_id=17)
|
|
|
|
value = MockValue(
|
|
|
|
value_id=123456,
|
|
|
|
index=0,
|
|
|
|
instance=1)
|
|
|
|
network.nodes = {17: node}
|
|
|
|
node.value = value
|
|
|
|
node.set_protection.return_value = False
|
|
|
|
|
|
|
|
resp = await client.post(
|
|
|
|
'/api/zwave/protection/17', data=json.dumps({
|
|
|
|
'value_id': '123456', 'selection': 'Protecton by Seuence'}))
|
|
|
|
|
|
|
|
assert resp.status == 404
|
|
|
|
result = await resp.json()
|
|
|
|
assert not node.set_protection.called
|
|
|
|
assert result == {'message': 'No protection commandclass on this node'}
|