# Copyright (c) 2021 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: Dependency with the On/Off cluster Verification (DUT as Server)

config:
    nodeId: 0x12344321
    cluster: "Level Control"
    endpoint: 1

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

    - label: "Sends a MoveToLevel command to set CurrentLevel to min value"
      command: "MoveToLevel"
      arguments:
          values:
              - name: "Level"
                value: 1
              - name: "TransitionTime"
                value: 0
              - name: "OptionsMask"
                value: 1
              - name: "OptionsOverride"
                value: 1

    - label: "Wait 100 ms"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "Reads CurrentLevel attribute from DUT"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 1

    - label: "Write OnOffTransitionTime attribute"
      command: "writeAttribute"
      attribute: "OnOffTransitionTime"
      arguments:
          value: 0

    - label: "Wait 100 ms"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "Read OnOffTransitionTime attribute"
      command: "readAttribute"
      attribute: "OnOffTransitionTime"
      response:
          value: 0

    - label: "Write OnLevel attribute"
      command: "writeAttribute"
      attribute: "OnLevel"
      arguments:
          value: 254

    - label: "Wait 100 ms"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "Read OnLevel attribute"
      command: "readAttribute"
      attribute: "OnLevel"
      response:
          value: 254

    - label: "Read MinValue attribute"
      command: "readAttribute"
      attribute: "MinLevel"
      response:
          value: 1

    - label: "Send On Command"
      cluster: "On/Off"
      command: "On"

    - label: "Check on/off attribute value is true after on command"
      cluster: "On/Off"
      command: "readAttribute"
      attribute: "OnOff"
      response:
          value: 1

    - label: "Wait OnOffTransitionTime"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "If OnLevel is defined, check CurrentLevel is OnLevel value"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 254

    - label: "Send Off Command"
      cluster: "On/Off"
      command: "Off"

    - label: "Check on/off attribute value is false after off command"
      cluster: "On/Off"
      command: "readAttribute"
      attribute: "OnOff"
      response:
          value: 0

    - label: "Wait OnOffTransitionTime"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 0

    - label: "If OnLevel is defined, check CurrentLevel is min value"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 1

    - label: "Sends a MoveToLevel command to set CurrentLevel to a mid value"
      command: "MoveToLevel"
      arguments:
          values:
              - name: "Level"
                value: 127
              - name: "TransitionTime"
                value: 0
              - name: "OptionsMask"
                value: 1
              - name: "OptionsOverride"
                value: 1

    - label: "Wait 100 ms"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "Reads CurrentLevel attribute from DUT"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 127

    - label: "Set OnLevel attribute to null"
      command: "writeAttribute"
      attribute: "OnLevel"
      arguments:
          value: null

    - label: "Wait 100 ms"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "Read OnLevel attribute"
      command: "readAttribute"
      attribute: "OnLevel"
      response:
          value: null

    - label: "Send On Command"
      cluster: "On/Off"
      command: "On"

    - label: "Check on/off attribute value is true after on command"
      cluster: "On/Off"
      command: "readAttribute"
      attribute: "OnOff"
      response:
          value: 1

    - label: "Wait OnOffTransitionTime"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 100

    - label: "If OnLevel is not defined, check CurrentLevel is restored"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 127

    - label: "Send Off Command"
      cluster: "On/Off"
      command: "Off"

    - label: "Check on/off attribute value is false after off command"
      cluster: "On/Off"
      command: "readAttribute"
      attribute: "OnOff"
      response:
          value: 0

    - label: "Wait OnOffTransitionTime"
      cluster: "DelayCommands"
      command: "WaitForMs"
      arguments:
          values:
              - name: "ms"
                value: 0

    - label: "If OnLevel is not defined, check CurrentLevel is restored"
      command: "readAttribute"
      attribute: "CurrentLevel"
      response:
          value: 127
