Skip to content

Commit

Permalink
Add heal_node and test_node services. (#10369)
Browse files Browse the repository at this point in the history
* Add heal_node and test_node services.

* lint
  • Loading branch information
turbokongen authored and balloob committed Nov 5, 2017
1 parent bc51bd9 commit c07e651
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
37 changes: 37 additions & 0 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
vol.All(vol.Coerce(int), cv.positive_int),
})

HEAL_NODE_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Optional(const.ATTR_RETURN_ROUTES, default=False): cv.boolean,
})

TEST_NODE_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Optional(const.ATTR_MESSAGES, default=1): cv.positive_int,
})


DEVICE_CONFIG_SCHEMA_ENTRY = vol.Schema({
vol.Optional(CONF_POLLING_INTENSITY): cv.positive_int,
vol.Optional(CONF_IGNORED, default=DEFAULT_CONF_IGNORED): cv.boolean,
Expand Down Expand Up @@ -564,6 +575,22 @@ def reset_node_meters(service):
_LOGGER.info("Node %s on instance %s does not have resettable "
"meters.", node_id, instance)

def heal_node(service):
"""Heal a node on the network."""
node_id = service.data.get(const.ATTR_NODE_ID)
update_return_routes = service.data.get(const.ATTR_RETURN_ROUTES)
node = network.nodes[node_id]
_LOGGER.info("Z-Wave node heal running for node %s", node_id)
node.heal(update_return_routes)

def test_node(service):
"""Send test messages to a node on the network."""
node_id = service.data.get(const.ATTR_NODE_ID)
messages = service.data.get(const.ATTR_MESSAGES)
node = network.nodes[node_id]
_LOGGER.info("Sending %s test-messages to node %s.", messages, node_id)
node.test(messages)

def start_zwave(_service_or_event):
"""Startup Z-Wave network."""
_LOGGER.info("Starting Z-Wave network...")
Expand Down Expand Up @@ -684,6 +711,16 @@ def start_zwave(_service_or_event):
set_poll_intensity,
descriptions[const.SERVICE_SET_POLL_INTENSITY],
schema=SET_POLL_INTENSITY_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_HEAL_NODE,
heal_node,
descriptions[
const.SERVICE_HEAL_NODE],
schema=HEAL_NODE_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_TEST_NODE,
test_node,
descriptions[
const.SERVICE_TEST_NODE],
schema=TEST_NODE_SCHEMA)

# Setup autoheal
if autoheal:
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/zwave/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
ATTR_GROUP = "group"
ATTR_VALUE_ID = "value_id"
ATTR_OBJECT_ID = "object_id"
ATTR_MESSAGES = "messages"
ATTR_NAME = "name"
ATTR_RETURN_ROUTES = "return_routes"
ATTR_SCENE_ID = "scene_id"
ATTR_SCENE_DATA = "scene_data"
ATTR_BASIC_LEVEL = "basic_level"
Expand All @@ -32,7 +34,9 @@
SERVICE_REMOVE_NODE = "remove_node"
SERVICE_CANCEL_COMMAND = "cancel_command"
SERVICE_HEAL_NETWORK = "heal_network"
SERVICE_HEAL_NODE = "heal_node"
SERVICE_SOFT_RESET = "soft_reset"
SERVICE_TEST_NODE = "test_node"
SERVICE_TEST_NETWORK = "test_network"
SERVICE_SET_CONFIG_PARAMETER = "set_config_parameter"
SERVICE_PRINT_CONFIG_PARAMETER = "print_config_parameter"
Expand Down
21 changes: 21 additions & 0 deletions homeassistant/components/zwave/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ cancel_command:

heal_network:
description: Start a Z-Wave network heal. This might take a while and will slow down the Z-Wave network greatly while it is being processed. Refer to OZW.log for progress.
fields:
return_routes:
description: Wheter or not to update the return routes from the nodes to the controller. Defaults to False.
example: True

heal_node:
description: Start a Z-Wave node heal. Refer to OZW.log for progress.
fields:
return_routes:
description: Wheter or not to update the return routes from the node to the controller. Defaults to False.
example: True

remove_node:
description: Remove a node from the Z-Wave network. Refer to OZW.log for progress.
Expand Down Expand Up @@ -120,6 +131,16 @@ soft_reset:
test_network:
description: This will send test to nodes in the Z-Wave network. This will greatly slow down the Z-Wave network while it is being processed. Refer to OZW.log for progress.

test_node:
description: This will send test messages to a node in the Z-Wave network. This could bring back dead nodes.
fields:
node_id:
description: ID of the node to send test messages to.
example: 10
messages:
description: Optional. Amount of test messages to send.
example: 3

rename_node:
description: Set the name of a node. This will also affect the IDs of all entities in the node.
fields:
Expand Down
24 changes: 24 additions & 0 deletions tests/components/zwave/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,3 +1253,27 @@ def test_refresh_node(self):

assert node.refresh_info.called
assert len(node.refresh_info.mock_calls) == 1

def test_heal_node(self):
"""Test zwave heal_node service."""
node = MockNode(node_id=19)
self.zwave_network.nodes = {19: node}
self.hass.services.call('zwave', 'heal_node', {
const.ATTR_NODE_ID: 19,
})
self.hass.block_till_done()

assert node.heal.called
assert len(node.heal.mock_calls) == 1

def test_test_node(self):
"""Test the zwave test_node service."""
node = MockNode(node_id=19)
self.zwave_network.nodes = {19: node}
self.hass.services.call('zwave', 'test_node', {
const.ATTR_NODE_ID: 19,
})
self.hass.block_till_done()

assert node.test.called
assert len(node.test.mock_calls) == 1

0 comments on commit c07e651

Please sign in to comment.