mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add missing Short type to set_config_param (#38618)
* Add missing Short type to set_config_param * Forgot to fix the for loop * Remove leftover return * Guard the for loop * Changed from if to else * Fixed list iteration for validating input * Adjusted per linter
This commit is contained in:
parent
ef039d6a65
commit
597d1e2799
@ -68,73 +68,60 @@ class ZWaveServices:
|
|||||||
selection = service.data[const.ATTR_CONFIG_VALUE]
|
selection = service.data[const.ATTR_CONFIG_VALUE]
|
||||||
payload = None
|
payload = None
|
||||||
|
|
||||||
node = self._manager.get_instance(instance_id).get_node(node_id).values()
|
value = (
|
||||||
|
self._manager.get_instance(instance_id)
|
||||||
|
.get_node(node_id)
|
||||||
|
.get_value(CommandClass.CONFIGURATION, param)
|
||||||
|
)
|
||||||
|
|
||||||
for value in node:
|
if value.type == ValueType.BOOL:
|
||||||
if (
|
payload = selection == "True"
|
||||||
value.command_class != CommandClass.CONFIGURATION
|
|
||||||
or value.index != param
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if value.type == ValueType.BOOL:
|
if value.type == ValueType.LIST:
|
||||||
payload = selection == "True"
|
# accept either string from the list value OR the int value
|
||||||
|
for selected in value.value["List"]:
|
||||||
|
if selection not in (selected["Label"], selected["Value"]):
|
||||||
|
continue
|
||||||
|
payload = int(selected["Value"])
|
||||||
|
|
||||||
if value.type == ValueType.LIST:
|
if payload is None:
|
||||||
# accept either string from the list value OR the int value
|
_LOGGER.error(
|
||||||
if isinstance(selection, int):
|
"Invalid value %s for parameter %s", selection, param,
|
||||||
if selection > value.max or selection < value.min:
|
)
|
||||||
_LOGGER.error(
|
|
||||||
"Value %s out of range for parameter %s (Min: %s Max: %s)",
|
|
||||||
selection,
|
|
||||||
param,
|
|
||||||
value.min,
|
|
||||||
value.max,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
payload = int(selection)
|
|
||||||
|
|
||||||
# iterate list labels to get value
|
|
||||||
for selected in value.value["List"]:
|
|
||||||
if selected["Label"] != selection:
|
|
||||||
continue
|
|
||||||
payload = int(selected["Value"])
|
|
||||||
|
|
||||||
if payload is None:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Invalid value %s for parameter %s", selection, param,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
if value.type == ValueType.BUTTON:
|
|
||||||
# Unsupported at this time
|
|
||||||
_LOGGER.info("Button type not supported yet")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if value.type == ValueType.STRING:
|
if value.type == ValueType.BUTTON:
|
||||||
payload = selection
|
# Unsupported at this time
|
||||||
|
_LOGGER.info("Button type not supported yet")
|
||||||
if value.type == ValueType.INT or value.type == ValueType.BYTE:
|
|
||||||
if selection > value.max or selection < value.min:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Value %s out of range for parameter %s (Min: %s Max: %s)",
|
|
||||||
selection,
|
|
||||||
param,
|
|
||||||
value.min,
|
|
||||||
value.max,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
payload = int(selection)
|
|
||||||
|
|
||||||
value.send_value(payload) # send the payload
|
|
||||||
_LOGGER.info(
|
|
||||||
"Setting configuration parameter %s on Node %s with value %s",
|
|
||||||
param,
|
|
||||||
node_id,
|
|
||||||
payload,
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if value.type == ValueType.STRING:
|
||||||
|
payload = selection
|
||||||
|
|
||||||
|
if (
|
||||||
|
value.type == ValueType.INT
|
||||||
|
or value.type == ValueType.BYTE
|
||||||
|
or value.type == ValueType.SHORT
|
||||||
|
):
|
||||||
|
if selection > value.max or selection < value.min:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Value %s out of range for parameter %s (Min: %s Max: %s)",
|
||||||
|
selection,
|
||||||
|
param,
|
||||||
|
value.min,
|
||||||
|
value.max,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
payload = int(selection)
|
||||||
|
|
||||||
|
value.send_value(payload) # send the payload
|
||||||
|
_LOGGER.info(
|
||||||
|
"Setting configuration parameter %s on Node %s with value %s",
|
||||||
|
param,
|
||||||
|
node_id,
|
||||||
|
payload,
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_node(self, service):
|
def async_add_node(self, service):
|
||||||
"""Enter inclusion mode on the controller."""
|
"""Enter inclusion mode on the controller."""
|
||||||
|
@ -2,61 +2,61 @@
|
|||||||
from .common import setup_ozw
|
from .common import setup_ozw
|
||||||
|
|
||||||
|
|
||||||
async def test_services(hass, lock_data, sent_messages, lock_msg, caplog):
|
async def test_services(hass, light_data, sent_messages, light_msg, caplog):
|
||||||
"""Test services on lock."""
|
"""Test services on lock."""
|
||||||
await setup_ozw(hass, fixture=lock_data)
|
await setup_ozw(hass, fixture=light_data)
|
||||||
|
|
||||||
# Test set_config_parameter list by label
|
# Test set_config_parameter list by label
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 1, "value": "Disabled"},
|
{"node_id": 39, "parameter": 1, "value": "Disable"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 1
|
assert len(sent_messages) == 1
|
||||||
msg = sent_messages[0]
|
msg = sent_messages[0]
|
||||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
assert msg["payload"] == {"Value": 0, "ValueIDKey": 281475154706452}
|
assert msg["payload"] == {"Value": 0, "ValueIDKey": 281475641245716}
|
||||||
|
|
||||||
# Test set_config_parameter list by index int
|
# Test set_config_parameter list by index int
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 1, "value": 0},
|
{"node_id": 39, "parameter": 1, "value": 1},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 2
|
assert len(sent_messages) == 2
|
||||||
msg = sent_messages[1]
|
msg = sent_messages[1]
|
||||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
assert msg["payload"] == {"Value": 0, "ValueIDKey": 281475154706452}
|
assert msg["payload"] == {"Value": 1, "ValueIDKey": 281475641245716}
|
||||||
|
|
||||||
# Test set_config_parameter int
|
# Test set_config_parameter int
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 6, "value": 0},
|
{"node_id": 39, "parameter": 3, "value": 55},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 3
|
assert len(sent_messages) == 3
|
||||||
msg = sent_messages[2]
|
msg = sent_messages[2]
|
||||||
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
assert msg["payload"] == {"Value": 0, "ValueIDKey": 1688850038259731}
|
assert msg["payload"] == {"Value": 55, "ValueIDKey": 844425594667027}
|
||||||
|
|
||||||
# Test set_config_parameter invalid list int
|
# Test set_config_parameter invalid list int
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 1, "value": 12},
|
{"node_id": 39, "parameter": 1, "value": 12},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 3
|
assert len(sent_messages) == 3
|
||||||
assert "Value 12 out of range for parameter 1" in caplog.text
|
assert "Invalid value 12 for parameter 1" in caplog.text
|
||||||
|
|
||||||
# Test set_config_parameter invalid list string
|
# Test set_config_parameter invalid list string
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 1, "value": "Blah"},
|
{"node_id": 39, "parameter": 1, "value": "Blah"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 3
|
assert len(sent_messages) == 3
|
||||||
@ -66,8 +66,32 @@ async def test_services(hass, lock_data, sent_messages, lock_msg, caplog):
|
|||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"ozw",
|
"ozw",
|
||||||
"set_config_parameter",
|
"set_config_parameter",
|
||||||
{"node_id": 10, "parameter": 6, "value": 2147483657},
|
{"node_id": 39, "parameter": 3, "value": 2147483657},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(sent_messages) == 3
|
assert len(sent_messages) == 3
|
||||||
assert "Value 12 out of range for parameter 1" in caplog.text
|
assert "Value 2147483657 out of range for parameter 3" in caplog.text
|
||||||
|
|
||||||
|
# Test set_config_parameter short
|
||||||
|
await hass.services.async_call(
|
||||||
|
"ozw",
|
||||||
|
"set_config_parameter",
|
||||||
|
{"node_id": 39, "parameter": 81, "value": 3000},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert len(sent_messages) == 4
|
||||||
|
msg = sent_messages[3]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 3000, "ValueIDKey": 22799473778098198}
|
||||||
|
|
||||||
|
# Test set_config_parameter byte
|
||||||
|
await hass.services.async_call(
|
||||||
|
"ozw",
|
||||||
|
"set_config_parameter",
|
||||||
|
{"node_id": 39, "parameter": 16, "value": 20},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert len(sent_messages) == 5
|
||||||
|
msg = sent_messages[4]
|
||||||
|
assert msg["topic"] == "OpenZWave/1/command/setvalue/"
|
||||||
|
assert msg["payload"] == {"Value": 20, "ValueIDKey": 4503600291905553}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user