forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhmDelegate.h
345 lines (296 loc) · 14.6 KB
/
WhmDelegate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <app-common/zap-generated/cluster-objects.h>
#include <app/clusters/water-heater-management-server/water-heater-management-server.h>
#include <protocols/interaction_model/StatusCode.h>
namespace chip {
namespace app {
namespace Clusters {
namespace WaterHeaterManagement {
class WhmManufacturer;
enum HeatingOp
{
TurnHeatingOn,
TurnHeatingOff,
LeaveHeatingUnchanged
};
// This is an application level delegate to handle operational state commands according to the specific business logic.
class WaterHeaterManagementDelegate : public WaterHeaterManagement::Delegate
{
public:
WaterHeaterManagementDelegate(EndpointId clustersEndpoint);
virtual ~WaterHeaterManagementDelegate() = default;
void SetWaterHeaterManagementInstance(WaterHeaterManagement::Instance & instance);
void SetWhmManufacturer(WhmManufacturer & whmManufacturer);
/*********************************************************************************
*
* Methods implementing the WaterHeaterManagement::Delegate interface
*
*********************************************************************************/
/**
* @brief Delegate should implement a handler to start boosting the water
* temperature as required. Upon receipt, the Water Heater SHALL
* transition into the BOOST state, which SHALL cause the water in
* the tank (or the TargetPercentage of the water, if included) to be
* heated towards the set point (or the TemporarySetpoint, if
* included), which in turn may cause a call for heat, even if the
* mode is OFF, or is TIMED and it is during one of the Off periods.
*
* @param duration Indicates the time period in seconds for which
* the BOOST state is activated before it
* automatically reverts to the previous mode
* (e.g. OFF, MANUAL or TIMED).
*
* @param oneShot Indicates whether the BOOST state should be
* automatically canceled once the hot water has
* first reached the set point temperature (or the
* TemporarySetpoint temperature, if specified)
* for the TargetPercentage (if specified).
*
* @param emergencyBoost Indicates that the consumer wants the water to
* be heated as quickly as practicable. This MAY
* cause multiple heat sources to be activated
* (e.g. a heat pump and direct electric heating
* element).
*
* @param temporarySetpoint Indicates the target temperature to which to
* heat the hot water for this Boost command. It
* SHALL be used instead of the normal set point
* temperature whilst the BOOST state is active.
*
* @param targetPercentage If the tank supports the TankPercent feature,
* this field indicates the amount of water that
* SHALL be heated by this Boost command before
* the heater is switched off.
*
* @param targetReheat If the tank supports the TankPercent feature,
* and the heating by this Boost command has
* ceased because the TargetPercentage of the
* water in the tank has been heated to the set
* point (or TemporarySetpoint if included), this
* field indicates the percentage to which the hot
* water in the tank SHALL be allowed to fall
* before again beginning to reheat it.
*
* @return Success if the boost command is accepted; otherwise the command
* SHALL be rejected with appropriate error.
*/
Protocols::InteractionModel::Status HandleBoost(uint32_t duration, Optional<bool> oneShot, Optional<bool> emergencyBoost,
Optional<int16_t> temporarySetpoint, Optional<Percent> targetPercentage,
Optional<Percent> targetReheat) override;
/**
* @brief Delegate should implement a handler to cancel a boost command.
* Upon receipt, the Water Heater SHALL transition back from the
* BOOST state to the previous mode (e.g. OFF, MANUAL or TIMED).
*
* @return It should report SUCCESS if successful and FAILURE otherwise.
*/
Protocols::InteractionModel::Status HandleCancelBoost() override;
// ------------------------------------------------------------------
// Get attribute methods
BitMask<WaterHeaterHeatSourceBitmap> GetHeaterTypes() override;
BitMask<WaterHeaterHeatSourceBitmap> GetHeatDemand() override;
uint16_t GetTankVolume() override;
Energy_mWh GetEstimatedHeatRequired() override;
Percent GetTankPercentage() override;
BoostStateEnum GetBoostState() override;
// ------------------------------------------------------------------
// Set attribute methods
void SetHeaterTypes(BitMask<WaterHeaterHeatSourceBitmap> heaterTypes);
void SetHeatDemand(BitMask<WaterHeaterHeatSourceBitmap> heatDemand);
void SetTankVolume(uint16_t tankVolume);
void SetEstimatedHeatRequired(Energy_mWh estimatedHeatRequired);
void SetTankPercentage(Percent tankPercentage);
void SetBoostState(BoostStateEnum boostState);
/***************************************************************************
*
* WaterHeaterManagementDelegate specific methods
*
***************************************************************************/
/**
* @brief Set the Water Header Mode and act accordingly.
*
* @param mode The Water Heater Mode (e.g. OFF, MANUAL or TIMED).
*/
Protocols::InteractionModel::Status SetWaterHeaterMode(uint8_t mode);
/**
* @brief Set the water temperature of the tank
*
* @param waterTemperature The water temperature in 100th's Celsius
*/
void SetWaterTemperature(int16_t waterTemperature);
/**
* @brief Set the target water temperature of the tank
*
* @param targetWaterTemperature The water temperature in 100th's Celsius
*/
void SetTargetWaterTemperature(int16_t targetWaterTemperature);
/**
* @brief Determine whether the heating sources need to be turned on or off or left unchanged.
*
* @return Success if the heating was successfully turned on or off or left unchanged otherwise an error
* code is returned if turning the heating on or off failed.
*/
Protocols::InteractionModel::Status ChangeHeatingIfNecessary();
/**
* @brief Static timer callback for when Boost timer expires.
*/
static void BoostTimerExpiry(System::Layer * systemLayer, void * delegate);
/**
* @brief Object timer callback for when Boost timer expires.
*/
void HandleBoostTimerExpiry();
/**
* Determines whether the tank water temperature has reached the target
* temperature.
*
* @return Returns True is tank water temperature has reached the target
* temperature, False otherwise.
*/
bool HasWaterTemperatureReachedTarget() const;
/**
* Simulates water being drawn from the water tank.
*
* @param percentageReplaced The % of water being replaced with water with
* a temperature of replacedWaterTemperature.
*
* @param replacedWaterTemperature The temperature of the
* percentageReplaced water.
*/
void DrawOffHotWater(Percent percentageReplaced, int16_t replacedWaterTemperature);
/**
* Set the temperature of the cold water that fills the tank as the hot water
* is drawn off.
*
* @param coldWaterTemperature The cold water temperature in 100th of a C
*/
void SetColdWaterTemperature(int16_t coldWaterTemperature);
private:
/**
* Return the target temperature.
* If a boost command is in progress and has a mBoostTemporarySetpoint value use that as the
* target temperature otherwise use the temperature set via SetTargetWaterTemperature().
*
* @return the target temperature
*/
int16_t GetActiveTargetWaterTemperature() const;
/**
* @brief Calculate the percentage of the water in the tank at the target
* temperature.
*
* @return Percentage of water at the target temperature
*/
uint8_t CalculateTankPercentage() const;
/**
* @brief Determine whether heating needs to be turned on or off or left as
* is.
*
* @param heatingOp[out] Set as determined whether heating needs to be
* turned on/off or left unchanged.
*
* @return Success if the heating operation could be determined otherwise
* returns with appropriate error.
*/
Protocols::InteractionModel::Status DetermineIfChangingHeatingState(HeatingOp & heatingOp);
private:
/***************************************************************************
*
* WaterHeaterManagementDelegate specific attributes
*
***************************************************************************/
// Need the following so can determine which features are supported
WaterHeaterManagement::Instance * mpWhmInstance;
// Pointer to the manufacturer specific object which understand the hardware
WhmManufacturer * mpWhmManufacturer;
// Target water temperature in 100ths of a C
int16_t mTargetWaterTemperature;
// Actual water temperature in 100ths of a C
int16_t mWaterTemperature;
// The cold water temperature in 100ths of a C
int16_t mColdWaterTemperature;
// Boost command parameters
// This field SHALL indicate whether the BOOST state should be automatically
// canceled once the hot water has first reached the set point temperature
// (or the TemporarySetpoint temperature, if specified) for the
// TargetPercentage (if specified).
Optional<bool> mBoostOneShot;
// This field indicates that the consumer wants the water to be heated as
// quickly as practicable. This MAY cause multiple heat sources to be
// activated (e.g. a heat pump and direct electric heating element).
Optional<bool> mBoostEmergencyBoost;
// This field indicates the target temperature to which to heat the hot
// water for this Boost command. It SHALL be used instead of the normal set
// point temperature whilst the BOOST state is active.
Optional<int16_t> mBoostTemporarySetpoint;
// If the tank supports the TankPercent feature, this field indicates the
// amount of water that SHALL be heated by this Boost command before the
// heater is switched off. This field is optional, however it SHALL be
// included if the TargetReheat field is included.
Optional<Percent> mBoostTargetPercentage;
// If the tank supports the TankPercent feature, and the heating by this
// Boost command has ceased because the TargetPercentage of the water in the
// tank has been heated to the set point (or TemporarySetpoint if included),
// this field indicates the percentage to which the hot water in the tank
// SHALL be allowed to fall before again beginning to reheat it. For example
// if the TargetPercentage was 80%, and the TargetReheat was 40%, then after
// initial heating to 80% hot water, the tank may have hot water drawn off
// until only 40% hot water remains. At this point the heater will begin to
// heat back up to 80% of hot water. If this field and the OneShot field
// were both omitted, heating would begin again after any water draw which
// reduced the TankPercentage below 80%.
Optional<Percent> mBoostTargetReheat;
// Track whether the water temperature has reached the water temperature
// specified in the boost command. Used in conjunction with the boost
// command boostTargetReheat parameter
bool mBoostTargetTemperatureReached;
/*********************************************************************************
*
* Member variables implementing the WaterHeaterManagement::Delegate interface
*
*********************************************************************************/
// This attribute SHALL indicate the methods to call for heat that the
// controller supports. If a bit is set then the controller supports the
// corresponding method.
BitMask<WaterHeaterHeatSourceBitmap> mHeaterTypes;
// This attribute SHALL indicate if the controller is asking for heat. If a
// bit is set then the corresponding call for heat is active.
BitMask<WaterHeaterHeatSourceBitmap> mHeatDemand;
// This attribute SHALL indicate the volume of water that the hot water tank
// can hold (in units of Litres). This allows an energy management system to
// estimate the required heating energy needed to reach the target
// temperature.
uint16_t mTankVolume;
// This attribute SHALL indicate the estimated heat energy needed to raise
// the water temperature to the target setpoint. This can be computed by
// taking the specific heat capacity of water (4182 J/kg °C) and by knowing
// the current temperature of the water, the tank volume and target
// temperature.
Energy_mWh mEstimatedHeatRequired;
// This attribute SHALL indicate an approximate level of hot water stored in
// the tank, which may help consumers understand the amount of hot water
// remaining in the tank.
Percent mTankPercentage;
// This attribute SHALL indicate if the BOOST state, as triggered by a Boost
// command, is currently active.
BoostStateEnum mBoostState;
};
} // namespace WaterHeaterManagement
} // namespace Clusters
} // namespace app
} // namespace chip