Add zwave.network_complete_some_dead event (#16894)

* Add zwave.network_complete_some_dead event

* add missing comma

* typo

* Add SIGNAL_AWAKE_NODES_QUERIED_SOME_DEAD Test

* Add blank lines

* fix linter warnings

Line too long

* remove trailing whitespace

* Change test signal

* Listen to other event
pull/16954/head
Jan van Helvoort 2018-09-28 19:14:57 +02:00 committed by John Arild Berentsen
parent af89e7c50f
commit 7d1960baba
4 changed files with 42 additions and 2 deletions

View File

@ -275,7 +275,9 @@ async def async_setup(hass, config):
ZWaveNetwork.SIGNAL_SCENE_EVENT,
ZWaveNetwork.SIGNAL_NODE_EVENT,
ZWaveNetwork.SIGNAL_AWAKE_NODES_QUERIED,
ZWaveNetwork.SIGNAL_ALL_NODES_QUERIED):
ZWaveNetwork.SIGNAL_ALL_NODES_QUERIED,
ZWaveNetwork
.SIGNAL_ALL_NODES_QUERIED_SOME_DEAD):
pprint(_obj_to_dict(value))
print("")
@ -356,6 +358,12 @@ async def async_setup(hass, config):
"have been queried")
hass.bus.fire(const.EVENT_NETWORK_COMPLETE)
def network_complete_some_dead():
"""Handle the querying of all nodes on network."""
_LOGGER.info("Z-Wave network is complete. All nodes on the network "
"have been queried, but some node are marked dead")
hass.bus.fire(const.EVENT_NETWORK_COMPLETE_SOME_DEAD)
dispatcher.connect(
value_added, ZWaveNetwork.SIGNAL_VALUE_ADDED, weak=False)
dispatcher.connect(
@ -364,6 +372,9 @@ async def async_setup(hass, config):
network_ready, ZWaveNetwork.SIGNAL_AWAKE_NODES_QUERIED, weak=False)
dispatcher.connect(
network_complete, ZWaveNetwork.SIGNAL_ALL_NODES_QUERIED, weak=False)
dispatcher.connect(
network_complete_some_dead,
ZWaveNetwork.SIGNAL_ALL_NODES_QUERIED_SOME_DEAD, weak=False)
def add_node(service):
"""Switch into inclusion mode."""

View File

@ -60,6 +60,7 @@ EVENT_SCENE_ACTIVATED = "zwave.scene_activated"
EVENT_NODE_EVENT = "zwave.node_event"
EVENT_NETWORK_READY = "zwave.network_ready"
EVENT_NETWORK_COMPLETE = "zwave.network_complete"
EVENT_NETWORK_COMPLETE_SOME_DEAD = "zwave.network_complete_some_dead"
EVENT_NETWORK_START = "zwave.network_start"
EVENT_NETWORK_STOP = "zwave.network_stop"

View File

@ -458,6 +458,33 @@ def test_network_complete(hass, mock_openzwave):
assert len(events) == 1
@asyncio.coroutine
def test_network_complete_some_dead(hass, mock_openzwave):
"""Test Node network complete some dead event."""
mock_receivers = []
def mock_connect(receiver, signal, *args, **kwargs):
if signal == MockNetwork.SIGNAL_ALL_NODES_QUERIED_SOME_DEAD:
mock_receivers.append(receiver)
with patch('pydispatch.dispatcher.connect', new=mock_connect):
yield from async_setup_component(hass, 'zwave', {'zwave': {}})
assert len(mock_receivers) == 1
events = []
def listener(event):
events.append(event)
hass.bus.async_listen(const.EVENT_NETWORK_COMPLETE_SOME_DEAD, listener)
hass.async_add_job(mock_receivers[0])
yield from hass.async_block_till_done()
assert len(events) == 1
class TestZWaveDeviceEntityValues(unittest.TestCase):
"""Tests for the ZWaveDeviceEntityValues helper."""

View File

@ -88,7 +88,8 @@ class MockNetwork(MagicMock):
SIGNAL_NODE_QUERIES_COMPLETE = 'mock_NodeQueriesComplete'
SIGNAL_AWAKE_NODES_QUERIED = 'mock_AwakeNodesQueried'
SIGNAL_ALL_NODES_QUERIED = 'mock_AllNodesQueried'
SIGNAL_ALL_NODES_QUERIED_SOME_DEAD = 'mock_AllNodesQueriedSomeDead'
SIGNAL_ALL_NODES_QUERIED_SOME_DEAD = \
'mock_AllNodesQueriedSomeDead'
SIGNAL_MSG_COMPLETE = 'mock_MsgComplete'
SIGNAL_NOTIFICATION = 'mock_Notification'
SIGNAL_CONTROLLER_COMMAND = 'mock_ControllerCommand'