Is it possible to set the custom capability max value dynamically from the driver?

For a capability for current_limit the target device can be configured in hardware for 16A or 32A in addition depending on connected cable type, it may change to for example 20A.

{
  "type": "number",
  "title": {
    "en": "Current Limit",
  },
  "getable": true,
  "setable": true,
  "min": 6,
  "max": 32,
  "step": 1,
  "units": {
    "en": "A"
  },
  "uiComponent": "slider",
}

For above capability, I would like to be able set the max value on the fly. Can it be done directly on the capability, or do I need to remove and add it back with new limit?

And answer is yes:

const currentLimitOpts = await this.getCapabilityOptions('current_limit');
// Check for device's maximum current configuration and adjust device current_limit capability maximum setting value.
// Only update if different.
if(currentLimitOpts.max !== deviceInfo.current_max) {
  this.log(`[Device] ${this.getName()}: ${this.getData().id} setCurrentLimitOpts Max: '${deviceInfo.current_max}'`);
  await this.setCapabilityOptions('current_limit', { max: deviceInfo.current_max })
}

deviceInfo has been read from the device earlier.

1 Like