# 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:
    4.2.2. [TC-SMOKECO-2.2] Primary Functionality - Smoke Alarm with DUT as
    Server

PICS:
    - SMOKECO.S.F00

config:
    nodeId: 0x12344321
    cluster: "Smoke CO Alarm"
    endpoint: 1
    timeout: 990
    TEST_EVENT_TRIGGER_KEY:
        type: octet_string
        defaultValue: "hex:00112233445566778899aabbccddeeff"
    TEST_EVENT_TRIGGER_WARNING_SMOKE_ALARM:
        type: int64u
        defaultValue: "0x005c000000000090"
    TEST_EVENT_TRIGGER_CRITICAL_SMOKE_ALARM:
        type: int64u
        defaultValue: "0x005c00000000009c"
    TEST_EVENT_TRIGGER_SMOKE_ALARM_CLEAR:
        type: int64u
        defaultValue: "0x005c0000000000a0"

tests:
    - label: "Step 1: Commission DUT to TH"
      cluster: "DelayCommands"
      command: "WaitForCommissionee"
      arguments:
          values:
              - name: "nodeId"
                value: nodeId

    - label: "Step 2: TH subscribes to SmokeState attribute from DUT"
      PICS: SMOKECO.S.A0001
      command: "subscribeAttribute"
      attribute: "SmokeState"
      minInterval: 1
      maxInterval: 900
      response:
          value: 0
          constraints:
              type: enum8

    - label: "Step 3: TH reads ExpressedState attribute from DUT"
      PICS: SMOKECO.S.A0000
      command: "readAttribute"
      attribute: "ExpressedState"
      response:
          value: 0
          constraints:
              type: enum8

    - label: "TH gets last event number from DUT"
      PICS: SMOKECO.S.E0a
      command: "readEvent"
      event: "AllClear"

    - label:
          "Step 4: TH reads TestEventTriggersEnabled attribute from General
          Diagnostics Cluster"
      PICS: DGGEN.S.A0008
      cluster: "General Diagnostics"
      endpoint: 0
      command: "readAttribute"
      attribute: "TestEventTriggersEnabled"
      response:
          value: 1

    - label:
          "Step 5: TH sends TestEventTrigger command to General Diagnostics
          Cluster on Endpoint 0 with EnableKey field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER for Warning Smoke Alarm Test Event"
      PICS: DGGEN.S.C00.Rsp
      cluster: "General Diagnostics"
      endpoint: 0
      command: "TestEventTrigger"
      arguments:
          values:
              - name: "EnableKey"
                value: TEST_EVENT_TRIGGER_KEY
              - name: "EventTrigger"
                value: TEST_EVENT_TRIGGER_WARNING_SMOKE_ALARM

    - label:
          "Step 6: TH waits for a report of SmokeState attribute from DUT with a
          timeout of 300 seconds"
      PICS: PICS_SKIP_SAMPLE_APP && SMOKECO.S.A0001
      cluster: "LogCommands"
      command: "UserPrompt"
      verification: |
          ./chip-tool smokecoalarm read smoke-state 1 1

          [TOO] Endpoint: 1 Cluster: 0x0000_005C Attribute 0x0000_0001 DataVersion: 1795725838
          [TOO]   SmokeState: 1
          [1689664630.513112][46175:46177] CHIP:EM: <<< [E:20916i S:3567 M:7458867 (Ack:19624350)] (S) Msg TX to 1:0000000000000001 [7A4E] --- Type 0000:10 (SecureChannel:StandaloneAck)
      arguments:
          values:
              - name: "message"
                value: "Enter 'y' after success"
              - name: "expectedValue"
                value: "y"

    - label: "Step 7: TH reads ExpressedState attribute from DUT"
      PICS: SMOKECO.S.A0000
      command: "readAttribute"
      attribute: "ExpressedState"
      response:
          value: 1
          constraints:
              type: enum8

    - label: "Step 8: TH reads SmokeAlarm event from DUT"
      PICS: SMOKECO.S.E00
      command: "readEvent"
      event: "SmokeAlarm"
      eventNumber: "LastReceivedEventNumber + 1"
      response:
          value: { AlarmSeverityLevel: 1 }

    - label: "Step 9:Start manually DUT self-test"
      cluster: "LogCommands"
      PICS: PICS_USER_PROMPT && SMOKECO.M.ManuallyControlledTest
      command: "UserPrompt"
      arguments:
          values:
              - name: "message"
                value: "Please enter 'y' for success"
              - name: "expectedValue"
                value: "y"

    - label: "Step 10: TH reads TestInProgress attribute from DUT"
      PICS: SMOKECO.S.A0005 && SMOKECO.M.ManuallyControlledTest
      command: "readAttribute"
      attribute: "TestInProgress"
      response:
          value: 0
          constraints:
              type: boolean

    - label: "Step 11 & 12: TH sends SelfTestRequest command to DUT"
      PICS: SMOKECO.S.C00.Rsp
      command: "SelfTestRequest"
      response:
          error: BUSY

    - label: "Step 13: TH reads TestInProgress attribute from DUT"
      PICS: SMOKECO.S.A0005
      command: "readAttribute"
      attribute: "TestInProgress"
      response:
          value: 0
          constraints:
              type: boolean

    - label:
          "Step 14: TH sends TestEventTrigger command to General Diagnostics
          Cluster on Endpoint 0 with EnableKey field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER for Critical Smoke Alarm Test Event"
      PICS: DGGEN.S.C00.Rsp
      cluster: "General Diagnostics"
      endpoint: 0
      command: "TestEventTrigger"
      arguments:
          values:
              - name: "EnableKey"
                value: TEST_EVENT_TRIGGER_KEY
              - name: "EventTrigger"
                value: TEST_EVENT_TRIGGER_CRITICAL_SMOKE_ALARM

    - label:
          "Step 15: TH waits for a report of SmokeState attribute from DUT with
          a timeout of 300 seconds"
      PICS: PICS_SKIP_SAMPLE_APP && SMOKECO.S.A0001
      cluster: "LogCommands"
      command: "UserPrompt"
      verification: |
          ./chip-tool smokecoalarm read smoke-state 1 1

          [TOO] Endpoint: 1 Cluster: 0x0000_005C Attribute 0x0000_0001 DataVersion: 1795725838
          [TOO]   SmokeState: 2
          [1689664630.513112][46175:46177] CHIP:EM: <<< [E:20916i S:3567 M:7458867 (Ack:19624350)] (S) Msg TX to 1:0000000000000001 [7A4E] --- Type 0000:10 (SecureChannel:StandaloneAck)
      arguments:
          values:
              - name: "message"
                value: "Enter 'y' after success"
              - name: "expectedValue"
                value: "y"

    - label: "Step 16: TH reads ExpressedState attribute from DUT"
      PICS: SMOKECO.S.A0000
      command: "readAttribute"
      attribute: "ExpressedState"
      response:
          value: 1
          constraints:
              type: enum8

    - label: "Step 17: TH reads SmokeAlarm event from DUT"
      PICS: SMOKECO.S.E00
      command: "readEvent"
      event: "SmokeAlarm"
      eventNumber: "LastReceivedEventNumber + 1"
      response:
          value: { AlarmSeverityLevel: 2 }

    - label:
          "Step 18: TH sends TestEventTrigger command to General Diagnostics
          Cluster on Endpoint 0 with EnableKey field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER_KEY and EventTrigger field set to
          PIXIT.SMOKECO.TEST_EVENT_TRIGGER for Smoke Alarm Test Event Clear"
      PICS: DGGEN.S.C00.Rsp
      cluster: "General Diagnostics"
      endpoint: 0
      command: "TestEventTrigger"
      arguments:
          values:
              - name: "EnableKey"
                value: TEST_EVENT_TRIGGER_KEY
              - name: "EventTrigger"
                value: TEST_EVENT_TRIGGER_SMOKE_ALARM_CLEAR

    - label:
          "Step 19: TH waits for a report of SmokeState attribute from DUT with
          a timeout of 300 seconds"
      PICS: PICS_SKIP_SAMPLE_APP && SMOKECO.S.A0001
      cluster: "LogCommands"
      command: "UserPrompt"
      verification: |
          ./chip-tool smokecoalarm read smoke-state 1 1

          [TOO] Endpoint: 1 Cluster: 0x0000_005C Attribute 0x0000_0001 DataVersion: 1795725838
          [TOO]   SmokeState: 0
          [1689664630.513112][46175:46177] CHIP:EM: <<< [E:20916i S:3567 M:7458867 (Ack:19624350)] (S) Msg TX to 1:0000000000000001 [7A4E] --- Type 0000:10 (SecureChannel:StandaloneAck)
      arguments:
          values:
              - name: "message"
                value: "Enter 'y' after success"
              - name: "expectedValue"
                value: "y"

    - label: "Step 20: TH reads ExpressedState attribute from DUT"
      PICS: SMOKECO.S.A0000
      command: "readAttribute"
      attribute: "ExpressedState"
      response:
          value: 0
          constraints:
              type: enum8

    - label: "Step 21: TH reads AllClear event from DUT"
      PICS: SMOKECO.S.E0a
      command: "readEvent"
      event: "AllClear"
      eventNumber: "LastReceivedEventNumber + 1"
      response:
          value: {}
