mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add zwave_js ping node service (#51435)
* Add zwave_js ping node service * uncomment code * use asyncio.gather
This commit is contained in:
parent
b1fa01e4bc
commit
f00f2b4ae4
@ -62,4 +62,6 @@ SERVICE_MULTICAST_SET_VALUE = "multicast_set_value"
|
|||||||
|
|
||||||
ATTR_BROADCAST = "broadcast"
|
ATTR_BROADCAST = "broadcast"
|
||||||
|
|
||||||
|
SERVICE_PING = "ping"
|
||||||
|
|
||||||
ADDON_SLUG = "core_zwave_js"
|
ADDON_SLUG = "core_zwave_js"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Methods and classes related to executing Z-Wave commands and publishing these to hass."""
|
"""Methods and classes related to executing Z-Wave commands and publishing these to hass."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -294,6 +295,24 @@ class ZWaveServices:
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._hass.services.async_register(
|
||||||
|
const.DOMAIN,
|
||||||
|
const.SERVICE_PING,
|
||||||
|
self.async_ping,
|
||||||
|
schema=vol.Schema(
|
||||||
|
vol.All(
|
||||||
|
{
|
||||||
|
vol.Optional(ATTR_DEVICE_ID): vol.All(
|
||||||
|
cv.ensure_list, [cv.string]
|
||||||
|
),
|
||||||
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
|
},
|
||||||
|
cv.has_at_least_one_key(ATTR_DEVICE_ID, ATTR_ENTITY_ID),
|
||||||
|
get_nodes_from_service_data,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
async def async_set_config_parameter(self, service: ServiceCall) -> None:
|
async def async_set_config_parameter(self, service: ServiceCall) -> None:
|
||||||
"""Set a config value on a node."""
|
"""Set a config value on a node."""
|
||||||
nodes = service.data[const.ATTR_NODES]
|
nodes = service.data[const.ATTR_NODES]
|
||||||
@ -418,3 +437,8 @@ class ZWaveServices:
|
|||||||
|
|
||||||
if success is False:
|
if success is False:
|
||||||
raise SetValueFailed("Unable to set value via multicast")
|
raise SetValueFailed("Unable to set value via multicast")
|
||||||
|
|
||||||
|
async def async_ping(self, service: ServiceCall) -> None:
|
||||||
|
"""Ping node(s)."""
|
||||||
|
nodes: set[ZwaveNode] = service.data[const.ATTR_NODES]
|
||||||
|
await asyncio.gather(*[node.async_ping() for node in nodes])
|
||||||
|
@ -210,3 +210,10 @@ multicast_set_value:
|
|||||||
required: true
|
required: true
|
||||||
selector:
|
selector:
|
||||||
object:
|
object:
|
||||||
|
|
||||||
|
ping:
|
||||||
|
name: Ping a node
|
||||||
|
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.
|
||||||
|
target:
|
||||||
|
entity:
|
||||||
|
integration: zwave_js
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.components.zwave_js.const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_BULK_SET_PARTIAL_CONFIG_PARAMETERS,
|
SERVICE_BULK_SET_PARTIAL_CONFIG_PARAMETERS,
|
||||||
SERVICE_MULTICAST_SET_VALUE,
|
SERVICE_MULTICAST_SET_VALUE,
|
||||||
|
SERVICE_PING,
|
||||||
SERVICE_REFRESH_VALUE,
|
SERVICE_REFRESH_VALUE,
|
||||||
SERVICE_SET_CONFIG_PARAMETER,
|
SERVICE_SET_CONFIG_PARAMETER,
|
||||||
SERVICE_SET_VALUE,
|
SERVICE_SET_VALUE,
|
||||||
@ -790,3 +791,43 @@ async def test_multicast_set_value(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_ping(
|
||||||
|
hass,
|
||||||
|
client,
|
||||||
|
climate_danfoss_lc_13,
|
||||||
|
climate_radio_thermostat_ct100_plus_different_endpoints,
|
||||||
|
integration,
|
||||||
|
):
|
||||||
|
"""Test ping service."""
|
||||||
|
client.async_send_command.return_value = {"responded": True}
|
||||||
|
|
||||||
|
# Test successful ping call
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PING,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: [
|
||||||
|
CLIMATE_DANFOSS_LC13_ENTITY,
|
||||||
|
CLIMATE_RADIO_THERMOSTAT_ENTITY,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(client.async_send_command.call_args_list) == 2
|
||||||
|
args = client.async_send_command.call_args[0][0]
|
||||||
|
assert args["command"] == "node.ping"
|
||||||
|
assert args["nodeId"] == climate_danfoss_lc_13.node_id
|
||||||
|
|
||||||
|
client.async_send_command.reset_mock()
|
||||||
|
|
||||||
|
# Test no device or entity raises error
|
||||||
|
with pytest.raises(vol.Invalid):
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_PING,
|
||||||
|
{},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user