@@ -340,8 +340,10 @@ Status OnOffServer::getOnOffValue(chip::EndpointId endpoint, bool * currentOnOff
340
340
* @param endpoint Ver.: always
341
341
* @param command Ver.: always
342
342
* @param initiatedByLevelChange Ver.: always
343
+ * @param forceSend Send value of the On/Off even when it is the same as current On/Off value.
344
+ * This parameter is useful at the start when you try to determine startup state of On/Off relay that does not store state after losing power
343
345
*/
344
- Status OnOffServer::setOnOffValue (chip::EndpointId endpoint, chip::CommandId command, bool initiatedByLevelChange)
346
+ Status OnOffServer::setOnOffValue (chip::EndpointId endpoint, chip::CommandId command, bool initiatedByLevelChange, bool forceSend )
345
347
{
346
348
MATTER_TRACE_SCOPE (" setOnOffValue" , " OnOff" );
347
349
Status status;
@@ -355,18 +357,33 @@ Status OnOffServer::setOnOffValue(chip::EndpointId endpoint, chip::CommandId com
355
357
return status;
356
358
}
357
359
358
- // if the value is already what we want to set it to then do nothing
359
- if ((!currentValue && command == Commands::Off::Id) || (currentValue && command == Commands::On::Id))
360
+ if (forceSend)
360
361
{
361
- ChipLogProgress (Zcl, " Endpoint %x On/off already set to new value" , endpoint);
362
- return Status::Success;
363
- }
362
+ if (command == Commands::Off::Id)
363
+ {
364
+ newValue = false ;
365
+ }
366
+ else if (command == Commands::On::Id)
367
+ {
368
+ newValue = true ;
364
369
365
- // we either got a toggle, or an on when off, or an off when on,
366
- // so we need to swap the value
367
- newValue = !currentValue;
368
- ChipLogProgress (Zcl, " Toggle ep%x on/off from state %x to %x" , endpoint, currentValue, newValue);
370
+ }
371
+ // I guess that, I can only get ON/OFF at startup
372
+ }
373
+ else
374
+ {
375
+ // if the value is already what we want to set it to then do nothing
376
+ if ((!currentValue && command == Commands::Off::Id) || (currentValue && command == Commands::On::Id))
377
+ {
378
+ ChipLogProgress (Zcl, " Endpoint %x On/off already set to new value" , endpoint);
379
+ return Status::Success;
380
+ }
369
381
382
+ // we either got a toggle, or an on when off, or an off when on,
383
+ // so we need to swap the value
384
+ newValue = !currentValue;
385
+ ChipLogProgress (Zcl, " Toggle ep%x on/off from state %x to %x" , endpoint, currentValue, newValue);
386
+ }
370
387
// the sequence of updating on/off attribute and kick off level change effect should
371
388
// be depend on whether we are turning on or off. If we are turning on the light, we
372
389
// should update the on/off attribute before kicking off level change, if we are
@@ -499,7 +516,7 @@ void OnOffServer::initOnOffServer(chip::EndpointId endpoint)
499
516
Status status = getOnOffValueForStartUp (endpoint, onOffValueForStartUp);
500
517
if (status == Status::Success)
501
518
{
502
- status = setOnOffValue (endpoint, onOffValueForStartUp, true );
519
+ status = setOnOffValue (endpoint, onOffValueForStartUp, true , true );
503
520
}
504
521
505
522
#if defined(MATTER_DM_PLUGIN_SCENES_MANAGEMENT) && CHIP_CONFIG_SCENES_USE_DEFAULT_HANDLERS
0 commit comments