# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: 142.2.3. [TC-TIMESYNC-2.3] SetTrustedTimeSource command with DUT as Server

PICS:
    - TIMESYNC.S
    - TIMESYNC.S.F03
    - TIMESYNC.S.C01.Rsp
    - TIMESYNC.S.C00.Rsp
    - TIMESYNC.S.A0001
    - TIMESYNC.S.A0000

config:
    nodeId: 0x12344321
    cluster: "Time Synchronization"
    endpoint: 0

tests:
    - label: "Step 0: Wait for the commissioned device to be retrieved"
      cluster: "DelayCommands"
      command: "WaitForCommissionee"
      arguments:
          values:
              - name: "nodeId"
                value: nodeId

    - label: "Read commissioner nodeID and saves as th_node_id"
      cluster: "CommissionerCommands"
      command: "GetCommissionerNodeId"
      response:
          values:
              - name: "nodeId"
                saveAs: th_node_id

    - label:
          "Step 1: TH sends the SetTrustedTimeSource command to the DUT with the
          TrustedTimeSource fields set as follows: NodeID: th_node_id, Endpoint:
          0"
      command: "SetTrustedTimeSource"
      arguments:
          values:
              - name: "TrustedTimeSource"
                value: { NodeID: th_node_id, Endpoint: 0 }

    - label:
          "Step 2: TH reads from the DUT the CurrentFabricIndex attribute from
          the Node Operational Credentials Cluster and saves as th_fabric_idx"
      command: "readAttribute"
      attribute: "CurrentFabricIndex"
      cluster: "Operational Credentials"
      response:
          saveAs: th_fabric_idx

    - label: "Step 3: TH reads from the DUT the TrustedTimeSource attribute."
      command: "readAttribute"
      attribute: "TrustedTimeSource"
      response:
          value: { FabricIndex: th_fabric_idx, NodeID: th_node_id, Endpoint: 0 }

    - label:
          "Step 4: TH sends the SetTrustedTimeSource command to the DUT with the
          TrustedTimeSource set to null."
      command: "SetTrustedTimeSource"
      arguments:
          values:
              - name: "TrustedTimeSource"
                value: null

    - label: "Step 5: TH reads from the DUT the TrustedTimeSource attribute."
      command: "readAttribute"
      attribute: "TrustedTimeSource"
      response:
          value: null
