Apply ColorTempPhysicalMaxMireds when ColorTemperatureMaximumMireds f… (#33983)

* Apply ColorTempPhysicalMaxMireds when ColorTemperatureMaximumMireds field is 0. Add tests

* Restyled by whitespace

* Restyled by prettier-yaml

* Change wait time to 1 sec as rate is calculated in step per second

* Add code comment, fix typo in test command

---------

Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp
index 784bca8..558703a 100644
--- a/src/app/clusters/color-control-server/color-control-server.cpp
+++ b/src/app/clusters/color-control-server/color-control-server.cpp
@@ -2693,11 +2693,16 @@
         return true;
     }
 
+    // Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
+    // when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always >= to 0)
     if (colorTemperatureMinimum < tempPhysicalMin)
     {
         colorTemperatureMinimum = tempPhysicalMin;
     }
-    if (colorTemperatureMaximum > tempPhysicalMax)
+
+    // Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
+    // when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
+    if ((colorTemperatureMaximum == 0) || (colorTemperatureMaximum > tempPhysicalMax))
     {
         colorTemperatureMaximum = tempPhysicalMax;
     }
@@ -2804,11 +2809,16 @@
     Attributes::ColorTempPhysicalMinMireds::Get(endpoint, &tempPhysicalMin);
     Attributes::ColorTempPhysicalMaxMireds::Get(endpoint, &tempPhysicalMax);
 
+    // Per spec, colorTemperatureMinimumMireds field is limited to ColorTempPhysicalMinMireds and
+    // when colorTemperatureMinimumMireds field is 0, ColorTempPhysicalMinMireds shall be used (always >= to 0)
     if (colorTemperatureMinimum < tempPhysicalMin)
     {
         colorTemperatureMinimum = tempPhysicalMin;
     }
-    if (colorTemperatureMaximum > tempPhysicalMax)
+
+    // Per spec, colorTemperatureMaximumMireds field is limited to ColorTempPhysicalMaxMireds and
+    // when colorTemperatureMaximumMireds field is 0, ColorTempPhysicalMaxMireds shall be used
+    if ((colorTemperatureMaximum == 0) || (colorTemperatureMaximum > tempPhysicalMax))
     {
         colorTemperatureMaximum = tempPhysicalMax;
     }
diff --git a/src/app/tests/suites/certification/Test_TC_CC_6_2.yaml b/src/app/tests/suites/certification/Test_TC_CC_6_2.yaml
index fcb4f1c..f525937 100644
--- a/src/app/tests/suites/certification/Test_TC_CC_6_2.yaml
+++ b/src/app/tests/suites/certification/Test_TC_CC_6_2.yaml
@@ -364,6 +364,85 @@
           constraints:
               minValue: 0
               maxValue: 3
+    - label:
+          "Step 6a: TH sends MoveColorTemperature command to DUT with MoveMode =
+          0x03(down), Rate = 65535 (max value) with
+          ColorTemperatureMinimumMireds of 0"
+      PICS: CC.S.F04 && CC.S.C4b.Rsp
+      command: MoveColorTemperature
+      arguments:
+          values:
+              - name: "MoveMode"
+                value: 3
+              - name: "Rate"
+                value: 65535
+              - name: "ColorTemperatureMinimumMireds"
+                value: 0
+              - name: "ColorTemperatureMaximumMireds"
+                value: ColorTempPhysicalMaxMiredsValue
+              - name: "OptionsMask"
+                value: 0
+              - name: "OptionsOverride"
+                value: 0
+
+    - label: "Wait 1s"
+      PICS: CC.S.F04
+      cluster: "DelayCommands"
+      command: "WaitForMs"
+      arguments:
+          values:
+              - name: "ms"
+                value: 1000
+
+    - label: "Step 6b: TH reads ColorTemperatureMireds attribute from DUT."
+      PICS: CC.S.F04 && CC.S.A0007 && CC.S.C4b.Rsp
+      command: "readAttribute"
+      attribute: "ColorTemperatureMireds"
+      response:
+          value: ColorTempPhysicalMinMiredsValue
+          constraints:
+              minValue: ColorTempPhysicalMinMiredsValue
+              maxValue: ColorTempPhysicalMaxMiredsValue
+
+    - label:
+          "Step 7a: TH sends MoveColorTemperature command to DUT with MoveMode =
+          0x01(up), Rate = 65535 (max value) with ColorTemperatureMaximumMireds
+          of 0"
+      PICS: CC.S.F04 && CC.S.C4b.Rsp
+      command: MoveColorTemperature
+      arguments:
+          values:
+              - name: "MoveMode"
+                value: 1
+              - name: "Rate"
+                value: 65535
+              - name: "ColorTemperatureMinimumMireds"
+                value: ColorTempPhysicalMinMiredsValue
+              - name: "ColorTemperatureMaximumMireds"
+                value: 0
+              - name: "OptionsMask"
+                value: 0
+              - name: "OptionsOverride"
+                value: 0
+
+    - label: "Wait 1s"
+      PICS: CC.S.F04
+      cluster: "DelayCommands"
+      command: "WaitForMs"
+      arguments:
+          values:
+              - name: "ms"
+                value: 1000
+
+    - label: "Step 7b: TH reads ColorTemperatureMireds attribute from DUT."
+      PICS: CC.S.F04 && CC.S.A0007 && CC.S.C4b.Rsp
+      command: "readAttribute"
+      attribute: "ColorTemperatureMireds"
+      response:
+          value: ColorTempPhysicalMaxMiredsValue
+          constraints:
+              minValue: ColorTempPhysicalMinMiredsValue
+              maxValue: ColorTempPhysicalMaxMiredsValue
 
     - label: "Turn off light that we turned on"
       PICS: OO.S.C00.Rsp
diff --git a/src/app/tests/suites/certification/Test_TC_CC_6_3.yaml b/src/app/tests/suites/certification/Test_TC_CC_6_3.yaml
index 934a4a3..437ef78 100644
--- a/src/app/tests/suites/certification/Test_TC_CC_6_3.yaml
+++ b/src/app/tests/suites/certification/Test_TC_CC_6_3.yaml
@@ -287,6 +287,90 @@
               minValue: 0
               maxValue: 3
 
+    - label:
+          "Step 5a: TH sends StepColorTemperature command to DUT with StepMode =
+          0x01 (up), StepSize = ColorTempPhysicalMaxMireds and TransitionTime =
+          0 (instant)."
+      PICS: CC.S.F04 && CC.S.C4c.Rsp
+      command: "StepColorTemperature"
+      arguments:
+          values:
+              - name: "StepMode"
+                value: 1
+              - name: "StepSize"
+                value: ColorTempPhysicalMaxMiredsValue
+              - name: "ColorTemperatureMinimumMireds"
+                value: ColorTempPhysicalMinMiredsValue
+              - name: "ColorTemperatureMaximumMireds"
+                value: 0
+              - name: "TransitionTime"
+                value: 0
+              - name: "OptionsMask"
+                value: 0
+              - name: "OptionsOverride"
+                value: 0
+
+    - label: "Wait 100ms"
+      PICS: CC.S.F04
+      cluster: "DelayCommands"
+      command: "WaitForMs"
+      arguments:
+          values:
+              - name: "ms"
+                value: 100
+
+    - label: "Step 5b: TH reads ColorTemperatureMireds attribute from DUT."
+      PICS: CC.S.F04 && CC.S.A0007 && CC.S.C4c.Rsp
+      command: "readAttribute"
+      attribute: "ColorTemperatureMireds"
+      response:
+          value: ColorTempPhysicalMaxMiredsValue
+          constraints:
+              minValue: ColorTempPhysicalMinMiredsValue
+              maxValue: ColorTempPhysicalMaxMiredsValue
+
+    - label:
+          "Step 6a: TH sends StepColorTemperature command to DUT with StepMode =
+          0x03 (down), StepSize = ColorTempPhysicalMaxMireds and TransitionTime
+          = 0 (instant)."
+      PICS: CC.S.F04 && CC.S.C4c.Rsp
+      command: "StepColorTemperature"
+      arguments:
+          values:
+              - name: "StepMode"
+                value: 3
+              - name: "StepSize"
+                value: ColorTempPhysicalMaxMiredsValue
+              - name: "ColorTemperatureMinimumMireds"
+                value: 0
+              - name: "ColorTemperatureMaximumMireds"
+                value: ColorTempPhysicalMaxMiredsValue
+              - name: "TransitionTime"
+                value: 0
+              - name: "OptionsMask"
+                value: 0
+              - name: "OptionsOverride"
+                value: 0
+
+    - label: "Wait 100ms"
+      PICS: CC.S.F04
+      cluster: "DelayCommands"
+      command: "WaitForMs"
+      arguments:
+          values:
+              - name: "ms"
+                value: 100
+
+    - label: "Step 6b: TH reads ColorTemperatureMireds attribute from DUT."
+      PICS: CC.S.F04 && CC.S.A0007 && CC.S.C4c.Rsp
+      command: "readAttribute"
+      attribute: "ColorTemperatureMireds"
+      response:
+          value: ColorTempPhysicalMinMiredsValue
+          constraints:
+              minValue: ColorTempPhysicalMinMiredsValue
+              maxValue: ColorTempPhysicalMaxMiredsValue
+
     - label: "Turn Off light that we turned on"
       PICS: OO.S.C00.Rsp
       cluster: "On/Off"