node-zwave-js icon indicating copy to clipboard operation
node-zwave-js copied to clipboard

feat(cc): allow setting either `defaultToneId` or `defaultVolume` in Sound Switch CC

Open Copilot opened this issue 2 months ago • 2 comments

Description

The setConfiguration API supports sentinel values to modify only one parameter while preserving the other, but both parameters were required. This made the API unnecessarily verbose.

Changes

  • Added method overloads to SoundSwitchCCAPI.setConfiguration() to ensure at least one parameter must be specified:
    • setConfiguration(defaultToneId: number, defaultVolume?: number)
    • setConfiguration(defaultToneId: number | undefined, defaultVolume: number)
  • Applied appropriate sentinel defaults when parameters are omitted:
    • defaultToneId0x00 (preserve current tone)
    • defaultVolume0xff (preserve current volume)
  • Updated SoundSwitchCCConfigurationSetOptions to use a union type that enforces at least one parameter must be specified:
    export type SoundSwitchCCConfigurationSetOptions = {
      defaultVolume: number;
      defaultToneId?: number;
    } | {
      defaultVolume?: number;
      defaultToneId: number;
    };
    
  • Updated SoundSwitchCCConfigurationSet constructor to reflect optional properties

Usage

// Before: had to pass sentinel values explicitly
await api.setConfiguration(5, 0xff);  // Change tone only
await api.setConfiguration(0x00, 50); // Change volume only

// After: omit what you want to preserve
await api.setConfiguration(5);        // Change tone only
await api.setConfiguration(undefined, 50); // Change volume only
Original prompt

This section details on the original issue you should resolve

<issue_title>Sound Switch CC: setConfiguration should have both params optional</issue_title> <issue_description>The API has sentinel values for each that allow changing one parameter without changing the other.

For changing the volume only, pass 0 as the tone ID. For changing the default tone ID only, pass 0xff as the volume.</issue_description>

<agent_instructions>Make both function arguments optional (use ?:)</agent_instructions>

Comments on the Issue (you are @copilot in this section)

  • Fixes zwave-js/zwave-js#8483

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Dec 10 '25 09:12 Copilot

@copilot remove the test file.

Add overloads to setConfiguration:...

Done in 3caf934. Removed the test file and added the overloads as specified.

Copilot avatar Dec 10 '25 10:12 Copilot

@copilot SoundSwitchCCConfigurationSetOptions should be updated accordingly:

export type SoundSwitchCCConfigurationSetOptions = {...

Done in 55539f8. Updated SoundSwitchCCConfigurationSetOptions to use the union type as specified.

Copilot avatar Dec 10 '25 11:12 Copilot