Skip to content
Snippets Groups Projects
Unverified Commit fc1ed7d7 authored by Raman Gupta's avatar Raman Gupta Committed by GitHub
Browse files

Refactor targets for zwave_js services (#115734)

* Let labels be used as targets for zwave_js services

* add coverage

* Fix test bug and switch from targets to fields

* Remove label addition

* Remove labels from service descriptions

* Remove labels from strings

* More changes
parent 281a9f04
No related branches found
No related tags found
No related merge requests found
......@@ -343,20 +343,18 @@ def async_get_nodes_from_area_id(
}
)
# Add devices in an area that are Z-Wave JS devices
for device in dr.async_entries_for_area(dev_reg, area_id):
if next(
(
config_entry_id
for config_entry_id in device.config_entries
if cast(
ConfigEntry,
hass.config_entries.async_get_entry(config_entry_id),
).domain
== DOMAIN
),
None,
):
nodes.add(async_get_node_from_device_id(hass, device.id, dev_reg))
nodes.update(
async_get_node_from_device_id(hass, device.id, dev_reg)
for device in dr.async_entries_for_area(dev_reg, area_id)
if any(
cast(
ConfigEntry,
hass.config_entries.async_get_entry(config_entry_id),
).domain
== DOMAIN
for config_entry_id in device.config_entries
)
)
return nodes
......
......@@ -48,6 +48,12 @@ _LOGGER = logging.getLogger(__name__)
type _NodeOrEndpointType = ZwaveNode | Endpoint
TARGET_VALIDATORS = {
vol.Optional(ATTR_AREA_ID): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(ATTR_DEVICE_ID): vol.All(cv.ensure_list, [cv.string]),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
}
def parameter_name_does_not_need_bitmask(
val: dict[str, int | str | list[str]],
......@@ -261,13 +267,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Optional(const.ATTR_ENDPOINT, default=0): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_PARAMETER): vol.Any(
vol.Coerce(int), cv.string
......@@ -305,13 +305,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Optional(const.ATTR_ENDPOINT, default=0): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_PARAMETER): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_VALUE): vol.Any(
......@@ -356,13 +350,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Required(const.ATTR_COMMAND_CLASS): vol.Coerce(int),
vol.Required(const.ATTR_PROPERTY): vol.Any(
vol.Coerce(int), str
......@@ -391,13 +379,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Optional(const.ATTR_BROADCAST, default=False): cv.boolean,
vol.Required(const.ATTR_COMMAND_CLASS): vol.Coerce(int),
vol.Required(const.ATTR_PROPERTY): vol.Any(
......@@ -428,15 +410,7 @@ class ZWaveServices:
self.async_ping,
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
},
TARGET_VALIDATORS,
cv.has_at_least_one_key(
ATTR_DEVICE_ID, ATTR_ENTITY_ID, ATTR_AREA_ID
),
......@@ -453,13 +427,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Required(const.ATTR_COMMAND_CLASS): vol.All(
vol.Coerce(int), vol.Coerce(CommandClass)
),
......@@ -483,13 +451,7 @@ class ZWaveServices:
schema=vol.Schema(
vol.All(
{
vol.Optional(ATTR_AREA_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_DEVICE_ID): vol.All(
cv.ensure_list, [cv.string]
),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
**TARGET_VALIDATORS,
vol.Required(const.ATTR_NOTIFICATION_TYPE): vol.All(
vol.Coerce(int), vol.Coerce(NotificationType)
),
......
......@@ -89,10 +89,28 @@ set_lock_configuration:
boolean:
set_config_parameter:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
endpoint:
example: 1
default: 0
......@@ -127,10 +145,28 @@ set_config_parameter:
max: 3
bulk_set_partial_config_parameters:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
endpoint:
example: 1
default: 0
......@@ -169,10 +205,28 @@ refresh_value:
boolean:
set_value:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
command_class:
example: 117
required: true
......@@ -208,10 +262,28 @@ set_value:
boolean:
multicast_set_value:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
broadcast:
example: true
required: false
......@@ -248,9 +320,28 @@ multicast_set_value:
object:
ping:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
reset_meter:
target:
......@@ -258,6 +349,30 @@ reset_meter:
domain: sensor
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
entity:
- integration: zwave_js
domain: sensor
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
entity:
- integration: zwave_js
domain: sensor
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
domain: sensor
multiple: true
meter_type:
example: 1
required: false
......@@ -270,10 +385,28 @@ reset_meter:
text:
invoke_cc_api:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
command_class:
example: 132
required: true
......@@ -296,10 +429,28 @@ invoke_cc_api:
object:
refresh_notifications:
target:
entity:
integration: zwave_js
fields:
area_id:
example: living_room
selector:
area:
device:
- integration: zwave_js
multiple: true
device_id:
example: "8f4219cfa57e23f6f669c4616c2205e2"
selector:
device:
filter:
- integration: zwave_js
multiple: true
entity_id:
example: sensor.living_room_temperature
selector:
entity:
filter:
- integration: zwave_js
multiple: true
notification_type:
example: 1
required: true
......
......@@ -265,10 +265,22 @@
"bulk_set_partial_config_parameters": {
"description": "Allows for bulk setting partial parameters. Useful when multiple partial parameters have to be set at the same time.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"endpoint": {
"description": "[%key:component::zwave_js::services::set_config_parameter::fields::endpoint::description%]",
"name": "[%key:component::zwave_js::services::set_config_parameter::fields::endpoint::name%]"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
},
"parameter": {
"description": "[%key:component::zwave_js::services::set_config_parameter::fields::parameter::description%]",
"name": "[%key:component::zwave_js::services::set_config_parameter::fields::parameter::name%]"
......@@ -293,14 +305,26 @@
"invoke_cc_api": {
"description": "Calls a Command Class API on a node. Some Command Classes can't be fully controlled via the `set_value` action and require direct calls to the Command Class API.",
"fields": {
"area_id": {
"description": "The area(s) to target for this service. If an area is specified, all zwave_js devices and entities in that area will be targeted for this service.",
"name": "Area ID(s)"
},
"command_class": {
"description": "The ID of the command class that you want to issue a command to.",
"name": "[%key:component::zwave_js::services::set_value::fields::command_class::name%]"
},
"device_id": {
"description": "The device(s) to target for this service.",
"name": "Device ID(s)"
},
"endpoint": {
"description": "The endpoint to call the API on. If an endpoint is specified, that endpoint will be targeted for all nodes associated with the target areas, devices, and/or entities. If an endpoint is not specified, the root endpoint (0) will be targeted for nodes associated with target areas and devices, and the endpoint for the primary value of each entity will be targeted.",
"name": "[%key:component::zwave_js::services::set_config_parameter::fields::endpoint::name%]"
},
"entity_id": {
"description": "The entity ID(s) to target for this service.",
"name": "Entity ID(s)"
},
"method_name": {
"description": "The name of the API method to call. Refer to the Z-Wave JS Command Class API documentation (https://zwave-js.github.io/node-zwave-js/#/api/CCs/index) for available methods.",
"name": "Method name"
......@@ -315,6 +339,10 @@
"multicast_set_value": {
"description": "Changes any value that Z-Wave JS recognizes on multiple Z-Wave devices using multicast, so all devices receive the message simultaneously. This action has minimal validation so only use this action if you know what you are doing.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"broadcast": {
"description": "Whether command should be broadcast to all devices on the network.",
"name": "Broadcast?"
......@@ -323,10 +351,18 @@
"description": "[%key:component::zwave_js::services::set_value::fields::command_class::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::command_class::name%]"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"endpoint": {
"description": "[%key:component::zwave_js::services::set_value::fields::endpoint::description%]",
"name": "[%key:component::zwave_js::services::set_config_parameter::fields::endpoint::name%]"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
},
"options": {
"description": "[%key:component::zwave_js::services::set_value::fields::options::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::options::name%]"
......@@ -348,11 +384,37 @@
},
"ping": {
"description": "Forces Z-Wave JS to try to reach a node. This can be used to update the status of the node in Z-Wave JS when you think it doesn't accurately reflect reality, e.g. reviving a failed/dead node or marking the node as asleep.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
}
},
"name": "Ping a node"
},
"refresh_notifications": {
"description": "Refreshes notifications on a node based on notification type and optionally notification event.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
},
"notification_event": {
"description": "The Notification Event number as defined in the Z-Wave specs.",
"name": "Notification Event"
......@@ -381,6 +443,18 @@
"reset_meter": {
"description": "Resets the meters on a node.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
},
"meter_type": {
"description": "The type of meter to reset. Not all meters support the ability to pick a meter type to reset.",
"name": "Meter type"
......@@ -395,14 +469,26 @@
"set_config_parameter": {
"description": "Changes the configuration parameters of your Z-Wave devices.",
"fields": {
"area_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::area_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::area_id::name%]"
},
"bitmask": {
"description": "Target a specific bitmask (see the documentation for more information). Cannot be combined with value_size or value_format.",
"name": "Bitmask"
},
"device_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::device_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::device_id::name%]"
},
"endpoint": {
"description": "The configuration parameter's endpoint.",
"name": "Endpoint"
},
"entity_id": {
"description": "[%key:component::zwave_js::services::set_value::fields::entity_id::description%]",
"name": "[%key:component::zwave_js::services::set_value::fields::entity_id::name%]"
},
"parameter": {
"description": "The name (or ID) of the configuration parameter you want to configure.",
"name": "Parameter"
......@@ -477,14 +563,26 @@
"set_value": {
"description": "Changes any value that Z-Wave JS recognizes on a Z-Wave device. This action has minimal validation so only use this action if you know what you are doing.",
"fields": {
"area_id": {
"description": "The area(s) to target for this service. If an area is specified, all zwave_js devices and entities in that area will be targeted for this service.",
"name": "Area ID(s)"
},
"command_class": {
"description": "The ID of the command class for the value.",
"name": "Command class"
},
"device_id": {
"description": "The device(s) to target for this service.",
"name": "Device ID(s)"
},
"endpoint": {
"description": "The endpoint for the value.",
"name": "[%key:component::zwave_js::services::set_config_parameter::fields::endpoint::name%]"
},
"entity_id": {
"description": "The entity ID(s) to target for this service.",
"name": "Entity ID(s)"
},
"options": {
"description": "Set value options map. Refer to the Z-Wave JS documentation for more information on what options can be set.",
"name": "Options"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment