Add cancel_command service for OpenZWave (#41285)

* Add cancel_command service for OpenZWave

* Raise ValueError if instance is None
This commit is contained in:
Charles Garwood 2020-10-06 08:05:52 -04:00 committed by GitHub
parent 34416fcad3
commit 356ebc1128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -40,6 +40,7 @@ ATTR_SCENE_VALUE_LABEL = "scene_value_label"
# Service specific
SERVICE_ADD_NODE = "add_node"
SERVICE_REMOVE_NODE = "remove_node"
SERVICE_CANCEL_COMMAND = "cancel_command"
SERVICE_SET_CONFIG_PARAMETER = "set_config_parameter"
# Home Assistant Events

View File

@ -43,6 +43,14 @@ class ZWaveServices:
{vol.Optional(const.ATTR_INSTANCE_ID, default=1): vol.Coerce(int)}
),
)
self._hass.services.async_register(
const.DOMAIN,
const.SERVICE_CANCEL_COMMAND,
self.async_cancel_command,
schema=vol.Schema(
{vol.Optional(const.ATTR_INSTANCE_ID, default=1): vol.Coerce(int)}
),
)
self._hass.services.async_register(
const.DOMAIN,
@ -111,3 +119,12 @@ class ZWaveServices:
instance_id = service.data[const.ATTR_INSTANCE_ID]
instance = self._manager.get_instance(instance_id)
instance.remove_node()
@callback
def async_cancel_command(self, service):
"""Tell the controller to cancel an add or remove command."""
instance_id = service.data[const.ATTR_INSTANCE_ID]
instance = self._manager.get_instance(instance_id)
if instance is None:
raise ValueError(f"No OpenZWave Instance with ID {instance_id}")
instance.cancel_controller_command()

View File

@ -13,6 +13,12 @@ remove_node:
instance_id:
description: (Optional) The OZW Instance/Controller to use, defaults to 1.
cancel_command:
description: Cancel a pending add or remove node command.
fields:
instance_id:
description: (Optional) The OZW Instance/Controller to use, defaults to 1.
set_config_parameter:
description: Set a config parameter to a node on the Z-Wave network.
fields: