diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 0e6e41c63a5..2faeccde154 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -123,6 +123,17 @@ SET_WAKEUP_SCHEMA = vol.Schema({ 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, @@ -564,6 +575,22 @@ def setup(hass, config): _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...") @@ -684,6 +711,16 @@ def setup(hass, config): 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: diff --git a/homeassistant/components/zwave/const.py b/homeassistant/components/zwave/const.py index dced1689dba..5f0a7f4750b 100644 --- a/homeassistant/components/zwave/const.py +++ b/homeassistant/components/zwave/const.py @@ -8,7 +8,9 @@ ATTR_INSTANCE = "instance" 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" @@ -32,7 +34,9 @@ SERVICE_ADD_NODE_SECURE = "add_node_secure" 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" diff --git a/homeassistant/components/zwave/services.yaml b/homeassistant/components/zwave/services.yaml index 06e317333be..ba8e177c9f7 100644 --- a/homeassistant/components/zwave/services.yaml +++ b/homeassistant/components/zwave/services.yaml @@ -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. @@ -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: diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index 1e759949a46..ce2795297a2 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -1253,3 +1253,27 @@ class TestZWaveServices(unittest.TestCase): 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