mirror of
https://github.com/elisspace/core.git
synced 2026-10-05 08:46:29 +00:00
Change behavior of Z-Wave JS services (#52941)
* Change behavior of Z-Wave JS services * pop parameters in for loop * Update logger message
This commit is contained in:
@@ -261,31 +261,7 @@ async def test_set_config_parameter(hass, client, multisensor_6, integration):
|
||||
}
|
||||
assert args["value"] == 1
|
||||
|
||||
# Test that an invalid entity ID raises a MultipleInvalid
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_ENTITY_ID: "sensor.fake_entity",
|
||||
ATTR_CONFIG_PARAMETER: "Temperature Threshold (Unit)",
|
||||
ATTR_CONFIG_VALUE: "Fahrenheit",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
# Test that an invalid device ID raises a MultipleInvalid
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_DEVICE_ID: "fake_device_id",
|
||||
ATTR_CONFIG_PARAMETER: "Temperature Threshold (Unit)",
|
||||
ATTR_CONFIG_VALUE: "Fahrenheit",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
client.async_send_command_no_wait.reset_mock()
|
||||
|
||||
# Test that we can't include a bitmask value if parameter is a string
|
||||
with pytest.raises(vol.Invalid):
|
||||
@@ -308,36 +284,10 @@ async def test_set_config_parameter(hass, client, multisensor_6, integration):
|
||||
identifiers={("test", "test")},
|
||||
)
|
||||
|
||||
# Test that a non Z-Wave JS device raises a MultipleInvalid
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_DEVICE_ID: non_zwave_js_device.id,
|
||||
ATTR_CONFIG_PARAMETER: "Temperature Threshold (Unit)",
|
||||
ATTR_CONFIG_VALUE: "Fahrenheit",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
zwave_js_device_with_invalid_node_id = dev_reg.async_get_or_create(
|
||||
config_entry_id=integration.entry_id, identifiers={(DOMAIN, "500-500")}
|
||||
)
|
||||
|
||||
# Test that a Z-Wave JS device with an invalid node ID raises a MultipleInvalid
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_DEVICE_ID: zwave_js_device_with_invalid_node_id.id,
|
||||
ATTR_CONFIG_PARAMETER: "Temperature Threshold (Unit)",
|
||||
ATTR_CONFIG_VALUE: "Fahrenheit",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
non_zwave_js_entity = ent_reg.async_get_or_create(
|
||||
"test",
|
||||
"sensor",
|
||||
@@ -346,18 +296,59 @@ async def test_set_config_parameter(hass, client, multisensor_6, integration):
|
||||
config_entry=non_zwave_js_config_entry,
|
||||
)
|
||||
|
||||
# Test that a non Z-Wave JS entity raises a MultipleInvalid
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_ENTITY_ID: non_zwave_js_entity.entity_id,
|
||||
ATTR_CONFIG_PARAMETER: "Temperature Threshold (Unit)",
|
||||
ATTR_CONFIG_VALUE: "Fahrenheit",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
# Test that a Z-Wave JS device with an invalid node ID, non Z-Wave JS entity,
|
||||
# non Z-Wave JS device, invalid device_id, and invalid node_id gets filtered out.
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_CONFIG_PARAMETER,
|
||||
{
|
||||
ATTR_ENTITY_ID: [
|
||||
AIR_TEMPERATURE_SENSOR,
|
||||
non_zwave_js_entity.entity_id,
|
||||
"sensor.fake",
|
||||
],
|
||||
ATTR_DEVICE_ID: [
|
||||
zwave_js_device_with_invalid_node_id.id,
|
||||
non_zwave_js_device.id,
|
||||
"fake_device_id",
|
||||
],
|
||||
ATTR_CONFIG_PARAMETER: 102,
|
||||
ATTR_CONFIG_PARAMETER_BITMASK: "0x01",
|
||||
ATTR_CONFIG_VALUE: 1,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command_no_wait.call_args_list) == 1
|
||||
args = client.async_send_command_no_wait.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
assert args["nodeId"] == 52
|
||||
assert args["valueId"] == {
|
||||
"commandClassName": "Configuration",
|
||||
"commandClass": 112,
|
||||
"endpoint": 0,
|
||||
"property": 102,
|
||||
"propertyName": "Group 2: Send battery reports",
|
||||
"propertyKey": 1,
|
||||
"metadata": {
|
||||
"type": "number",
|
||||
"readable": True,
|
||||
"writeable": True,
|
||||
"valueSize": 4,
|
||||
"min": 0,
|
||||
"max": 1,
|
||||
"default": 1,
|
||||
"format": 0,
|
||||
"allowManualEntry": True,
|
||||
"label": "Group 2: Send battery reports",
|
||||
"description": "Include battery information in periodic reports to Group 2",
|
||||
"isFromConfig": True,
|
||||
},
|
||||
"value": 0,
|
||||
}
|
||||
assert args["value"] == 1
|
||||
|
||||
client.async_send_command_no_wait.reset_mock()
|
||||
|
||||
# Test that when a device is awake, we call async_send_command instead of
|
||||
# async_send_command_no_wait
|
||||
@@ -862,19 +853,24 @@ async def test_multicast_set_value(
|
||||
|
||||
client.async_send_command.reset_mock()
|
||||
|
||||
# Test sending one node without broadcast fails
|
||||
with pytest.raises(vol.Invalid):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_MULTICAST_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: CLIMATE_DANFOSS_LC13_ENTITY,
|
||||
ATTR_COMMAND_CLASS: 117,
|
||||
ATTR_PROPERTY: "local",
|
||||
ATTR_VALUE: 2,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
# Test sending one node without broadcast uses the node.set_value command instead
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_MULTICAST_SET_VALUE,
|
||||
{
|
||||
ATTR_ENTITY_ID: CLIMATE_DANFOSS_LC13_ENTITY,
|
||||
ATTR_COMMAND_CLASS: 117,
|
||||
ATTR_PROPERTY: "local",
|
||||
ATTR_VALUE: 2,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert len(client.async_send_command_no_wait.call_args_list) == 1
|
||||
args = client.async_send_command_no_wait.call_args[0][0]
|
||||
assert args["command"] == "node.set_value"
|
||||
|
||||
client.async_send_command_no_wait.reset_mock()
|
||||
|
||||
# Test no device, entity, or broadcast flag raises error
|
||||
with pytest.raises(vol.Invalid):
|
||||
|
||||
Reference in New Issue
Block a user