supla-device
Loading...
Searching...
No Matches
action_trigger.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
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
20#define SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
21
22#include <stdint.h>
23
24#include <supla/action_handler.h>
25#include <supla/actions.h>
26#include <supla/at_channel.h>
27#include <supla/element.h>
28
29namespace Supla {
30
31namespace Protocol {
32class SuplaSrpc;
33}
34
35enum ActionHandlingType : uint8_t {
36 ActionHandlingType_RelayOnSuplaServer = 0,
37 ActionHandlingType_PublishAllDisableNone = 1,
38 ActionHandlingType_PublishAllDisableAll = 2
39};
40
41namespace Control {
42
43class Button;
44
45class ActionTrigger : public Element, public ActionHandler {
46 public:
47 ActionTrigger();
48 virtual ~ActionTrigger();
49
50 // Use below methods to attach button instance to ActionTrigger.
51 // It will automatically register to all supported button actions
52 // during onInit() call on action trigger instance.
53 void attach(Supla::Control::Button *);
54 void attach(Supla::Control::Button &);
55
56 // Makes AT channel related to other channel, so Supla Cloud will not
57 // list AT as a separate channel, but it will be extending i.e. Relay
58 // channel.
59 void setRelatedChannel(Element *);
60 void setRelatedChannel(Channel *);
61 void setRelatedChannel(Element &);
62 void setRelatedChannel(Channel &);
63
64 void handleAction(int event, int action) override;
65 void activateAction(int action) override;
66 Supla::Channel *getChannel() override;
67 const Supla::Channel *getChannel() const override;
68 void onInit() override;
69 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr) override;
71 bool local = false) override;
72 void onLoadConfig(SuplaDeviceClass *) override;
73 void onLoadState() override;
74 void onSaveState() override;
75
76 void disableATCapability(uint32_t capToDisable);
77 void enableStateStorage();
78
79 static int actionTriggerCapToButtonEvent(uint32_t actionCap);
80 static int actionTriggerCapToActionId(uint32_t actionCap);
81 static int getActionTriggerCap(int action);
82
83 bool isAnyActionEnabledOnServer() const;
84
85 void setAlwaysUseOnClick1();
86
87 void enable();
88 void disable();
89
90 protected:
91 void addActionToButtonAndDisableIt(int event, int action);
92 void parseActiveActionsFromServer();
93
94 Supla::Control::Button *attachedButton = nullptr;
95 Supla::ActionHandlerClient *localHandlerForEnabledAt = nullptr;
96 Supla::ActionHandlerClient *localHandlerForDisabledAt = nullptr;
97 uint32_t activeActionsFromServer = 0;
98 uint32_t disablesLocalOperation = 0;
99 uint32_t disabledCapabilities = 0;
100
101 Supla::AtChannel channel;
102
103 ActionHandlingType actionHandlingType = ActionHandlingType_RelayOnSuplaServer;
104 bool storageEnabled = false;
105 bool alwaysUseOnClick1 = false;
106 bool enabled = true;
107};
108
109} // namespace Control
110} // namespace Supla
111
112#endif // SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
Definition SuplaDevice.h:153
Definition local_action.h:27
Definition action_handler.h:21
Definition at_channel.h:25
Definition channel.h:33
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition action_trigger.cpp:549
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local=false) override
Handles "set channel config" request from server.
Definition action_trigger.cpp:308
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition action_trigger.cpp:196
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition action_trigger.cpp:349
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:595
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:556
Definition button.h:34
Definition supla_srpc.h:55
Definition proto.h:3071