hueplusplus  1.0.0
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 
33 namespace hueplusplus
34 {
35 
42 class Rule
43 {
44 public:
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 
130 private:
140  nlohmann::json sendPutRequest(const nlohmann::json& request, FileInfo fileInfo);
141 
142 private:
143  int id;
144  APICache state;
145 };
146 
151 {
152 public:
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 
169 private:
170  nlohmann::json request;
171 };
172 
173 } // namespace hueplusplus
174 
175 #endif
void setConditions(const std::vector< Condition > &conditions)
Set conditions for the rule.
Definition: Rule.cpp:235
Definition: HueCommandAPI.h:37
Rule(int id, const std::shared_ptr< APICache > &baseCache)
Creates rule with shared cache.
Definition: Rule.cpp:133
Rule stored in the bridge.
Definition: Rule.h:42
Namespace for the hueplusplus library.
Definition: Action.h:27
Caches API GET requests and refreshes regularly.
Definition: APICache.h:37
void refresh(bool force=false)
Refreshes internal cached state.
Definition: Rule.cpp:143
std::string getOwner() const
Get user that created or last changed the rule.
Definition: Rule.cpp:208
Parameters for creating a new Rule.
Definition: Rule.h:150
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
One-time, absolute time point.
Definition: TimePattern.h:72
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets custom refresh interval for this rule.
Definition: Rule.cpp:155
void setEnabled(bool enabled)
Enable or disable rule.
Definition: Rule.cpp:202
int getTimesTriggered() const
Get the number of times the rule was triggered.
Definition: Rule.cpp:192
void setActions(const std::vector< Action > &actions)
Set actions for the rule.
Definition: Rule.cpp:247
bool isEnabled() const
Get whether rule is enabled or disabled.
Definition: Rule.cpp:197
std::vector< Action > getActions() const
Get the actions that are executed.
Definition: Rule.cpp:224
time::AbsoluteTime getLastTriggered() const
Get time the rule was last triggered.
Definition: Rule.cpp:182
void setName(const std::string &name)
Set rule name.
Definition: Rule.cpp:170
std::string getName() const
Get rule name.
Definition: Rule.cpp:165
time::AbsoluteTime getCreated() const
Get created time.
Definition: Rule.cpp:177
int getId() const
Get rule identifier.
Definition: Rule.cpp:160
std::vector< Condition > getConditions() const
Get the conditions that have to be met.
Definition: Rule.cpp:213