52 uint8_t staircaseFunction : 1;
53 uint8_t impulseFunction : 1;
54 uint8_t overcurrent : 1;
55 uint8_t weeklySchedule : 1;
57 uint8_t operatingMode : 2;
63 static_assert(
sizeof(
RelayFlags) ==
sizeof(uint8_t),
64 "Flags size must be 1 byte");
67 _supla_int_t functions =
68 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
72 _supla_int_t functions =
73 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
74 explicit Relay(
int pin,
76 _supla_int_t functions =
77 (0xFF ^ SUPLA_BIT_FUNC_CONTROLLINGTHEROLLERSHUTTER));
81 virtual Relay &setDefaultStateOn();
82 virtual Relay &setDefaultStateOff();
83 virtual Relay &setDefaultStateRestore();
84 virtual Relay &setPreloadStateOnSoftReset(
bool enabled =
true);
85 virtual Relay &keepTurnOnDuration(
bool keep =
true);
87 [[deprecated(
"Use IoPin::writeActive/writeInactive instead")]]
virtual uint8_t
89 [[deprecated(
"Use IoPin::writeActive/writeInactive instead")]]
virtual uint8_t
91 virtual void turnOn(_supla_int_t duration = 0);
92 virtual void turnOff(_supla_int_t duration = 0);
94 virtual void toggle(_supla_int_t duration = 0);
98 void handleAction(
int event,
int action)
override;
110 bool local =
false)
override;
111 void fillChannelConfig(
void *channelConfig,
113 uint8_t configType)
override;
128 unsigned _supla_int_t getStoredTurnOnDurationMs();
129 void setStoredTurnOnDurationMs(uint32_t durationMs);
131 bool isStaircaseFunction(uint32_t functionToCheck = 0)
const;
132 bool isImpulseFunction(uint32_t functionToCheck = 0)
const;
133 void disableCountdownTimerFunction();
134 void enableCountdownTimerFunction();
135 bool isCountdownTimerFunctionEnabled()
const;
136 void setMinimumAllowedDurationMs(uint32_t durationMs);
138 static void setRelayStorageSaveDelay(uint32_t delayMs);
140 bool isDefaultRelatedMeterChannelSet()
const;
141 uint32_t getCurrentValueFromMeter()
const;
142 void setDefaultRelatedMeterChannelNo(
int channelNo);
143 void setTurnOffWhenEmptyAggregator(
bool turnOff);
158 return overcurrentThreshold;
174 return overcurrentMaxAllowed;
183 defaultStaircaseDurationMs = durationMs;
192 defaultImpulseDurationMs = durationMs;
196 bool setAndSaveFunction(uint32_t channelFunction)
override;
212 bool isFullyInitialized()
const;
240 void disableCyclicMode();
241 bool isCyclicMode()
const;
243 bool isWeeklyScheduleSupported()
const;
244 Relay &setWeeklyScheduleAvailable(
bool available =
true);
245 bool isWeeklyScheduleAvailable()
const;
246 Relay &setAutomaticModeSupported(
bool supported =
true);
247 bool isAutomaticModeSupported()
const;
248 bool isAutomaticMode()
const;
249 bool setAutomaticMode(
bool enabled);
250 bool setWeeklyScheduleController(
257 _supla_int_t functions,
266 void applyDuration(int32_t durationMs,
bool turnOn);
269 virtual void setNewChannelValue(
bool value);
270 virtual void fillDefaultWeeklySchedule(
272 virtual bool canUseWeeklySchedule()
const;
275 virtual bool isWeeklyScheduleProgramModeSupported(uint8_t mode)
const;
276 bool isWeeklyScheduleProgramModeAvailable(uint8_t mode)
const;
278 bool isWeeklyScheduleProgramModeApplicable(uint8_t mode)
const;
279 bool hasAnyWeeklyScheduleProgramModeAvailable()
const;
280 virtual void iterateAutomaticMode();
282 void saveConfig()
const;
283 void loadRelayConfigOnly();
284 bool ensureNativeWeeklyScheduleController();
285 void updateWeeklyScheduleCapabilities();
286 void updateAutomaticModeCapability();
287 void purgeRelayConfigOnly();
288 void updateTimerValue();
289 void emitCountdownTimerActionIfNeeded();
290 void updateRelayHvacAggregator();
291 bool isManualActionAllowed(
bool turnOn)
const;
292 bool isManualForcedModeSupported()
const;
293 bool setManualForcedMode(uint8_t mode);
294 void disableWeeklySchedule();
295 void applyWeeklyScheduleProgram(uint8_t programMode,
bool programChanged);
296 virtual bool applyWeeklyScheduleState(
bool on);
297 void notifyWeeklyScheduleManualAction();
298 uint32_t durationMs = 0;
299 uint32_t storedTurnOnDurationMs = 0;
300 uint32_t durationTimestamp = 0;
301 uint32_t turnOffDurationForCycle = 0;
302 uint16_t defaultStaircaseDurationMs = 10000;
303 uint16_t defaultImpulseDurationMs = 500;
305 uint32_t overcurrentThreshold = 0;
306 uint32_t overcurrentMaxAllowed = 0;
307 uint32_t overcurrentActiveTimestamp = 0;
308 uint32_t overcurrentCheckTimestamp = 0;
310 uint32_t timerUpdateTimestamp = 0;
311 uint32_t lastCountdownTimerRemainingSec = UINT32_MAX;
312 uint32_t postponeCommTimestamp = 0;
316 uint16_t minimumAllowedDurationMs = 0;
317 int16_t defaultRelatedMeterChannelNo = -1;
322 : keepTurnOnDurationMs(
false),
323 turnOffWhenEmptyAggregator(
true),
325 restartTimerOnToggle(
false),
326 skipInitialStateSetting(
false),
327 preloadStateOnSoftReset(
false),
328 automaticModeSupported(
false),
329 weeklyScheduleAvailable(
false) {}
331 uint8_t keepTurnOnDurationMs : 1;
332 uint8_t turnOffWhenEmptyAggregator : 1;
333 uint8_t initDone : 1;
334 uint8_t restartTimerOnToggle : 1;
335 uint8_t skipInitialStateSetting : 1;
336 uint8_t preloadStateOnSoftReset : 1;
337 uint8_t automaticModeSupported : 1;
339 uint8_t weeklyScheduleAvailable : 1;
343 "Relay runtime flags must fit in uint8_t");
347 int8_t stateOnInit = STATE_ON_INIT_OFF;
351 static uint16_t relayStorageSaveDelay;