supla-device
Loading...
Searching...
No Matches
condition.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15*/
16
17#ifndef SRC_SUPLA_CONDITION_H_
18#define SRC_SUPLA_CONDITION_H_
19
20#include "action_handler.h"
21#include "condition_getter.h"
22
23namespace Supla {
24
26
27class Condition : public ActionHandler {
28 public:
29 Condition(double threshold, bool useAlternativeValue);
30 Condition(double threshold, ConditionGetter *getter);
31
32 virtual ~Condition();
33 void setSource(ElementWithChannelActions *src);
34 void setClient(ActionHandler *clientPtr);
35 void setSource(ElementWithChannelActions &src); // NOLINT(runtime/references)
36 void setClient(ActionHandler &clientPtr); // NOLINT(runtime/references)
37
38 void activateAction(int action) override;
39 void handleAction(int event, int action) override;
40 bool deleteClient() override;
41 ActionHandler *getRealClient() override;
42
43 virtual bool checkConditionFor(double val, bool isValid = true);
44
45 void setThreshold(double val);
46
47 protected:
48 virtual bool condition(double val, bool isValid = true) = 0;
49
50 double threshold = 0;
51 bool useAlternativeValue = false;
52 bool alreadyFired = false;
53 Supla::ElementWithChannelActions *source = nullptr;
54 Supla::ActionHandler *client = nullptr;
55 Supla::ConditionGetter *getter = nullptr;
56};
57
58}; // namespace Supla
59
60Supla::Condition *OnLess(double threshold,
61 bool useAlternativeValue = false);
62Supla::Condition *OnLessEq(double threshold,
63 bool useAlternativeValue = false);
64Supla::Condition *OnGreater(double threshold,
65 bool useAlternativeValue = false);
66Supla::Condition *OnGreaterEq(double threshold,
67 bool useAlternativeValue = false);
68Supla::Condition *OnBetween(double threshold1,
69 double threshold2,
70 bool useAlternativeValue = false);
71Supla::Condition *OnBetweenEq(double threshold1,
72 double threshold2,
73 bool useAlternativeValue = false);
74Supla::Condition *OnEqual(double threshold,
75 bool useAlternativeValue = false);
76Supla::Condition *OnInvalid(bool useAlternativeValue = false);
77
78Supla::Condition *OnLess(double threshold, Supla::ConditionGetter *);
79Supla::Condition *OnLessEq(double threshold, Supla::ConditionGetter *);
80Supla::Condition *OnGreater(double threshold, Supla::ConditionGetter *);
81Supla::Condition *OnGreaterEq(double threshold, Supla::ConditionGetter *);
82Supla::Condition *OnBetween(double threshold1,
83 double threshold2,
85Supla::Condition *OnBetweenEq(double threshold1,
86 double threshold2,
88Supla::Condition *OnEqual(double threshold, Supla::ConditionGetter *);
90
91#endif // SRC_SUPLA_CONDITION_H_
Definition action_handler.h:21
Definition condition_getter.h:27
Definition condition.h:27
Definition element_with_channel_actions.h:42