AdapterLib.HueLightingServiceHandler.TransitionLampState C# (CSharp) Method

TransitionLampState() public method

public TransitionLampState ( ulong Timestamp, BridgeRT NewState, uint TransitionPeriod, uint &LampResponseCode ) : uint
Timestamp ulong
NewState BridgeRT
TransitionPeriod uint
LampResponseCode uint
return uint
        public uint TransitionLampState(ulong Timestamp, BridgeRT.State NewState, uint TransitionPeriod, out uint LampResponseCode)
        {
            var command = new LightCommand();
            command.TransitionTime = TimeSpan.FromMilliseconds(TransitionPeriod);
            command.On = NewState.IsOn;
            if (NewState.Brightness.HasValue && LampDetails_Dimmable)
                command.Brightness = (byte)(NewState.Brightness.Value * 254d / UInt32Max);
            if (NewState.Hue.HasValue && LampDetails_Color)
                command.Hue = (int)(NewState.Hue.Value * 65535d / UInt32Max);
            if (NewState.Saturation.HasValue && LampDetails_Color)
                command.Saturation = (int)(NewState.Saturation.Value * 254d / UInt32Max);
            if (NewState.ColorTemp.HasValue && LampDetails_VariableColorTemp)
            {
                double kelvin = NewState.ColorTemp.Value * 19000d / UInt32Max + 1000;
                int kelvinLimited = (int)Math.Max(LampDetails_MinTemperature, Math.Min(LampDetails_MaxTemperature, kelvin));
                int mired = (int)(1000000d / kelvinLimited);
                //Currently hue doesn't like setting color temp if the other parameters are also set.
                //Skipping for now.
                //command.ColorTemperature = mired;
            }
            LampResponseCode = 0;
            System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(Timestamp)).ContinueWith(_ =>
            {
                _client.SendCommandAsync(command, new[] { _light.Id });
                //Update state
                if(command.Hue.HasValue)
                    _light.State.Hue = command.Hue.Value;
                if (command.Brightness.HasValue)
                    _light.State.Brightness = command.Brightness.Value;
                if (command.Saturation.HasValue)
                    _light.State.Saturation= command.Saturation.Value;
                if (command.ColorTemperature.HasValue)
                    _light.State.ColorTemperature = command.ColorTemperature.Value;
                if (command.On.HasValue)
                    _light.State.On = command.On.Value;
            });
            return 0; //TODO
        }
    }