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 protected:
86 void addActionToButtonAndDisableIt(int event, int action);
87 void parseActiveActionsFromServer();
88
89 Supla::Control::Button *attachedButton = nullptr;
90 Supla::ActionHandlerClient *localHandlerForEnabledAt = nullptr;
91 Supla::ActionHandlerClient *localHandlerForDisabledAt = nullptr;
92 uint32_t activeActionsFromServer = 0;
93 uint32_t disablesLocalOperation = 0;
94 uint32_t disabledCapabilities = 0;
95
96 Supla::AtChannel channel;
97
98 ActionHandlingType actionHandlingType = ActionHandlingType_RelayOnSuplaServer;
99 bool storageEnabled = false;
100};
101
102} // namespace Control
103} // namespace Supla
104
105#endif // SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
Definition SuplaDevice.h:93
Definition local_action.h:28
Definition action_handler.h:21
Definition at_channel.h:24
Definition channel.h:33
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition action_trigger.cpp:536
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local=false) override
Handles "set channel config" request from server.
Definition action_trigger.cpp:297
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition action_trigger.cpp:194
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition action_trigger.cpp:338
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:582
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:543
Definition button.h:30
Definition supla_srpc.h:55
Definition proto.h:2912