supla-device
Loading...
Searching...
No Matches
action_trigger.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
5#define SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
6
7#include <stdint.h>
8
9#include <supla/action_handler.h>
10#include <supla/actions.h>
11#include <supla/at_channel.h>
12#include <supla/element.h>
13
14namespace Supla {
15
16namespace Protocol {
17class SuplaSrpc;
18}
19
20enum ActionHandlingType : uint8_t {
21 ActionHandlingType_RelayOnSuplaServer = 0,
22 ActionHandlingType_PublishAllDisableNone = 1,
23 ActionHandlingType_PublishAllDisableAll = 2
24};
25
26namespace Control {
27
28class Button;
29
30class ActionTrigger : public Element, public ActionHandler {
31 public:
33 virtual ~ActionTrigger();
34
35 // Use below methods to attach button instance to ActionTrigger.
36 // It will automatically register to all supported button actions
37 // during onInit() call on action trigger instance.
38 void attach(Supla::Control::Button *);
39 void attach(Supla::Control::Button &);
40
41 // Makes AT channel related to other channel, so Supla Cloud will not
42 // list AT as a separate channel, but it will be extending i.e. Relay
43 // channel.
44 void setRelatedChannel(Element *);
45 void setRelatedChannel(Channel *);
46 void setRelatedChannel(Element &);
47 void setRelatedChannel(Channel &);
48
49 void handleAction(int event, int action) override;
50 void activateAction(int action) override;
51 Supla::Channel *getChannel() override;
52 const Supla::Channel *getChannel() const override;
53 void onInit() override;
54 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr) override;
56 bool local = false) override;
57 void onLoadConfig(SuplaDeviceClass *) override;
58 void onLoadState() override;
59 void onSaveState() override;
60
61 void rebuildForAttachedButton();
62 void disableATCapability(uint32_t capToDisable);
63 void enableStateStorage();
64
65 static int actionTriggerCapToButtonEvent(uint32_t actionCap);
66 static int actionTriggerCapToActionId(uint32_t actionCap);
67 static int getActionTriggerCap(int action);
68
69 bool isAnyActionEnabledOnServer() const;
70
71 void setAlwaysUseOnClick1();
72
73 void enable();
74 void disable();
75
76 protected:
77 void addActionToButtonAndDisableIt(int event, int action);
78 void parseActiveActionsFromServer();
79
80 Supla::Control::Button *attachedButton = nullptr;
81 Supla::ActionHandlerClient *localHandlerForEnabledAt = nullptr;
82 Supla::ActionHandlerClient *localHandlerForDisabledAt = nullptr;
83 Supla::ActionHandler *localHandlerClient = nullptr;
84 uint16_t localHandlerAction = 0;
85 uint32_t activeActionsFromServer = 0;
86 uint32_t disablesLocalOperation = 0;
87 uint32_t disabledCapabilities = 0;
88
89 Supla::AtChannel channel;
90
91 ActionHandlingType actionHandlingType = ActionHandlingType_RelayOnSuplaServer;
92 bool storageEnabled = false;
93 bool alwaysUseOnClick1 = false;
94 bool enabled = true;
95 bool localHandlerSwitchConfigured = false;
96};
97
98} // namespace Control
99} // namespace Supla
100
101#endif // SRC_SUPLA_CONTROL_ACTION_TRIGGER_H_
Definition SuplaDevice.h:167
Definition local_action.h:14
Definition action_handler.h:8
Definition at_channel.h:12
Definition channel.h:20
Definition action_trigger.h:30
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition action_trigger.cpp:575
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local=false) override
Handles "set channel config" request from server.
Definition action_trigger.cpp:301
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr) override
Method called each time when device successfully registers to Supla server.
Definition action_trigger.cpp:184
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition action_trigger.cpp:343
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:621
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition action_trigger.cpp:582
Definition button.h:21
Base class for all elements of SuplaDevice.
Definition element.h:27
Definition supla_srpc.h:47
Definition proto.h:3159