supla-device
Loading...
Searching...
No Matches
element_with_channel_actions.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_ELEMENT_WITH_CHANNEL_ACTIONS_H_
20#define SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
21
22#include <supla/element.h>
23#include <supla/channels/channel.h>
24#include <supla/local_action.h>
25#include <supla/action_handler.h>
26#include <supla/condition.h>
27
28namespace Supla {
29
30enum class ChannelConfigState : uint8_t {
31 None = 0,
32 LocalChangePending = 1,
33 SetChannelConfigSend = 2,
34 SetChannelConfigFailed = 3,
35 WaitForConfigFinished = 4,
36 OcrConfigPending = 5,
37 SetChannelOcrConfigSend = 6,
38};
39
40class Condition;
41
42class ElementWithChannelActions : public Element, public LocalAction {
43 public:
44 // Override local action methods in order to delegate execution to Channel
45 void addAction(uint16_t action,
46 ActionHandler &client, // NOLINT(runtime/references)
47 uint16_t event,
48 bool alwaysEnabled = false) override;
49 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
50 bool alwaysEnabled = false) override;
51 virtual void addAction(uint16_t action,
52 ActionHandler &client, // NOLINT(runtime/references)
53 Supla::Condition *condition,
54 bool alwaysEnabled = false);
55 virtual void addAction(uint16_t action, ActionHandler *client,
56 Supla::Condition *condition,
57 bool alwaysEnabled = false);
58
59 bool isEventAlreadyUsed(uint16_t event, bool ignoreAlwaysEnabled) override;
60 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
61 bool iterateConnected() override;
62 void handleChannelConfigFinished() override;
63 uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override;
65 TSDS_SetChannelConfigResult *result) override;
66 void purgeConfig() override;
67
68 void clearChannelConfigChangedFlag();
69
70 void runAction(uint16_t event) const override;
71
72 // returns true if function was changed (previous one was different)
73 virtual bool setAndSaveFunction(_supla_int_t channelFunction);
74 virtual bool loadFunctionFromConfig();
75 virtual bool saveConfigChangeFlag();
76 virtual bool loadConfigChangeFlag();
77 bool isAnyUpdatePending() override;
78
79 // methods to override for channels with runtime config support
80 virtual uint8_t applyChannelConfig(TSD_ChannelConfig *result, bool local);
81 virtual void fillChannelConfig(void *channelConfig, int *size);
82 virtual void fillChannelOcrConfig(void *channelConfig, int *size);
83
84 void triggerSetChannelConfig();
85
86 protected:
87 virtual bool hasOcrConfig() const;
88 virtual bool isOcrConfigMissing() const;
89 virtual void clearOcrConfig();
90 Supla::ChannelConfigState channelConfigState =
91 Supla::ChannelConfigState::None;
92 bool configFinishedReceived = false;
93 uint8_t setChannelConfigAttempts = 0;
94};
95
96}; // namespace Supla
97
98#endif // SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
Definition action_handler.h:21
Definition condition.h:27
Definition element_with_channel_actions.h:42
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition element_with_channel_actions.cpp:422
bool isAnyUpdatePending() override
Returns true if any update is pending.
Definition element_with_channel_actions.cpp:162
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition element_with_channel_actions.cpp:193
void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result) override
Handles "set channel config" reply from server.
Definition element_with_channel_actions.cpp:389
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override
Handles "set channel config" request from server.
Definition element_with_channel_actions.cpp:313
void handleChannelConfigFinished() override
Handles "channel config finished" message from server.
Definition element_with_channel_actions.cpp:214
bool iterateConnected() override
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition element_with_channel_actions.cpp:222
Definition local_action.h:53
Definition supla_srpc.h:55
Definition proto.h:2928
Definition proto.h:2912