zap icon indicating copy to clipboard operation
zap copied to clipboard

Refactor Matter-specific code into a separate file

Open ethanzhouyc opened this issue 1 year ago • 0 comments

Issue: ZAP backend functions include Matter-specific logic, such as handling featureMap shown below, which contains Matter terminology from Matter spec and is irrelevant to Zigbee. However, these functions support both Zigbee and Matter.

Solution: All Matter-specific code should be encapsulated into functions and moved to a separate file for improved modularity and maintainability.

// Looking for the feature map attribute in matter and setting it as per
  // the device types if default value is 0
  if (
    staticAttribute.code == 0xfffc &&
    staticAttribute.name == 'FeatureMap' &&
    staticAttribute.defaultValue == 0
  ) {
    let featureMapDefaultValue = staticAttribute.defaultValue
    let featuresOnEndpointTypeAndCluster =
      await queryDeviceType.selectDeviceTypeFeaturesByEndpointTypeIdAndClusterId(
        db,
        endpointTypeId,
        clusterRef
      )
    // only set featureMap bit to 1 for mandatory features
    let featureMapBitsToBeEnabled = featuresOnEndpointTypeAndCluster
      .filter((f) => f.conformance == 'M')
      .map((f) => f.featureBit)
    featureMapBitsToBeEnabled.forEach(
      (featureBit) =>
        (featureMapDefaultValue = featureMapDefaultValue | (1 << featureBit))
    )
    staticAttribute.defaultValue = featureMapDefaultValue
  }

ethanzhouyc avatar Nov 21 '24 17:11 ethanzhouyc