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 rebuildForAttachedButton();
77 void disableATCapability(uint32_t capToDisable);
78 void enableStateStorage();
79
80 static int actionTriggerCapToButtonEvent(uint32_t actionCap);
81 static int actionTriggerCapToActionId(uint32_t actionCap);
82 static int getActionTriggerCap(int action);
83
84 bool isAnyActionEnabledOnServer() const;
85
86 void setAlwaysUseOnClick1();
87
88 void enable();
89 void disable();
90
91 protected:
92 void addActionToButtonAndDisableIt(int event, int action);
93 void parseActiveActionsFromServer();
94
95 Supla::Control::Button *attachedButton = nullptr;
96 Supla::ActionHandlerClient *localHandlerForEnabledAt = nullptr;
97 Supla::ActionHandlerClient *localHandlerForDisabledAt = nullptr;
98 Supla::ActionHandler *localHandlerClient = nullptr;
99 uint16_t localHandlerAction = 0;
100 uint32_t activeActionsFromServer = 0;
101 uint32_t disablesLocalOperation = 0;
102 uint32_t disabledCapabilities = 0;
103
104 Supla::AtChannel channel;
105
106 ActionHandlingType actionHandlingType = ActionHandlingType_RelayOnSuplaServer;
107 bool storageEnabled = false;
108 bool alwaysUseOnClick1 = false;
109 bool enabled = true;
110 bool localHandlerSwitchConfigured = false;
111};
112
113} // namespace Control
114} // namespace Supla
115
116#endif // SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
Definition SuplaDevice.h:177
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:585
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local=false) override
Handles "set channel config" request from server.
Definition action_trigger.cpp:316
const Supla::Channel * getChannel() const override
Returns pointer to main channel.
Definition action_trigger.cpp:64
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition action_trigger.cpp:199
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:358
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:631
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:592
Definition button.h:34
Definition supla_srpc.h:61
Definition proto.h:3412