2121
2222namespace ZWaveDotNet . CommandClasses
2323{
24+ /// <summary>
25+ /// This Command Class manipulates the color components of a device.
26+ /// Each color component is scaled by the brightness level previously set by a Multilevel Switch Set, Binary Switch Set or Basic Set Command.
27+ /// </summary>
2428 [ CCVersion ( CommandClass . SwitchColor , 1 , 3 ) ]
2529 public class SwitchColor : CommandClassBase
2630 {
@@ -39,6 +43,13 @@ enum SwitchColorCommand
3943
4044 public SwitchColor ( Node node , byte endpoint ) : base ( node , endpoint , CommandClass . SwitchColor ) { }
4145
46+ /// <summary>
47+ /// <b>Version 1</b>: Control one or more color components in a device (V1 nodes ignore duration)
48+ /// </summary>
49+ /// <param name="components"></param>
50+ /// <param name="cancellationToken"></param>
51+ /// <param name="duration"></param>
52+ /// <returns></returns>
4253 public async Task Set ( KeyValuePair < ColorType , byte > [ ] components , CancellationToken cancellationToken = default , TimeSpan ? duration = null )
4354 {
4455 var payload = new List < byte > ( ) ;
@@ -49,12 +60,24 @@ public async Task Set(KeyValuePair<ColorType,byte>[] components, CancellationTok
4960 await SendCommand ( SwitchColorCommand . Set , cancellationToken , payload . ToArray ( ) ) ;
5061 }
5162
63+ /// <summary>
64+ /// <b>Version 1</b>: Request the status of a specified color component
65+ /// </summary>
66+ /// <param name="component"></param>
67+ /// <param name="cancellationToken"></param>
68+ /// <returns></returns>
5269 public async Task < SwitchColorReport > Get ( ColorType component , CancellationToken cancellationToken = default )
5370 {
5471 ReportMessage response = await SendReceive ( SwitchColorCommand . Get , SwitchColorCommand . Report , cancellationToken , ( byte ) component ) ;
5572 return new SwitchColorReport ( response . Payload . Span ) ;
5673 }
5774
75+ /// <summary>
76+ /// <b>Version 1</b>: Request the supported color components of a device
77+ /// </summary>
78+ /// <param name="cancellationToken"></param>
79+ /// <returns></returns>
80+ /// <exception cref="DataException"></exception>
5881 public async Task < ColorType [ ] > GetSupported ( CancellationToken cancellationToken = default )
5982 {
6083 ReportMessage response = await SendReceive ( SwitchColorCommand . SupportedGet , SwitchColorCommand . SupportedReport , cancellationToken ) ;
@@ -70,16 +93,34 @@ public async Task<ColorType[]> GetSupported(CancellationToken cancellationToken
7093 return ret . ToArray ( ) ;
7194 }
7295
73- public async Task StartLevelChange ( bool up , ColorType component , int startLevel , CancellationToken cancellationToken = default )
96+ /// <summary>
97+ /// <b>Version 1</b>: Initiate a transition of one color component to a new level (V1-2 nodes ignore duration)
98+ /// </summary>
99+ /// <param name="up"></param>
100+ /// <param name="component"></param>
101+ /// <param name="startLevel">If < 0, start level is ignored</param>
102+ /// <param name="duration"></param>
103+ /// <param name="cancellationToken"></param>
104+ /// <returns></returns>
105+ public async Task StartLevelChange ( bool up , ColorType component , int startLevel , TimeSpan ? duration = null , CancellationToken cancellationToken = default )
74106 {
75107 byte flags = 0x0 ;
76108 if ( startLevel < 0 )
77109 flags |= 0x20 ; //Ignore Start
78110 if ( up )
79111 flags |= 0x40 ;
80- await SendCommand ( SwitchColorCommand . StartLevelChange , cancellationToken , flags , ( byte ) component , ( byte ) Math . Max ( 0 , startLevel ) ) ;
112+ byte durationByte = 0 ;
113+ if ( duration != null )
114+ durationByte = ( PayloadConverter . GetByte ( duration . Value ) ) ;
115+ await SendCommand ( SwitchColorCommand . StartLevelChange , cancellationToken , flags , ( byte ) component , ( byte ) Math . Max ( 0 , startLevel ) , durationByte ) ;
81116 }
82117
118+ /// <summary>
119+ /// <b>Version 1</b>: Stop an ongoing transition initiated by a StartLevelChange command
120+ /// </summary>
121+ /// <param name="component"></param>
122+ /// <param name="cancellationToken"></param>
123+ /// <returns></returns>
83124 public async Task StopLevelChange ( ColorType component , CancellationToken cancellationToken = default )
84125 {
85126 await SendCommand ( SwitchColorCommand . StopLevelChange , cancellationToken , ( byte ) component ) ;
0 commit comments