<?xml version="1.0" encoding="UTF-8"?>
<Domain
  xmlns="http://www.soti.net/connect-definitions"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.soti.net/connect-definitions ../../../Soti.Connect.ProtocolDefinitions/Soti.Connect.ProtocolDefinitions.Parser/protocol.xsd">
  <Imports>
    <xi:include href="./base-rest-protocol.xml" parse="xml" />
  </Imports>
  <Messages>
    <Message id="GetLight" />
    <Message id="GetBWLight" />
    <Message id="SearchLightBySerialNumber">
      <Segment id="Resource" type="string" />
    </Message>

    <Message id="Light">
      <Object id="Resource">
        <DataPointReference id="modelid" path="base-module#model-id" />
        <DataPointReference id="type" path="typeModule#type" />
        <DataPointReference id="name" path="base-module#device-name" />
        <DataPointReference id="manufacturername" path="base-module#manufacturer" />
        <DataPointReference id="swversion" path="base-module#version" />
        <DataPointReference id="DeviceId" path="hue-dimmable-light-module#unique_id" />
        <Object id="state">
          <DataPointReference id="on" path="switch#on" />
          <DataPointReference id="bri" path="hue-brightness-module#hue-brightness" />
          <DataPointReference id="hue" path="hue-hs-module#hue-hue" />
          <DataPointReference id="sat" path="hue-hs-module#hue-saturation" />
          <DataPointReference id="xy" path="hue-color-light-module#cie-color-coordinates" />
          <DataPointReference id="ct" path="hue-mired-color-temperature-module#hue-mired-color-temperature" />
          <DataPointReference id="alert" path="hue-dimmable-light-module#alert" />
          <DataPointReference id="effect" path="hue-color-light-module#light-effect" />
          <DataPointReference id="colormode" path="hue-color-light-module#color-mode" />
          <DataPointReference id="reachable" path="hue-dimmable-light-module#reachable" />
        </Object>
      </Object>
    </Message>

    <Message id="ChangeLightState">
      <Object id="Command">
        <Segment id="transitiontime" type="integer" />
        <Segment id="bri_inc" type="integer" />
        <Segment id="sat_inc" type="integer" />
        <Segment id="hue_inc" type="integer" />
        <Segment id="ct_inc" type="integer" />
      </Object>
      <Object id="Resource">
        <DataPointReference id="on" path="switch#on" />
        <DataPointReference id="bri" path="brightness-module#brightness" />
        <DataPointReference id="hue" path="hue-hs-module#hue-hue" />
        <DataPointReference id="sat" path="hue-hs-module#hue-saturation" />
        <DataPointReference id="ct" path="hue-mired-color-temperature-module#hue-mired-color-temperature" />
        <DataPointReference id="alert" path="hue-dimmable-light-module#alert" />
        <DataPointReference id="effect" path="hue-color-light-module#light-effect" />
        <DataPointReference id="colormode" path="hue-color-light-module#color-mode" />
      </Object>
    </Message>

    <Message id="BWLight">
      <Object id="Resource">
        <DataPointReference id="modelid" path="base-module#model-id" />
        <DataPointReference id="type" path="typeModule#type" />
        <DataPointReference id="name" path="base-module#device-name" />
        <DataPointReference id="manufacturername" path="base-module#manufacturer" />
        <DataPointReference id="swversion" path="base-module#version" />
        <DataPointReference id="DeviceId" path="hue-dimmable-light-module#unique_id" />
        <Object id="state">
          <DataPointReference id="on" path="switch#on" />
          <DataPointReference id="bri" path="hue-brightness-module#hue-brightness" />
          <DataPointReference id="alert" path="hue-dimmable-light-module#alert" />
          <DataPointReference id="reachable" path="hue-dimmable-light-module#reachable" />
        </Object>
      </Object>
    </Message>

    <Message id="ChangeBWLightState">
      <Object id="Command">
        <Segment id="transitiontime" type="integer" />
      </Object>
      <Object id="Resource">
        <DataPointReference id="on" path="switch#on" />
        <DataPointReference id="bri" path="brightness-module#brightness" />
        <DataPointReference id="alert" path="hue-dimmable-light-module#alert" />

      </Object>
    </Message>

    <Message id="RenameLight">
      <DataPointReference id="Resource" path="base-module#device-name" />
    </Message>

  </Messages>

  <Transactions>

    <Transaction id="Register" hint="You must first register a hub, gateway, or web service before you can discover and enroll devices on it.">
      <Blocks>
        <Block id="1">
          <SendMessage id="RegisterAPI">
            <UserAssignment actionArgName="Host Address" path="Settings/ApiIpAddress"
              hint="Enter the IP address of the Hue Hub you want to register. Press the button on the Hub no more than 20 seconds before selecting 'OK'." />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="RegisterAPISettings" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>


    <Transaction id="hue-dimmable-light.checkin" semanticid="base-module#checkin">
      <Blocks>
        <Block id="1">
          <SendMessage id="GetBWLight" />
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="BWLight" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-dimmable-light.rename" semanticid="hue-dimmable-light-module#rename">
      <Blocks>
        <Block id="1">
          <SendMessage id="RenameLight">
            <UserAssignment actionArgName="Label" path="Resource" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>

        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-dimmable-light.turn-on" semanticid="switch#turn-on">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeBWLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-dimmable-light.turn-off" semanticid="switch#turn-off">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeBWLightState">
            <ConstantAssignment path="Resource/on" value="false"></ConstantAssignment>
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-dimmable-light.set-brightness" semanticid="hue-brightness-module#hue-set-brightness">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeBWLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
            <UserAssignment actionArgName="Brightness" path="Resource/bri" defaultValue="250" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <!--Color-->
    <Transaction id="hue-color-light.checkin" semanticid="base-module#checkin">
      <Blocks>
        <Block id="1">
          <SendMessage id="GetLight" />
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Light" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-color-light.set-color" semanticid="hue-hs-module#hue-set-color-hsb">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
            <UserAssignment actionArgName="Hue" path="Resource/hue" defaultValue="0" />
            <UserAssignment actionArgName="Saturation" path="Resource/sat" defaultValue="200" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-color-light.set-color-temp" semanticid="hue-mired-color-temperature-module#hue-set-color-temperature">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
            <UserAssignment actionArgName="Mired Color Temperature" path="Resource/ct" defaultValue="300" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-color-light.start-color-loop" semanticid="hue-color-light-module#start-color-loop">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
            <ConstantAssignment path="Resource/effect" value="colorloop" />
            <ConstantAssignment path="Command/transitiontime" value="5" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="hue-color-light.stop-color-loop" semanticid="hue-color-light-module#stop-color-loop">
      <Blocks>
        <Block id="1">
          <SendMessage id="ChangeLightState">
            <ConstantAssignment path="Resource/on" value="true"></ConstantAssignment>
            <ConstantAssignment path="Resource/effect" value="none" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="SearchNewDevices">
      <Blocks>
        <Block id="1">
          <SendMessage id="SearchNewDevices" />
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>

    <Transaction id="SearchDeviceBySerialNumber">
      <Blocks>
        <Block id="1">
          <SendMessage id="SearchLightBySerialNumber">
            <UserAssignment actionArgName="Serial Number" path="Resource" hint="Six characters" />
          </SendMessage>
          <Switch>
            <SwitchOnMessage>
              <MessageCase>
                <ReceiveMessage id="Success" />
                <BlockAction>
                  <Terminate success="true" />
                </BlockAction>
              </MessageCase>
              <MessageCase>
                <ReceiveMessage id="Error">
                  <VariableDefinition id="Resource" path="Resource" />
                </ReceiveMessage>
                <BlockAction>
                  <Terminate success="false">
                    <Log variableId="Resource" />
                  </Terminate>
                </BlockAction>
              </MessageCase>
            </SwitchOnMessage>
          </Switch>
        </Block>
      </Blocks>
    </Transaction>


  </Transactions>

  <ProtocolDefinition id="10C024BF-C6CC-45B0-9F6F-0AF9C22AE1B7" name="Philips Hue HTTP">
    <Protocol>
      <Transaction id="InitializeProtocol" hidden="true" />
      <Transaction id="Register" />
      <Transaction id="DiscoverDevices" instanceIdRequired="true" />
      <Transaction id="SearchNewDevices" instanceIdRequired="true" />
      <Transaction id="SearchDeviceBySerialNumber" instanceIdRequired="true" />
      <Transaction id="NewDevices" />
      <Transaction id="Unregister" instanceIdRequired="true" />
      <Transaction id="DeployCertificate" hidden="true" />
      <Transaction id="ActivateCertificate" hidden="true" />
      <Transaction id="CancelCertificateActivation" hidden="true" />
      <Transaction id="GetConnectNetworkInventory" hidden="true" />
      <Transaction id="StopConnectNetworkInventory" hidden="true" />
      <Transaction id="ConnectNetworkInventory" hidden="true" />
    </Protocol>

    <Devices>
      <!-- Added light, dimmable, and dimmable color so we can use enrollment rules for parent devices-->
      <Device id="light">
        <Transaction id="hue-dimmable-light.turn-on" />
      </Device>
      <Device id="dimmable-light">
        <Transaction id="hue-dimmable-light.turn-on" />
      </Device>

      <Device id="dimmable-color-light">
        <Transaction id="hue-dimmable-light.turn-on" />
      </Device>

      <Device id="hue-color-light">
        <ApiTypeId id="Extended color light" />

        <Transaction id="hue-color-light.checkin" />
        <Transaction id="hue-color-light.set-color" />
        <Transaction id="hue-color-light.start-color-loop" />
        <Transaction id="hue-color-light.stop-color-loop" />
        <Transaction id="hue-color-light.set-color-temp" />
        <Transaction id="hue-dimmable-light.turn-on" />
        <Transaction id="hue-dimmable-light.turn-off" />
        <Transaction id="hue-dimmable-light.rename" />
        <Transaction id="hue-dimmable-light.set-brightness" />
      </Device>
      <Device id="hue-dimmable-light">
        <ApiTypeId id="Dimmable light" />

        <Transaction id="hue-dimmable-light.checkin" />
        <Transaction id="hue-dimmable-light.turn-on" />
        <Transaction id="hue-dimmable-light.turn-off" />
        <Transaction id="hue-dimmable-light.rename" />
        <Transaction id="hue-dimmable-light.set-brightness" />
      </Device>
    </Devices>
  </ProtocolDefinition>


</Domain>