From cdf18bd4b1f98367b5225dbde195aa19d06bd2a7 Mon Sep 17 00:00:00 2001 From: shbatm Date: Wed, 19 May 2021 19:08:35 -0500 Subject: [PATCH] Add Z-Wave Parameter and Node Rename Services to ISY994 (#50844) --- homeassistant/components/isy994/entity.py | 21 ++++++ homeassistant/components/isy994/services.py | 52 ++++++++++++++ homeassistant/components/isy994/services.yaml | 70 +++++++++++++++++++ 3 files changed, 143 insertions(+) diff --git a/homeassistant/components/isy994/entity.py b/homeassistant/components/isy994/entity.py index 6dab5b2ed65..69714dd9f4b 100644 --- a/homeassistant/components/isy994/entity.py +++ b/homeassistant/components/isy994/entity.py @@ -179,6 +179,27 @@ class ISYNodeEntity(ISYEntity): ) await self._node.send_cmd(command, value, unit_of_measurement, parameters) + async def async_get_zwave_parameter(self, parameter): + """Repsond to an entity service command to request a Z-Wave device parameter from the ISY.""" + if not hasattr(self._node, "protocol") or self._node.protocol != PROTO_ZWAVE: + raise HomeAssistantError( + f"Invalid service call: cannot request Z-Wave Parameter for non-Z-Wave device {self.entity_id}" + ) + await self._node.get_zwave_parameter(parameter) + + async def async_set_zwave_parameter(self, parameter, value, size): + """Repsond to an entity service command to set a Z-Wave device parameter via the ISY.""" + if not hasattr(self._node, "protocol") or self._node.protocol != PROTO_ZWAVE: + raise HomeAssistantError( + f"Invalid service call: cannot set Z-Wave Parameter for non-Z-Wave device {self.entity_id}" + ) + await self._node.set_zwave_parameter(parameter, value, size) + await self._node.get_zwave_parameter(parameter) + + async def async_rename_node(self, name): + """Repsond to an entity service command to rename a node on the ISY.""" + await self._node.rename(name) + class ISYProgramEntity(ISYEntity): """Representation of an ISY994 program base.""" diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index 03ecc3930bb..c34e8a1c67b 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -48,15 +48,20 @@ INTEGRATION_SERVICES = [ # Entity specific methods (valid for most Groups/ISY Scenes, Lights, Switches, Fans) SERVICE_SEND_RAW_NODE_COMMAND = "send_raw_node_command" SERVICE_SEND_NODE_COMMAND = "send_node_command" +SERVICE_GET_ZWAVE_PARAMETER = "get_zwave_parameter" +SERVICE_SET_ZWAVE_PARAMETER = "set_zwave_parameter" +SERVICE_RENAME_NODE = "rename_node" # Services valid only for dimmable lights. SERVICE_SET_ON_LEVEL = "set_on_level" SERVICE_SET_RAMP_RATE = "set_ramp_rate" +CONF_PARAMETER = "parameter" CONF_PARAMETERS = "parameters" CONF_VALUE = "value" CONF_INIT = "init" CONF_ISY = "isy" +CONF_SIZE = "size" VALID_NODE_COMMANDS = [ "beep", @@ -81,6 +86,7 @@ VALID_PROGRAM_COMMANDS = [ "enable_run_at_startup", "disable_run_at_startup", ] +VALID_PARAMETER_SIZES = [1, 2, 4] def valid_isy_commands(value: Any) -> str: @@ -116,6 +122,16 @@ SERVICE_SEND_NODE_COMMAND_SCHEMA = { vol.Required(CONF_COMMAND): vol.In(VALID_NODE_COMMANDS) } +SERVICE_RENAME_NODE_SCHEMA = {vol.Required(CONF_NAME): cv.string} + +SERVICE_GET_ZWAVE_PARAMETER_SCHEMA = {vol.Required(CONF_PARAMETER): vol.Coerce(int)} + +SERVICE_SET_ZWAVE_PARAMETER_SCHEMA = { + vol.Required(CONF_PARAMETER): vol.Coerce(int), + vol.Required(CONF_VALUE): vol.Coerce(int), + vol.Required(CONF_SIZE): vol.All(vol.Coerce(int), vol.In(VALID_PARAMETER_SIZES)), +} + SERVICE_SET_VARIABLE_SCHEMA = vol.All( cv.has_at_least_one_key(CONF_ADDRESS, CONF_TYPE, CONF_NAME), vol.Schema( @@ -377,6 +393,42 @@ def async_setup_services(hass: HomeAssistant): # noqa: C901 service_func=_async_send_node_command, ) + async def _async_get_zwave_parameter(call: ServiceCall): + await hass.helpers.service.entity_service_call( + async_get_platforms(hass, DOMAIN), "async_get_zwave_parameter", call + ) + + hass.services.async_register( + domain=DOMAIN, + service=SERVICE_GET_ZWAVE_PARAMETER, + schema=cv.make_entity_service_schema(SERVICE_GET_ZWAVE_PARAMETER_SCHEMA), + service_func=_async_get_zwave_parameter, + ) + + async def _async_set_zwave_parameter(call: ServiceCall): + await hass.helpers.service.entity_service_call( + async_get_platforms(hass, DOMAIN), "async_set_zwave_parameter", call + ) + + hass.services.async_register( + domain=DOMAIN, + service=SERVICE_SET_ZWAVE_PARAMETER, + schema=cv.make_entity_service_schema(SERVICE_SET_ZWAVE_PARAMETER_SCHEMA), + service_func=_async_set_zwave_parameter, + ) + + async def _async_rename_node(call: ServiceCall): + await hass.helpers.service.entity_service_call( + async_get_platforms(hass, DOMAIN), "async_rename_node", call + ) + + hass.services.async_register( + domain=DOMAIN, + service=SERVICE_RENAME_NODE, + schema=cv.make_entity_service_schema(SERVICE_RENAME_NODE_SCHEMA), + service_func=_async_rename_node, + ) + @callback def async_unload_services(hass: HomeAssistant): diff --git a/homeassistant/components/isy994/services.yaml b/homeassistant/components/isy994/services.yaml index c163d78a173..73e0a675e49 100644 --- a/homeassistant/components/isy994/services.yaml +++ b/homeassistant/components/isy994/services.yaml @@ -68,6 +68,76 @@ send_node_command: - "fast_off" - "fast_on" - "query" +get_zwave_parameter: + name: Get Z-Wave Parameter + description: >- + Request a Z-Wave Device parameter via the ISY. The parameter value will be returned as a entity extra state attribute with the name "ZW_#" + where "#" is the parameter number. + target: + entity: + integration: isy994 + fields: + parameter: + name: Parameter + description: The parameter number to retrieve from the device. + example: 8 + selector: + number: + min: 1 + max: 255 +set_zwave_parameter: + name: Set Z-Wave Parameter + description: >- + Update a Z-Wave Device parameter via the ISY. The parameter value will also be returned as a entity extra state attribute with the name "ZW_#" + where "#" is the parameter number. + target: + entity: + integration: isy994 + fields: + parameter: + name: Parameter + description: The parameter number to set on the end device. + required: true + example: 8 + selector: + number: + min: 1 + max: 255 + value: + name: Value + description: The value to set for the parameter. May be an integer or byte string (e.g. "0xFFFF"). + required: true + example: 33491663 + selector: + text: + size: + name: Size + description: The size of the parameter, either 1, 2, or 4 bytes. + required: true + example: 4 + selector: + select: + options: + - "1" + - "2" + - "4" +rename_node: + name: Rename Node on ISY994 + description: >- + Rename a node or group (scene) on the ISY994. Note: this will not automatically change the Home Assistant Entity Name or Entity ID to match. + The entity name and ID will only be updated after calling `isy994.reload` or restarting Home Assistant, and ONLY IF you have not already customized the + name within Home Assistant. + target: + entity: + integration: isy994 + fields: + name: + name: New Name + description: The new name to use within the ISY994. + required: true + example: "Front Door Light" + selector: + text: set_on_level: name: Set On Level description: Send a ISY set_on_level command to a Node.