supla-device
Loading...
Searching...
No Matches
condition.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_CONDITION_H_
5#define SRC_SUPLA_CONDITION_H_
6
7#include "action_handler.h"
8#include "condition_getter.h"
9
10namespace Supla {
11
12class ElementWithChannelActions;
13
14class Condition : public ActionHandler {
15 public:
16 Condition(double threshold, bool useAlternativeValue);
17 Condition(double threshold, ConditionGetter *getter);
18
19 virtual ~Condition();
20 void setSource(ElementWithChannelActions *src);
21 void setClient(ActionHandler *clientPtr);
22 void setSource(ElementWithChannelActions &src); // NOLINT(runtime/references)
23 void setClient(ActionHandler &clientPtr); // NOLINT(runtime/references)
24
25 void activateAction(int action) override;
26 void handleAction(int event, int action) override;
27 bool deleteClient() override;
28 ActionHandler *getRealClient() override;
29
30 virtual bool checkConditionFor(double val, bool isValid = true);
31
32 void setThreshold(double val);
33
34 protected:
35 virtual bool condition(double val, bool isValid = true) = 0;
36
37 double threshold = 0;
38 bool useAlternativeValue = false;
39 bool alreadyFired = false;
40 Supla::ElementWithChannelActions *source = nullptr;
41 Supla::ActionHandler *client = nullptr;
42 Supla::ConditionGetter *getter = nullptr;
43};
44
45}; // namespace Supla
46
47Supla::Condition *OnLess(double threshold,
48 bool useAlternativeValue = false);
49Supla::Condition *OnLessEq(double threshold,
50 bool useAlternativeValue = false);
51Supla::Condition *OnGreater(double threshold,
52 bool useAlternativeValue = false);
53Supla::Condition *OnGreaterEq(double threshold,
54 bool useAlternativeValue = false);
55Supla::Condition *OnBetween(double threshold1,
56 double threshold2,
57 bool useAlternativeValue = false);
58Supla::Condition *OnBetweenEq(double threshold1,
59 double threshold2,
60 bool useAlternativeValue = false);
61Supla::Condition *OnEqual(double threshold,
62 bool useAlternativeValue = false);
63Supla::Condition *OnInvalid(bool useAlternativeValue = false);
64
65Supla::Condition *OnLess(double threshold, Supla::ConditionGetter *);
66Supla::Condition *OnLessEq(double threshold, Supla::ConditionGetter *);
67Supla::Condition *OnGreater(double threshold, Supla::ConditionGetter *);
68Supla::Condition *OnGreaterEq(double threshold, Supla::ConditionGetter *);
69Supla::Condition *OnBetween(double threshold1,
70 double threshold2,
72Supla::Condition *OnBetweenEq(double threshold1,
73 double threshold2,
75Supla::Condition *OnEqual(double threshold, Supla::ConditionGetter *);
77
78#endif // SRC_SUPLA_CONDITION_H_
Definition action_handler.h:8
Definition condition_getter.h:14
Definition condition.h:14
Definition element_with_channel_actions.h:66