supla-device
Loading...
Searching...
No Matches
element_with_channel_actions.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
5#define SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
6
7#include <stdint.h>
8#include <supla-common/proto.h>
9#include <supla/element.h>
10#include <supla/local_action.h>
11
12namespace Supla {
13
14enum class ChannelConfigState : uint8_t {
15 None = 0,
16 LocalChangePending = 1,
17 SetChannelConfigSend = 2,
18 SetChannelConfigFailed = 3,
19 WaitForConfigFinished = 4,
20 ResendConfig = 5,
21 LocalChangeSent = 6
22};
23
24enum class ApplyConfigResult : uint8_t {
25 NotSupported,
26 Success,
27 DataError,
28 SetChannelConfigNeeded,
29};
30
31#pragma pack(push, 1)
33 private:
34 union {
35 struct {
36 uint8_t configFinishedReceived: 1;
37 uint8_t defaultConfig: 1;
38 uint8_t weeklySchedule: 1;
39 uint8_t altWeeklySchedule: 1;
40 uint8_t ocrConfig: 1;
41 uint8_t extendedDefaultConfig: 1;
42 };
43 uint8_t all = 0;
44 };
45
46 public:
47 bool isSet(int configType) const;
48 void clear(int configType);
49 void clearAll();
50 void setAll(uint8_t values);
51 uint8_t getAll() const;
52 void setConfigFinishedReceived();
53 void clearConfigFinishedReceived();
54 bool isConfigFinishedReceived() const;
55 void set(int configType, bool value = true);
56 bool operator!=(const ConfigTypesBitmap &other) const;
57};
58#pragma pack(pop)
59
60class Condition;
61class ActionHandler;
62namespace Protocol {
63class SuplaSrpc;
64} // namespace Protocol
65
67 public:
69 ElementMode mode = ElementMode::Registered);
70
71 // Override local action methods in order to delegate execution to Channel
72 void addAction(uint16_t action,
73 ActionHandler &client, // NOLINT(runtime/references)
74 uint16_t event,
75 bool alwaysEnabled = false) override;
76 void addAction(uint16_t action, ActionHandler *client, uint16_t event,
77 bool alwaysEnabled = false) override;
85 virtual void addAction(uint16_t action,
86 ActionHandler &client, // NOLINT(runtime/references)
87 uint16_t event,
88 Supla::Condition *condition,
89 bool alwaysEnabled = false);
93 virtual void addAction(uint16_t action, ActionHandler *client,
94 uint16_t event,
95 Supla::Condition *condition,
96 bool alwaysEnabled = false);
97 virtual void addAction(uint16_t action,
98 ActionHandler &client, // NOLINT(runtime/references)
99 Supla::Condition *condition,
100 bool alwaysEnabled = false);
101 virtual void addAction(uint16_t action, ActionHandler *client,
102 Supla::Condition *condition,
103 bool alwaysEnabled = false);
104
105 bool isEventAlreadyUsed(uint16_t event, bool ignoreAlwaysEnabled) override;
106 void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override;
107 bool iterateConnected() override;
108 void handleChannelConfigFinished() override;
109 void handleChannelConfigFinished(int channelNumber) override;
110 uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override;
112 TSDS_SetChannelConfigResult *result) override;
113 void purgeConfig() override;
114
115
116 void runAction(uint16_t event) const override;
117
118 bool isAnyUpdatePending() const override;
119
120 // methods to override for channels with runtime config support
121 virtual ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
122 bool local);
123 virtual void fillChannelConfig(void *channelConfig, int *size, uint8_t index);
124
125 void triggerSetChannelConfig(int configType = SUPLA_CONFIG_TYPE_DEFAULT);
126
127 protected:
128 // returns true if function was changed (previous one was different)
129 virtual bool setAndSaveFunction(uint32_t channelFunction);
130 virtual bool loadFunctionFromConfig();
131 virtual bool saveConfigChangeFlag() const;
132 virtual bool loadConfigChangeFlag();
133 void clearChannelConfigChangedFlag();
134 bool iterateConfigExchange();
140 int getNextConfigType() const;
141 Supla::ChannelConfigState channelConfigState =
142 Supla::ChannelConfigState::None;
143
144 uint8_t setChannelConfigAttempts = 0;
145 ConfigTypesBitmap usedConfigTypes;
146 ConfigTypesBitmap receivedConfigTypes;
147};
148
149}; // namespace Supla
150
151#endif // SRC_SUPLA_ELEMENT_WITH_CHANNEL_ACTIONS_H_
Definition action_handler.h:8
Definition condition.h:14
Definition element_with_channel_actions.h:66
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition element_with_channel_actions.cpp:494
void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc) override
Method called each time when device successfully registers to Supla server.
Definition element_with_channel_actions.cpp:302
bool isAnyUpdatePending() const override
Returns true if any update is pending.
Definition element_with_channel_actions.cpp:273
void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result) override
Handles "set channel config" reply from server.
Definition element_with_channel_actions.cpp:457
int getNextConfigType() const
Returns the next config type to be sent.
Definition element_with_channel_actions.cpp:597
uint8_t handleChannelConfig(TSD_ChannelConfig *result, bool local) override
Handles "set channel config" request from server.
Definition element_with_channel_actions.cpp:359
void handleChannelConfigFinished() override
Handles "channel config finished" message from server.
Definition element_with_channel_actions.cpp:323
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:347
Base class for all elements of SuplaDevice.
Definition element.h:27
Definition local_action.h:42
Definition supla_srpc.h:46
Definition element_with_channel_actions.h:32
Definition proto.h:3446
Definition proto.h:3430