Add ability to set Zwave protection commandclass (#15390)
* Add API for protection commandclass * Adjusting * tests * Spelling * Missed flake8 * Period * spelling * Review changes * removing additional .keys() * period * Move i/o out into executor pool * Move i/o out into executor pool * Forgot get method * Do it right... I feel stupid * Long lines * Merging
This commit is contained in:
1 parent
3204501174
commit
1b94fe3613
2 files changed
+246
No files matched your search
@@ -367,3 +367,192 @@ def test_save_config(hass, client):
|
||||
result = yield from resp.json()
|
||||
assert network.write_config.called
|
||||
assert result == {'message': 'Z-Wave configuration saved to file.'}
|
||||
|
||||
|
||||
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'}
|
||||
Reference in new issue
Block a user