diff --git a/homeassistant/components/zwave_js/device_action.py b/homeassistant/components/zwave_js/device_action.py index 9f6fa7fc35c..b81d675e6fd 100644 --- a/homeassistant/components/zwave_js/device_action.py +++ b/homeassistant/components/zwave_js/device_action.py @@ -53,6 +53,7 @@ from .const import ( from .device_automation_helpers import ( CONF_SUBTYPE, VALUE_ID_REGEX, + generate_config_parameter_subtype, get_config_parameter_value_schema, ) 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, ATTR_CONFIG_PARAMETER: config_value.property_, 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() ] diff --git a/homeassistant/components/zwave_js/device_automation_helpers.py b/homeassistant/components/zwave_js/device_automation_helpers.py index cfdb65a4b02..906efb2c4f9 100644 --- a/homeassistant/components/zwave_js/device_automation_helpers.py +++ b/homeassistant/components/zwave_js/device_automation_helpers.py @@ -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 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})" diff --git a/homeassistant/components/zwave_js/device_condition.py b/homeassistant/components/zwave_js/device_condition.py index fcd769dc8a4..ec8538e2b36 100644 --- a/homeassistant/components/zwave_js/device_condition.py +++ b/homeassistant/components/zwave_js/device_condition.py @@ -29,6 +29,7 @@ from .device_automation_helpers import ( CONF_SUBTYPE, CONF_VALUE_ID, NODE_STATUSES, + generate_config_parameter_subtype, get_config_parameter_value_schema, ) from .helpers import ( @@ -140,17 +141,18 @@ async def async_get_conditions( conditions.append({**base_condition, CONF_TYPE: NODE_STATUS_TYPE}) # Config parameter conditions - conditions.extend( - [ - { - **base_condition, - CONF_VALUE_ID: config_value.value_id, - CONF_TYPE: CONFIG_PARAMETER_TYPE, - CONF_SUBTYPE: f"{config_value.value_id} ({config_value.property_name})", - } - for config_value in node.get_configuration_values().values() - ] - ) + for config_value in node.get_configuration_values().values(): + conditions.extend( + [ + { + **base_condition, + CONF_VALUE_ID: config_value.value_id, + CONF_TYPE: CONFIG_PARAMETER_TYPE, + CONF_SUBTYPE: generate_config_parameter_subtype(config_value), + } + for config_value in node.get_configuration_values().values() + ] + ) return conditions diff --git a/homeassistant/components/zwave_js/device_trigger.py b/homeassistant/components/zwave_js/device_trigger.py index 888efbf2bfd..0615668cccd 100644 --- a/homeassistant/components/zwave_js/device_trigger.py +++ b/homeassistant/components/zwave_js/device_trigger.py @@ -49,7 +49,11 @@ from .const import ( ZWAVE_JS_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 ( async_get_node_from_device_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_ENDPOINT: config_value.endpoint, 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() ] diff --git a/tests/components/zwave_js/test_device_action.py b/tests/components/zwave_js/test_device_action.py index 5377d420268..07663ce9456 100644 --- a/tests/components/zwave_js/test_device_action.py +++ b/tests/components/zwave_js/test_device_action.py @@ -67,7 +67,7 @@ async def test_get_actions( "device_id": device.id, "parameter": 3, "bitmask": None, - "subtype": f"{node.node_id}-112-0-3 (Beeper)", + "subtype": "3 (Beeper)", }, ] actions = await async_get_device_automations( @@ -161,7 +161,7 @@ async def test_actions( "device_id": device.id, "parameter": 1, "bitmask": None, - "subtype": "2-112-0-3 (Beeper)", + "subtype": "3 (Beeper)", "value": 1, }, }, @@ -328,7 +328,6 @@ async def test_get_action_capabilities( integration: ConfigEntry, ): """Test we get the expected action capabilities.""" - node = climate_radio_thermostat_ct100_plus dev_reg = device_registry.async_get(hass) device = device_registry.async_entries_for_config_entry( dev_reg, integration.entry_id @@ -423,7 +422,7 @@ async def test_get_action_capabilities( "type": "set_config_parameter", "parameter": 1, "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 @@ -455,7 +454,7 @@ async def test_get_action_capabilities( "type": "set_config_parameter", "parameter": 10, "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 @@ -482,7 +481,7 @@ async def test_get_action_capabilities( "type": "set_config_parameter", "parameter": 2, "bitmask": None, - "subtype": f"{node.node_id}-112-0-2 (HVAC Settings)", + "subtype": "2 (HVAC Settings)", }, ) assert not capabilities diff --git a/tests/components/zwave_js/test_device_condition.py b/tests/components/zwave_js/test_device_condition.py index 71a6865287c..da6b4b15459 100644 --- a/tests/components/zwave_js/test_device_condition.py +++ b/tests/components/zwave_js/test_device_condition.py @@ -52,7 +52,7 @@ async def test_get_conditions(hass, client, lock_schlage_be469, integration) -> "type": "config_parameter", "device_id": device.id, "value_id": value_id, - "subtype": f"{value_id} ({name})", + "subtype": f"{config_value.property_} ({name})", }, { "condition": "device", @@ -250,7 +250,7 @@ async def test_config_parameter_state( "device_id": device.id, "type": "config_parameter", "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, } ], @@ -270,7 +270,7 @@ async def test_config_parameter_state( "device_id": device.id, "type": "config_parameter", "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, } ], @@ -483,7 +483,7 @@ async def test_get_condition_capabilities_config_parameter( "device_id": device.id, "type": "config_parameter", "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 @@ -514,7 +514,7 @@ async def test_get_condition_capabilities_config_parameter( "device_id": device.id, "type": "config_parameter", "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 @@ -540,7 +540,7 @@ async def test_get_condition_capabilities_config_parameter( "device_id": device.id, "type": "config_parameter", "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 diff --git a/tests/components/zwave_js/test_device_trigger.py b/tests/components/zwave_js/test_device_trigger.py index bf3738a7fb3..8a792706461 100644 --- a/tests/components/zwave_js/test_device_trigger.py +++ b/tests/components/zwave_js/test_device_trigger.py @@ -1120,7 +1120,6 @@ async def test_get_value_updated_config_parameter_triggers( hass, client, lock_schlage_be469, integration ): """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) device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0] expected_trigger = { @@ -1132,7 +1131,7 @@ async def test_get_value_updated_config_parameter_triggers( "property_key": None, "endpoint": 0, "command_class": CommandClass.CONFIGURATION.value, - "subtype": f"{node.node_id}-112-0-3 (Beeper)", + "subtype": "3 (Beeper)", } triggers = await async_get_device_automations( hass, DeviceAutomationType.TRIGGER, device.id @@ -1163,7 +1162,7 @@ async def test_if_value_updated_config_parameter_fires( "property_key": None, "endpoint": 0, "command_class": CommandClass.CONFIGURATION.value, - "subtype": f"{node.node_id}-112-0-3 (Beeper)", + "subtype": "3 (Beeper)", "from": 255, }, "action": { @@ -1212,7 +1211,6 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_range( hass, client, lock_schlage_be469, integration ): """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) device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0] 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, "endpoint": 0, "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 @@ -1255,7 +1253,6 @@ async def test_get_trigger_capabilities_value_updated_config_parameter_enumerate hass, client, lock_schlage_be469, integration ): """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) device = async_entries_for_config_entry(dev_reg, integration.entry_id)[0] 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, "endpoint": 0, "command_class": CommandClass.CONFIGURATION.value, - "subtype": f"{node.node_id}-112-0-3 (Beeper)", + "subtype": "3 (Beeper)", }, ) assert capabilities and "extra_fields" in capabilities