@@ -246,8 +246,6 @@ void WaterHeaterManagementDelegate::HandleBoostTimerExpiry()
246
246
*/
247
247
Status WaterHeaterManagementDelegate::HandleCancelBoost ()
248
248
{
249
- Status status = Status::Success;
250
-
251
249
ChipLogProgress (AppServer, " HandleCancelBoost" );
252
250
253
251
if (mBoostState == BoostStateEnum::kActive )
@@ -257,20 +255,16 @@ Status WaterHeaterManagementDelegate::HandleCancelBoost()
257
255
258
256
DeviceLayer::SystemLayer ().CancelTimer (BoostTimerExpiry, this );
259
257
260
- if (mpWhmManufacturer != nullptr )
261
- {
262
- status = mpWhmManufacturer->BoostCommandCancelled ();
263
- }
264
- else
265
- {
266
- status = Status::InvalidInState;
267
- ChipLogError (AppServer, " HandleCancelBoost: mpWhmManufacturer == nullptr" );
268
- }
258
+ VerifyOrReturnValue (mpWhmManufacturer != nullptr , Status::InvalidInState);
259
+
260
+ Status status = mpWhmManufacturer->BoostCommandCancelled ();
261
+ VerifyOrReturnValue (status == Status::Success, status);
269
262
270
263
status = CheckIfHeatNeedsToBeTurnedOnOrOff ();
264
+ VerifyOrReturnValue (status == Status::Success, status);
271
265
}
272
266
273
- return status ;
267
+ return Status::Success ;
274
268
}
275
269
276
270
/* ********************************************************************************
@@ -365,11 +359,44 @@ bool WaterHeaterManagementDelegate::HasWaterTemperatureReachedTarget() const
365
359
366
360
Status WaterHeaterManagementDelegate::CheckIfHeatNeedsToBeTurnedOnOrOff ()
367
361
{
368
- Status status = Status::Success;
369
- bool turningHeatOff = false ;
370
-
371
362
VerifyOrReturnError (mpWhmManufacturer != nullptr , Status::InvalidInState);
372
363
364
+ HeatingOp heatingOp = HeatingOp::LeaveHeatingUnchanged;
365
+
366
+ Status status = DetermineIfChangingHeatingState (heatingOp);
367
+
368
+ VerifyOrReturnError (status == Status::Success, status);
369
+
370
+ if (heatingOp == HeatingOp::TurnHeatingOn)
371
+ {
372
+ status = mpWhmManufacturer->TurnHeatingOn (mBoostEmergencyBoost .HasValue () ? mBoostEmergencyBoost .Value () : false );
373
+ }
374
+ else if (heatingOp == HeatingOp::TurnHeatingOff)
375
+ {
376
+ // If running a boost command with the oneShot parameter and turning heat off, then must have
377
+ // reached the boost command target temperature -> that's the boost command complete.
378
+ if (mBoostState == BoostStateEnum::kActive && mBoostOneShot .HasValue () && mBoostOneShot .Value ())
379
+ {
380
+ SetBoostState (BoostStateEnum::kInactive );
381
+
382
+ DeviceLayer::SystemLayer ().CancelTimer (BoostTimerExpiry, this );
383
+
384
+ mBoostEmergencyBoost .ClearValue ();
385
+
386
+ status = mpWhmManufacturer->BoostCommandCancelled ();
387
+ }
388
+
389
+ // Turn the heating off
390
+ status = mpWhmManufacturer->TurnHeatingOff ();
391
+ }
392
+
393
+ return status;
394
+ }
395
+
396
+ Status WaterHeaterManagementDelegate::DetermineIfChangingHeatingState (HeatingOp & heatingOp)
397
+ {
398
+ heatingOp = LeaveHeatingUnchanged;
399
+
373
400
if (!HasWaterTemperatureReachedTarget ())
374
401
{
375
402
VerifyOrReturnError (WaterHeaterMode::Instance () != nullptr , Status::InvalidInState);
@@ -389,57 +416,28 @@ Status WaterHeaterManagementDelegate::CheckIfHeatNeedsToBeTurnedOnOrOff()
389
416
// If a boost command is in progress or in manual mode, find a heating source and "turn it on".
390
417
if (mBoostState == BoostStateEnum::kActive || mode == WaterHeaterMode::kModeManual )
391
418
{
392
- // Find out from the manufacturer object the heating sources to use.
393
- BitMask<WaterHeaterDemandBitmap> heaterDemand = mpWhmManufacturer->DetermineHeatingSources ();
394
-
395
- SetHeatDemand (heaterDemand);
396
-
397
- // And turn the heating of the water tank on.
398
- status = mpWhmManufacturer->TurnHeatingOn (mBoostEmergencyBoost .HasValue () ? mBoostEmergencyBoost .Value () : false );
419
+ heatingOp = HeatingOp::TurnHeatingOn;
399
420
}
400
421
}
401
422
else if (mBoostState == BoostStateEnum::kInactive && mode == WaterHeaterMode::kModeOff )
402
423
{
403
424
// The water temperature is not at the target temperature but there is no boost command in progress and the mode is Off
404
425
// so need to ensure the heating is turned off.
405
- ChipLogError (AppServer, " CheckIfHeatNeedsToBeTurnedOnOrOff turning heating off due to no boost cmd and kModeOff" );
426
+ ChipLogError (AppServer, " DetermineIfChangingHeatingState turning heating off due to no boost cmd and kModeOff" );
406
427
407
- SetHeatDemand (BitMask<WaterHeaterDemandBitmap>(0 ));
408
-
409
- turningHeatOff = true ;
428
+ heatingOp = HeatingOp::TurnHeatingOff;
410
429
}
411
430
}
412
431
else if (mHeatDemand .Raw () != 0 )
413
432
{
414
433
// The water in the tank has reached the target temperature - need to turn the heating off
415
- SetHeatDemand (BitMask<WaterHeaterDemandBitmap>(0 ));
416
-
417
- turningHeatOff = true ;
434
+ heatingOp = HeatingOp::TurnHeatingOff;
418
435
419
436
// If a boost command is in progress, record that the target temperature has been reached.
420
437
mBoostTargetTemperatureReached = (mBoostState == BoostStateEnum::kActive );
421
438
}
422
439
423
- if (turningHeatOff)
424
- {
425
- // If running a boost command with the oneShot parameter and turning heat off, then must have
426
- // reached the boost command target temperature -> that's the boost command complete.
427
- if (mBoostState == BoostStateEnum::kActive && mBoostOneShot .HasValue () && mBoostOneShot .Value ())
428
- {
429
- SetBoostState (BoostStateEnum::kInactive );
430
-
431
- DeviceLayer::SystemLayer ().CancelTimer (BoostTimerExpiry, this );
432
-
433
- mBoostEmergencyBoost .ClearValue ();
434
-
435
- status = mpWhmManufacturer->BoostCommandCancelled ();
436
- }
437
-
438
- // Turn the heating off
439
- status = mpWhmManufacturer->TurnHeatingOff ();
440
- }
441
-
442
- return status;
440
+ return Status::Success;
443
441
}
444
442
445
443
Status WaterHeaterManagementDelegate::SetWaterHeaterMode (uint8_t modeValue)
0 commit comments