From 356ebc112885302b5f4bdd8131ba238ed5468a6a Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Tue, 6 Oct 2020 08:05:52 -0400 Subject: [PATCH] Add cancel_command service for OpenZWave (#41285) * Add cancel_command service for OpenZWave * Raise ValueError if instance is None --- homeassistant/components/ozw/const.py | 1 + homeassistant/components/ozw/services.py | 17 +++++++++++++++++ homeassistant/components/ozw/services.yaml | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/homeassistant/components/ozw/const.py b/homeassistant/components/ozw/const.py index 5164bbbe044..8e5007a8419 100644 --- a/homeassistant/components/ozw/const.py +++ b/homeassistant/components/ozw/const.py @@ -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 diff --git a/homeassistant/components/ozw/services.py b/homeassistant/components/ozw/services.py index fc3a9ee5ed4..9f66c3c33fd 100644 --- a/homeassistant/components/ozw/services.py +++ b/homeassistant/components/ozw/services.py @@ -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() diff --git a/homeassistant/components/ozw/services.yaml b/homeassistant/components/ozw/services.yaml index d7f5c540c67..641c086f524 100644 --- a/homeassistant/components/ozw/services.yaml +++ b/homeassistant/components/ozw/services.yaml @@ -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: