@@ -112,21 +112,21 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
112
112
{
113
113
xValue = 0x616B ; // Default X value according to spec
114
114
}
115
- AddAttributeValuePair (pairs, Attributes::CurrentX::Id, xValue, attributeCount);
115
+ AddAttributeValuePair< uint16_t > (pairs, Attributes::CurrentX::Id, xValue, attributeCount);
116
116
117
117
uint16_t yValue;
118
118
if (Status::Success != Attributes::CurrentY::Get (endpoint, &yValue))
119
119
{
120
120
yValue = 0x607D ; // Default Y value according to spec
121
121
}
122
- AddAttributeValuePair (pairs, Attributes::CurrentY::Id, yValue, attributeCount);
122
+ AddAttributeValuePair< uint16_t > (pairs, Attributes::CurrentY::Id, yValue, attributeCount);
123
123
}
124
124
125
125
if (ColorControlServer::Instance ().HasFeature (endpoint, ColorControlServer::Feature::kEnhancedHue ))
126
126
{
127
127
uint16_t hueValue = 0x0000 ;
128
128
Attributes::EnhancedCurrentHue::Get (endpoint, &hueValue);
129
- AddAttributeValuePair (pairs, Attributes::EnhancedCurrentHue::Id, hueValue, attributeCount);
129
+ AddAttributeValuePair< uint16_t > (pairs, Attributes::EnhancedCurrentHue::Id, hueValue, attributeCount);
130
130
}
131
131
132
132
if (ColorControlServer::Instance ().HasFeature (endpoint, ColorControlServer::Feature::kHueAndSaturation ))
@@ -136,7 +136,7 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
136
136
{
137
137
saturationValue = 0x00 ;
138
138
}
139
- AddAttributeValuePair (pairs, Attributes::CurrentSaturation::Id, saturationValue, attributeCount);
139
+ AddAttributeValuePair< uint8_t > (pairs, Attributes::CurrentSaturation::Id, saturationValue, attributeCount);
140
140
}
141
141
142
142
if (ColorControlServer::Instance ().HasFeature (endpoint, ColorControlServer::Feature::kColorLoop ))
@@ -146,21 +146,21 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
146
146
{
147
147
loopActiveValue = 0x00 ;
148
148
}
149
- AddAttributeValuePair (pairs, Attributes::ColorLoopActive::Id, loopActiveValue, attributeCount);
149
+ AddAttributeValuePair< uint8_t > (pairs, Attributes::ColorLoopActive::Id, loopActiveValue, attributeCount);
150
150
151
151
uint8_t loopDirectionValue;
152
152
if (Status::Success != Attributes::ColorLoopDirection::Get (endpoint, &loopDirectionValue))
153
153
{
154
154
loopDirectionValue = 0x00 ;
155
155
}
156
- AddAttributeValuePair (pairs, Attributes::ColorLoopDirection::Id, loopDirectionValue, attributeCount);
156
+ AddAttributeValuePair< uint8_t > (pairs, Attributes::ColorLoopDirection::Id, loopDirectionValue, attributeCount);
157
157
158
158
uint16_t loopTimeValue;
159
159
if (Status::Success != Attributes::ColorLoopTime::Get (endpoint, &loopTimeValue))
160
160
{
161
161
loopTimeValue = 0x0019 ; // Default loop time value according to spec
162
162
}
163
- AddAttributeValuePair (pairs, Attributes::ColorLoopTime::Id, loopTimeValue, attributeCount);
163
+ AddAttributeValuePair< uint16_t > (pairs, Attributes::ColorLoopTime::Id, loopTimeValue, attributeCount);
164
164
}
165
165
166
166
if (ColorControlServer::Instance ().HasFeature (endpoint, ColorControlServer::Feature::kColorTemperature ))
@@ -170,15 +170,15 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
170
170
{
171
171
temperatureValue = 0x00FA ; // Default temperature value according to spec
172
172
}
173
- AddAttributeValuePair (pairs, Attributes::ColorTemperatureMireds::Id, temperatureValue, attributeCount);
173
+ AddAttributeValuePair< uint16_t > (pairs, Attributes::ColorTemperatureMireds::Id, temperatureValue, attributeCount);
174
174
}
175
175
176
176
uint8_t modeValue;
177
177
if (Status::Success != Attributes::EnhancedColorMode::Get (endpoint, &modeValue))
178
178
{
179
179
modeValue = ColorControl::EnhancedColorMode::kCurrentXAndCurrentY ; // Default mode value according to spec
180
180
}
181
- AddAttributeValuePair (pairs, Attributes::EnhancedColorMode::Id, modeValue, attributeCount);
181
+ AddAttributeValuePair< uint8_t > (pairs, Attributes::EnhancedColorMode::Id, modeValue, attributeCount);
182
182
183
183
app::DataModel::List<AttributeValuePair> attributeValueList (pairs, attributeCount);
184
184
@@ -237,52 +237,76 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
237
237
case Attributes::CurrentX::Id:
238
238
if (SupportsColorMode (endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY ))
239
239
{
240
- if (decodePair.attributeValue )
240
+ if (decodePair.valueUnsigned16 . HasValue () )
241
241
colorXTransitionState->finalValue =
242
- std::min (static_cast < uint16_t >( decodePair.attributeValue ), colorXTransitionState->highLimit );
242
+ std::min (decodePair.valueUnsigned16 . Value ( ), colorXTransitionState->highLimit );
243
243
}
244
244
break ;
245
245
case Attributes::CurrentY::Id:
246
246
if (SupportsColorMode (endpoint, ColorControl::EnhancedColorMode::kCurrentXAndCurrentY ))
247
247
{
248
- colorYTransitionState->finalValue =
249
- std::min (static_cast <uint16_t >(decodePair.attributeValue ), colorYTransitionState->highLimit );
248
+ if (decodePair.valueUnsigned16 .HasValue ())
249
+ {
250
+ colorYTransitionState->finalValue =
251
+ std::min (decodePair.valueUnsigned16 .Value (), colorYTransitionState->highLimit );
252
+ }
250
253
}
251
254
break ;
252
255
case Attributes::EnhancedCurrentHue::Id:
253
256
if (SupportsColorMode (endpoint, ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation ))
254
257
{
255
- colorHueTransitionState->finalEnhancedHue = static_cast <uint16_t >(decodePair.attributeValue );
258
+ if (decodePair.valueUnsigned16 .HasValue ())
259
+ {
260
+ colorHueTransitionState->finalEnhancedHue = decodePair.valueUnsigned16 .Value ();
261
+ }
256
262
}
257
263
break ;
258
264
case Attributes::CurrentSaturation::Id:
259
265
if (SupportsColorMode (endpoint, ColorControl::EnhancedColorMode::kCurrentHueAndCurrentSaturation ))
260
266
{
261
- colorSaturationTransitionState->finalValue =
262
- std::min (static_cast <uint16_t >(decodePair.attributeValue ), colorSaturationTransitionState->highLimit );
267
+ if (decodePair.valueUnsigned16 .HasValue ())
268
+ {
269
+ colorSaturationTransitionState->finalValue =
270
+ std::min (decodePair.valueUnsigned16 .Value (), colorSaturationTransitionState->highLimit );
271
+ }
263
272
}
264
273
break ;
265
274
case Attributes::ColorLoopActive::Id:
266
- loopActiveValue = static_cast <uint8_t >(decodePair.attributeValue );
275
+ if (decodePair.valueUnsigned8 .HasValue ())
276
+ {
277
+ loopActiveValue = decodePair.valueUnsigned8 .Value ();
278
+ }
267
279
break ;
268
280
case Attributes::ColorLoopDirection::Id:
269
- loopDirectionValue = static_cast <uint8_t >(decodePair.attributeValue );
281
+ if (decodePair.valueUnsigned8 .HasValue ())
282
+ {
283
+ loopDirectionValue = decodePair.valueUnsigned8 .Value ();
284
+ }
270
285
break ;
271
286
case Attributes::ColorLoopTime::Id:
272
- loopTimeValue = static_cast <uint16_t >(decodePair.attributeValue );
287
+ if (decodePair.valueUnsigned16 .HasValue ())
288
+ {
289
+ loopTimeValue = decodePair.valueUnsigned16 .Value ();
290
+ }
273
291
break ;
274
292
case Attributes::ColorTemperatureMireds::Id:
275
293
if (SupportsColorMode (endpoint, ColorControl::EnhancedColorMode::kColorTemperature ))
276
294
{
277
- colorTempTransitionState->finalValue =
278
- std::min (static_cast <uint16_t >(decodePair.attributeValue ), colorTempTransitionState->highLimit );
295
+ if (decodePair.valueUnsigned16 .HasValue ())
296
+ {
297
+ colorTempTransitionState->finalValue =
298
+ std::min (decodePair.valueUnsigned16 .Value (), colorTempTransitionState->highLimit );
299
+ }
279
300
}
280
301
break ;
281
302
case Attributes::EnhancedColorMode::Id:
282
- if (decodePair.attributeValue <=
283
- static_cast <uint8_t >(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation ))
303
+ if (decodePair.valueUnsigned8 .HasValue ())
284
304
{
285
- targetColorMode = static_cast <uint8_t >(decodePair.attributeValue );
305
+ if (decodePair.valueUnsigned8 .Value () <=
306
+ static_cast <uint8_t >(ColorControl::EnhancedColorMode::kEnhancedCurrentHueAndCurrentSaturation ))
307
+ {
308
+ targetColorMode = decodePair.valueUnsigned8 .Value ();
309
+ }
286
310
}
287
311
break ;
288
312
default :
@@ -371,11 +395,26 @@ class DefaultColorControlSceneHandler : public scenes::DefaultSceneHandlerImpl
371
395
}
372
396
}
373
397
374
- void AddAttributeValuePair (ScenesManagement::Structs::AttributeValuePair::Type * pairs, AttributeId id, uint32_t value,
398
+ // / AddAttributeValuePair
399
+ // / @brief Helper function to add an attribute value pair to the attribute value pair array in the color control SceneHandler
400
+ // / @param pairs list of attribute value pairs
401
+ // / @param id attribute id
402
+ // / @param value attribute value
403
+ // / @param attributeCount number of attributes in the list, incremented by this function, used to keep track of how many
404
+ // / attributes from the array are being used for the list to encode
405
+ template <typename Type>
406
+ void AddAttributeValuePair (ScenesManagement::Structs::AttributeValuePair::Type * pairs, AttributeId id, Type value,
375
407
size_t & attributeCount)
376
408
{
377
- pairs[attributeCount].attributeID = id;
378
- pairs[attributeCount].attributeValue = value;
409
+ pairs[attributeCount].attributeID = id;
410
+ if constexpr (sizeof (Type) == sizeof (uint8_t ))
411
+ {
412
+ pairs[attributeCount].valueUnsigned8 .SetValue (value);
413
+ }
414
+ else if constexpr (sizeof (Type) == sizeof (uint16_t ))
415
+ {
416
+ pairs[attributeCount].valueUnsigned16 .SetValue (value);
417
+ }
379
418
attributeCount++;
380
419
}
381
420
};
0 commit comments