hueplusplus 1.2.0
Loading...
Searching...
No Matches
Rule.h
Go to the documentation of this file.
1
22#ifndef INCLUDE_HUEPLUSPLUS_RULE_H
23#define INCLUDE_HUEPLUSPLUS_RULE_H
24
25#include <string>
26
27#include "APICache.h"
28#include "Action.h"
29#include "Condition.h"
30#include "HueCommandAPI.h"
31#include "TimePattern.h"
32
33namespace hueplusplus
34{
35
42class Rule
43{
44public:
48 Rule(int id, const std::shared_ptr<APICache>& baseCache);
54 Rule(int id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json& currentState);
55
63 void refresh(bool force = false);
64
67 void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
68
70 int getId() const;
71
75 std::string getName() const;
76
84 void setName(const std::string& name);
85
88
91
93 int getTimesTriggered() const;
94
96 bool isEnabled() const;
103 void setEnabled(bool enabled);
104
106 std::string getOwner() const;
107
112 std::vector<Condition> getConditions() const;
116 std::vector<Action> getActions() const;
117
124 void setConditions(const std::vector<Condition>& conditions);
128 void setActions(const std::vector<Action>& actions);
129
130private:
140 nlohmann::json sendPutRequest(const nlohmann::json& request, FileInfo fileInfo);
141
142private:
143 int id;
144 APICache state;
145};
146
151{
152public:
156 CreateRule(const std::vector<Condition>& conditions, const std::vector<Action>& actions);
159 CreateRule& setName(const std::string& name);
160
163 CreateRule& setStatus(bool enabled);
164
167 nlohmann::json getRequest() const;
168
169private:
170 nlohmann::json request;
171};
172
173} // namespace hueplusplus
174
175#endif
Caches API GET requests and refreshes regularly.
Definition APICache.h:38
Parameters for creating a new Rule.
Definition Rule.h:151
CreateRule & setStatus(bool enabled)
Set status.
Definition Rule.cpp:286
CreateRule & setName(const std::string &name)
Set name.
Definition Rule.cpp:280
nlohmann::json getRequest() const
Get request to create the rule.
Definition Rule.cpp:292
Definition HueCommandAPI.h:38
Rule stored in the bridge.
Definition Rule.h:43
void setName(const std::string &name)
Set rule name.
Definition Rule.cpp:170
std::vector< Condition > getConditions() const
Get the conditions that have to be met.
Definition Rule.cpp:213
std::string getOwner() const
Get user that created or last changed the rule.
Definition Rule.cpp:208
void setActions(const std::vector< Action > &actions)
Set actions for the rule.
Definition Rule.cpp:247
int getId() const
Get rule identifier.
Definition Rule.cpp:160
std::vector< Action > getActions() const
Get the actions that are executed.
Definition Rule.cpp:224
int getTimesTriggered() const
Get the number of times the rule was triggered.
Definition Rule.cpp:192
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets custom refresh interval for this rule.
Definition Rule.cpp:155
time::AbsoluteTime getCreated() const
Get created time.
Definition Rule.cpp:177
bool isEnabled() const
Get whether rule is enabled or disabled.
Definition Rule.cpp:197
time::AbsoluteTime getLastTriggered() const
Get time the rule was last triggered.
Definition Rule.cpp:182
void setConditions(const std::vector< Condition > &conditions)
Set conditions for the rule.
Definition Rule.cpp:235
std::string getName() const
Get rule name.
Definition Rule.cpp:165
void refresh(bool force=false)
Refreshes internal cached state.
Definition Rule.cpp:143
void setEnabled(bool enabled)
Enable or disable rule.
Definition Rule.cpp:202
One-time, absolute time point.
Definition TimePattern.h:73
Namespace for the hueplusplus library.
Definition Action.h:28
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35