Improve zwave_js device automation strings for config parameters (#66428)
* Improve zwave_js device automation strings for config parameters * rename things to be more clear * Match config file format
This commit is contained in:
parent
7cb0ce0eec
commit
113c3149c4
7 changed files with 45 additions and 33 deletions
|
@ -53,6 +53,7 @@ from .const import (
|
||||||
from .device_automation_helpers import (
|
from .device_automation_helpers import (
|
||||||
CONF_SUBTYPE,
|
CONF_SUBTYPE,
|
||||||
VALUE_ID_REGEX,
|
VALUE_ID_REGEX,
|
||||||
|
generate_config_parameter_subtype,
|
||||||
get_config_parameter_value_schema,
|
get_config_parameter_value_schema,
|
||||||
)
|
)
|
||||||
from .helpers import async_get_node_from_device_id
|
from .helpers import async_get_node_from_device_id
|
||||||
|
@ -165,7 +166,7 @@ async def async_get_actions(hass: HomeAssistant, device_id: str) -> list[dict]:
|
||||||
CONF_TYPE: SERVICE_SET_CONFIG_PARAMETER,
|
CONF_TYPE: SERVICE_SET_CONFIG_PARAMETER,
|
||||||
ATTR_CONFIG_PARAMETER: config_value.property_,
|
ATTR_CONFIG_PARAMETER: config_value.property_,
|
||||||
ATTR_CONFIG_PARAMETER_BITMASK: config_value.property_key,
|
ATTR_CONFIG_PARAMETER_BITMASK: config_value.property_key,
|
||||||
CONF_SUBTYPE: f"{config_value.value_id} ({config_value.property_name})",
|
CONF_SUBTYPE: generate_config_parameter_subtype(config_value),
|
||||||
}
|
}
|
||||||
for config_value in node.get_configuration_values().values()
|
for config_value in node.get_configuration_values().values()
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,3 +32,12 @@ def get_config_parameter_value_schema(node: Node, value_id: str) -> vol.Schema |
|
||||||
return vol.In({int(k): v for k, v in config_value.metadata.states.items()})
|
return vol.In({int(k): v for k, v in config_value.metadata.states.items()})
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config_parameter_subtype(config_value: ConfigurationValue) -> str:
|
||||||
|
"""Generate the config parameter name used in a device automation subtype."""
|
||||||
|
parameter = str(config_value.property_)
|
||||||
|
if config_value.property_key:
|
||||||
|
parameter = f"{parameter}[{hex(config_value.property_key)}]"
|
||||||
|
|
||||||
|
return f"{parameter} ({config_value.property_name})"
|
||||||
|
|
|
@ -29,6 +29,7 @@ from .device_automation_helpers import (
|
||||||
CONF_SUBTYPE,
|
CONF_SUBTYPE,
|
||||||
CONF_VALUE_ID,
|
CONF_VALUE_ID,
|
||||||
NODE_STATUSES,
|
NODE_STATUSES,
|
||||||
|
generate_config_parameter_subtype,
|
||||||
get_config_parameter_value_schema,
|
get_config_parameter_value_schema,
|
||||||
)
|
)
|
||||||
from .helpers import (
|
from .helpers import (
|
||||||
|
@ -140,17 +141,18 @@ async def async_get_conditions(
|
||||||
conditions.append({**base_condition, CONF_TYPE: NODE_STATUS_TYPE})
|
conditions.append({**base_condition, CONF_TYPE: NODE_STATUS_TYPE})
|
||||||
|
|
||||||
# Config parameter conditions
|
# Config parameter conditions
|
||||||
conditions.extend(
|
for config_value in node.get_configuration_values().values():
|
||||||
[
|
conditions.extend(
|
||||||
{
|
[
|
||||||
**base_condition,
|
{
|
||||||
CONF_VALUE_ID: config_value.value_id,
|
**base_condition,
|
||||||
CONF_TYPE: CONFIG_PARAMETER_TYPE,
|
CONF_VALUE_ID: config_value.value_id,
|
||||||
CONF_SUBTYPE: f"{config_value.value_id} ({config_value.property_name})",
|
CONF_TYPE: CONFIG_PARAMETER_TYPE,
|
||||||
}
|
CONF_SUBTYPE: generate_config_parameter_subtype(config_value),
|
||||||
for config_value in node.get_configuration_values().values()
|
}
|
||||||
]
|
for config_value in node.get_configuration_values().values()
|
||||||
)
|
]
|
||||||
|
)
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,11 @@ from .const import (
|
||||||
ZWAVE_JS_NOTIFICATION_EVENT,
|
ZWAVE_JS_NOTIFICATION_EVENT,
|
||||||
ZWAVE_JS_VALUE_NOTIFICATION_EVENT,
|
ZWAVE_JS_VALUE_NOTIFICATION_EVENT,
|
||||||
)
|
)
|
||||||
from .device_automation_helpers import CONF_SUBTYPE, NODE_STATUSES
|
from .device_automation_helpers import (
|
||||||
|
CONF_SUBTYPE,
|
||||||
|
NODE_STATUSES,
|
||||||
|
generate_config_parameter_subtype,
|
||||||
|
)
|
||||||
from .helpers import (
|
from .helpers import (
|
||||||
async_get_node_from_device_id,
|
async_get_node_from_device_id,
|
||||||
async_get_node_status_sensor_entity_id,
|
async_get_node_status_sensor_entity_id,
|
||||||
|
@ -353,7 +357,7 @@ async def async_get_triggers(
|
||||||
ATTR_PROPERTY_KEY: config_value.property_key,
|
ATTR_PROPERTY_KEY: config_value.property_key,
|
||||||
ATTR_ENDPOINT: config_value.endpoint,
|
ATTR_ENDPOINT: config_value.endpoint,
|
||||||
ATTR_COMMAND_CLASS: config_value.command_class,
|
ATTR_COMMAND_CLASS: config_value.command_class,
|
||||||
CONF_SUBTYPE: f"{config_value.value_id} ({config_value.property_name})",
|
CONF_SUBTYPE: generate_config_parameter_subtype(config_value),
|
||||||
}
|
}
|
||||||
for config_value in node.get_configuration_values().values()
|
for config_value in node.get_configuration_values().values()
|
||||||
]
|
]
|
||||||
|
|
|
@ -67,7 +67,7 @@ async def test_get_actions(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"parameter": 3,
|
"parameter": 3,
|
||||||
"bitmask": None,
|
"bitmask": None,
|
||||||
"subtype": f"{node.node_id}-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
actions = await async_get_device_automations(
|
actions = await async_get_device_automations(
|
||||||
|
@ -161,7 +161,7 @@ async def test_actions(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"parameter": 1,
|
"parameter": 1,
|
||||||
"bitmask": None,
|
"bitmask": None,
|
||||||
"subtype": "2-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
"value": 1,
|
"value": 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -328,7 +328,6 @@ async def test_get_action_capabilities(
|
||||||
integration: ConfigEntry,
|
integration: ConfigEntry,
|
||||||
):
|
):
|
||||||
"""Test we get the expected action capabilities."""
|
"""Test we get the expected action capabilities."""
|
||||||
node = climate_radio_thermostat_ct100_plus
|
|
||||||
dev_reg = device_registry.async_get(hass)
|
dev_reg = device_registry.async_get(hass)
|
||||||
device = device_registry.async_entries_for_config_entry(
|
device = device_registry.async_entries_for_config_entry(
|
||||||
dev_reg, integration.entry_id
|
dev_reg, integration.entry_id
|
||||||
|
@ -423,7 +422,7 @@ async def test_get_action_capabilities(
|
||||||
"type": "set_config_parameter",
|
"type": "set_config_parameter",
|
||||||
"parameter": 1,
|
"parameter": 1,
|
||||||
"bitmask": None,
|
"bitmask": None,
|
||||||
"subtype": f"{node.node_id}-112-0-1 (Temperature Reporting Threshold)",
|
"subtype": "1 (Temperature Reporting Threshold)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
@ -455,7 +454,7 @@ async def test_get_action_capabilities(
|
||||||
"type": "set_config_parameter",
|
"type": "set_config_parameter",
|
||||||
"parameter": 10,
|
"parameter": 10,
|
||||||
"bitmask": None,
|
"bitmask": None,
|
||||||
"subtype": f"{node.node_id}-112-0-10 (Temperature Reporting Filter)",
|
"subtype": "10 (Temperature Reporting Filter)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
@ -482,7 +481,7 @@ async def test_get_action_capabilities(
|
||||||
"type": "set_config_parameter",
|
"type": "set_config_parameter",
|
||||||
"parameter": 2,
|
"parameter": 2,
|
||||||
"bitmask": None,
|
"bitmask": None,
|
||||||
"subtype": f"{node.node_id}-112-0-2 (HVAC Settings)",
|
"subtype": "2 (HVAC Settings)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert not capabilities
|
assert not capabilities
|
||||||
|
|
|
@ -52,7 +52,7 @@ async def test_get_conditions(hass, client, lock_schlage_be469, integration) ->
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"value_id": value_id,
|
"value_id": value_id,
|
||||||
"subtype": f"{value_id} ({name})",
|
"subtype": f"{config_value.property_} ({name})",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"condition": "device",
|
"condition": "device",
|
||||||
|
@ -250,7 +250,7 @@ async def test_config_parameter_state(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"value_id": f"{lock_schlage_be469.node_id}-112-0-3",
|
"value_id": f"{lock_schlage_be469.node_id}-112-0-3",
|
||||||
"subtype": f"{lock_schlage_be469.node_id}-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
"value": 255,
|
"value": 255,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -270,7 +270,7 @@ async def test_config_parameter_state(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"value_id": f"{lock_schlage_be469.node_id}-112-0-6",
|
"value_id": f"{lock_schlage_be469.node_id}-112-0-6",
|
||||||
"subtype": f"{lock_schlage_be469.node_id}-112-0-6 (User Slot Status)",
|
"subtype": "6 (User Slot Status)",
|
||||||
"value": 1,
|
"value": 1,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -483,7 +483,7 @@ async def test_get_condition_capabilities_config_parameter(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"value_id": f"{node.node_id}-112-0-1",
|
"value_id": f"{node.node_id}-112-0-1",
|
||||||
"subtype": f"{node.node_id}-112-0-1 (Temperature Reporting Threshold)",
|
"subtype": "1 (Temperature Reporting Threshold)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
@ -514,7 +514,7 @@ async def test_get_condition_capabilities_config_parameter(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"value_id": f"{node.node_id}-112-0-10",
|
"value_id": f"{node.node_id}-112-0-10",
|
||||||
"subtype": f"{node.node_id}-112-0-10 (Temperature Reporting Filter)",
|
"subtype": "10 (Temperature Reporting Filter)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
@ -540,7 +540,7 @@ async def test_get_condition_capabilities_config_parameter(
|
||||||
"device_id": device.id,
|
"device_id": device.id,
|
||||||
"type": "config_parameter",
|
"type": "config_parameter",
|
||||||
"value_id": f"{node.node_id}-112-0-2",
|
"value_id": f"{node.node_id}-112-0-2",
|
||||||
"subtype": f"{node.node_id}-112-0-2 (HVAC Settings)",
|
"subtype": "2 (HVAC Settings)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert not capabilities
|
assert not capabilities
|
||||||
|
|
|
@ -1120,7 +1120,6 @@ async def test_get_value_updated_config_parameter_triggers(
|
||||||
hass, client, lock_schlage_be469, integration
|
hass, client, lock_schlage_be469, integration
|
||||||
):
|
):
|
||||||
"""Test we get the zwave_js.value_updated.config_parameter trigger from a zwave_js device."""
|
"""Test we get the zwave_js.value_updated.config_parameter trigger from a zwave_js device."""
|
||||||
node = lock_schlage_be469
|
|
||||||
dev_reg = async_get_dev_reg(hass)
|
dev_reg = async_get_dev_reg(hass)
|
||||||
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
||||||
expected_trigger = {
|
expected_trigger = {
|
||||||
|
@ -1132,7 +1131,7 @@ async def test_get_value_updated_config_parameter_triggers(
|
||||||
"property_key": None,
|
"property_key": None,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"command_class": CommandClass.CONFIGURATION.value,
|
"command_class": CommandClass.CONFIGURATION.value,
|
||||||
"subtype": f"{node.node_id}-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
}
|
}
|
||||||
triggers = await async_get_device_automations(
|
triggers = await async_get_device_automations(
|
||||||
hass, DeviceAutomationType.TRIGGER, device.id
|
hass, DeviceAutomationType.TRIGGER, device.id
|
||||||
|
@ -1163,7 +1162,7 @@ async def test_if_value_updated_config_parameter_fires(
|
||||||
"property_key": None,
|
"property_key": None,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"command_class": CommandClass.CONFIGURATION.value,
|
"command_class": CommandClass.CONFIGURATION.value,
|
||||||
"subtype": f"{node.node_id}-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
"from": 255,
|
"from": 255,
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
|
@ -1212,7 +1211,6 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_range(
|
||||||
hass, client, lock_schlage_be469, integration
|
hass, client, lock_schlage_be469, integration
|
||||||
):
|
):
|
||||||
"""Test we get the expected capabilities from a range zwave_js.value_updated.config_parameter trigger."""
|
"""Test we get the expected capabilities from a range zwave_js.value_updated.config_parameter trigger."""
|
||||||
node = lock_schlage_be469
|
|
||||||
dev_reg = async_get_dev_reg(hass)
|
dev_reg = async_get_dev_reg(hass)
|
||||||
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
||||||
capabilities = await device_trigger.async_get_trigger_capabilities(
|
capabilities = await device_trigger.async_get_trigger_capabilities(
|
||||||
|
@ -1226,7 +1224,7 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_range(
|
||||||
"property_key": None,
|
"property_key": None,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"command_class": CommandClass.CONFIGURATION.value,
|
"command_class": CommandClass.CONFIGURATION.value,
|
||||||
"subtype": f"{node.node_id}-112-0-6 (User Slot Status)",
|
"subtype": "6 (User Slot Status)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
@ -1255,7 +1253,6 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_enumerate
|
||||||
hass, client, lock_schlage_be469, integration
|
hass, client, lock_schlage_be469, integration
|
||||||
):
|
):
|
||||||
"""Test we get the expected capabilities from an enumerated zwave_js.value_updated.config_parameter trigger."""
|
"""Test we get the expected capabilities from an enumerated zwave_js.value_updated.config_parameter trigger."""
|
||||||
node = lock_schlage_be469
|
|
||||||
dev_reg = async_get_dev_reg(hass)
|
dev_reg = async_get_dev_reg(hass)
|
||||||
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0]
|
||||||
capabilities = await device_trigger.async_get_trigger_capabilities(
|
capabilities = await device_trigger.async_get_trigger_capabilities(
|
||||||
|
@ -1269,7 +1266,7 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_enumerate
|
||||||
"property_key": None,
|
"property_key": None,
|
||||||
"endpoint": 0,
|
"endpoint": 0,
|
||||||
"command_class": CommandClass.CONFIGURATION.value,
|
"command_class": CommandClass.CONFIGURATION.value,
|
||||||
"subtype": f"{node.node_id}-112-0-3 (Beeper)",
|
"subtype": "3 (Beeper)",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert capabilities and "extra_fields" in capabilities
|
assert capabilities and "extra_fields" in capabilities
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue