supla-device
Loading...
Searching...
No Matches
valve_base.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_VALVE_BASE_H_
20#define SRC_SUPLA_CONTROL_VALVE_BASE_H_
21
22#include <supla/channel_element.h>
23#include <supla-common/proto.h>
24#include <supla/action_handler.h>
25
26namespace Supla {
27namespace Control {
28
29#define SUPLA_VALVE_SENSOR_MAX 20
30
31#pragma pack(push, 1)
32struct ValveConfig {
33 ValveConfig();
34 uint8_t sensorData[SUPLA_VALVE_SENSOR_MAX];
35 uint8_t closeValveOnFloodType = 0; // SUPLA_VALVE_CLOSE_ON_FLOOD_TYPE_*
36 uint8_t reserved[31] = {};
37};
38#pragma pack(pop)
39
44class ValveBase : public ChannelElement, public ActionHandler {
45 public:
52 explicit ValveBase(bool openClose = true);
53
54 void onInit() override;
55 void iterateAlways() override;
56 void onLoadConfig(SuplaDeviceClass *) override;
57 void onLoadState() override;
58 void onSaveState() override;
59 Supla::ApplyConfigResult applyChannelConfig(TSD_ChannelConfig *result,
60 bool local = false) override;
61 void fillChannelConfig(void *channelConfig,
62 int *size,
63 uint8_t configType) override;
64 int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override;
65 void purgeConfig() override;
66
77 void handleAction(int event, int action) override;
78
82 void openValve();
83
87 void closeValve();
88
95 void setValve(uint8_t openLevel);
96
97
103 bool isFloodDetected();
104
108 void printConfig() const;
109
115 void saveConfig(bool local = true);
116
124 virtual void setValueOnDevice(uint8_t openLevel);
125
133 virtual uint8_t getValueOpenStateFromDevice();
134
144 bool addSensor(uint8_t channelNumber);
145
154 bool removeSensor(uint8_t channelNumber);
155
166 void setIgnoreManuallyOpenedTimeMs(uint32_t timeMs);
167
174 void setDefaultCloseValveOnFloodType(uint8_t type);
175
176 protected:
177 ValveConfig config = {};
178 uint32_t lastSensorsCheckTimestamp = 0;
179 uint32_t lastUpdateTimestamp = 0;
180 uint32_t lastCmdTimestamp = 0;
181 uint32_t ignoreManuallyOpenedTimeMs = 30000;
182 uint8_t lastOpenLevelState = 0;
183 uint8_t defaultCloseValveOnFloodType = SUPLA_VALVE_CLOSE_ON_FLOOD_TYPE_NONE;
184 bool previousSensorState[SUPLA_VALVE_SENSOR_MAX] = {};
185};
186
187}; // namespace Control
188}; // namespace Supla
189
190#endif // SRC_SUPLA_CONTROL_VALVE_BASE_H_
Definition SuplaDevice.h:93
Definition action_handler.h:21
void closeValve()
Close valve.
Definition valve_base.cpp:333
bool removeSensor(uint8_t channelNumber)
Remove sensor from the channel's configuration.
Definition valve_base.cpp:431
void printConfig() const
Print current configuration in logs (for debug purpose)
Definition valve_base.cpp:186
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition valve_base.cpp:53
void onLoadConfig(SuplaDeviceClass *) override
First method called on element in SuplaDevice.begin().
Definition valve_base.cpp:155
void onLoadState() override
Second method called on element in SuplaDevice.begin().
Definition valve_base.cpp:198
virtual uint8_t getValueOpenStateFromDevice()
Get value from device or any other interface.
Definition valve_base.cpp:453
bool addSensor(uint8_t channelNumber)
Add sensor to the channel's configuration.
Definition valve_base.cpp:388
void setIgnoreManuallyOpenedTimeMs(uint32_t timeMs)
Set ignore manually opened time in milliseconds.
Definition valve_base.cpp:466
void setDefaultCloseValveOnFloodType(uint8_t type)
Set default close valve on flood type.
Definition valve_base.cpp:492
void onSaveState() override
Method called periodically during SuplaDevice iteration.
Definition valve_base.cpp:225
void setValve(uint8_t openLevel)
Set valve.
Definition valve_base.cpp:341
void handleAction(int event, int action) override
Implementation of ActionHandler::handleAction.
Definition valve_base.cpp:470
void purgeConfig() override
Removes all configration data related to the element from Storage::Config.
Definition valve_base.cpp:176
void saveConfig(bool local=true)
Save current configuration to Config.
Definition valve_base.cpp:360
int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue) override
Handles "new value" request from server.
Definition valve_base.cpp:132
bool isFloodDetected()
Check all sensors and return true if flood is detected.
Definition valve_base.cpp:87
void openValve()
Open valve.
Definition valve_base.cpp:337
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition valve_base.cpp:49
ValveBase(bool openClose=true)
Constructor.
Definition valve_base.cpp:36
virtual void setValueOnDevice(uint8_t openLevel)
Set value on device or any other interface.
Definition valve_base.cpp:460
Definition valve_base.h:32
Definition proto.h:2987
Definition proto.h:1169