Loading...
Searching...
No Matches
Rule.h
Go to the documentation of this file.
#ifndef INCLUDE_HUEPLUSPLUS_RULE_H
#define INCLUDE_HUEPLUSPLUS_RULE_H
#include <string>
#include "APICache.h"
#include "Action.h"
#include "Condition.h"
#include "HueCommandAPI.h"
#include "TimePattern.h"
namespace hueplusplus
{
class Rule
{
public:
Rule(int id, const std::shared_ptr<APICache>& baseCache);
Rule(int id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration, const nlohmann::json& currentState);
void refresh(bool force = false);
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
int getId() const;
std::string getName() const;
void setName(const std::string& name);
time::AbsoluteTime getCreated() const;
time::AbsoluteTime getLastTriggered() const;
int getTimesTriggered() const;
bool isEnabled() const;
void setEnabled(bool enabled);
std::string getOwner() const;
std::vector<Condition> getConditions() const;
std::vector<Action> getActions() const;
void setConditions(const std::vector<Condition>& conditions);
void setActions(const std::vector<Action>& actions);
private:
nlohmann::json sendPutRequest(const nlohmann::json& request, FileInfo fileInfo);
private:
int id;
APICache state;
};
class CreateRule
{
public:
CreateRule(const std::vector<Condition>& conditions, const std::vector<Action>& actions);
CreateRule& setName(const std::string& name);
CreateRule& setStatus(bool enabled);
nlohmann::json getRequest() const;
private:
nlohmann::json request;
};
} // namespace hueplusplus
#endif
APICache.h
Action.h
Condition.h
HueCommandAPI.h
TimePattern.h
hueplusplus::APICache
Caches API GET requests and refreshes regularly.
Definition APICache.h:38
hueplusplus::CreateRule::setStatus
CreateRule & setStatus(bool enabled)
Set status.
Definition Rule.cpp:286
hueplusplus::CreateRule::setName
CreateRule & setName(const std::string &name)
Set name.
Definition Rule.cpp:280
hueplusplus::CreateRule::getRequest
nlohmann::json getRequest() const
Get request to create the rule.
Definition Rule.cpp:292
hueplusplus::CreateRule::CreateRule
CreateRule(const std::vector< Condition > &conditions, const std::vector< Action > &actions)
Construct with necessary parameters.
Definition Rule.cpp:264
hueplusplus::HueCommandAPI
Definition HueCommandAPI.h:38
hueplusplus::Rule::setName
void setName(const std::string &name)
Set rule name.
Definition Rule.cpp:170
hueplusplus::Rule::getConditions
std::vector< Condition > getConditions() const
Get the conditions that have to be met.
Definition Rule.cpp:213
hueplusplus::Rule::getOwner
std::string getOwner() const
Get user that created or last changed the rule.
Definition Rule.cpp:208
hueplusplus::Rule::setActions
void setActions(const std::vector< Action > &actions)
Set actions for the rule.
Definition Rule.cpp:247
hueplusplus::Rule::getId
int getId() const
Get rule identifier.
Definition Rule.cpp:160
hueplusplus::Rule::getActions
std::vector< Action > getActions() const
Get the actions that are executed.
Definition Rule.cpp:224
hueplusplus::Rule::Rule
Rule(int id, const std::shared_ptr< APICache > &baseCache)
Creates rule with shared cache.
Definition Rule.cpp:133
hueplusplus::Rule::getTimesTriggered
int getTimesTriggered() const
Get the number of times the rule was triggered.
Definition Rule.cpp:192
hueplusplus::Rule::setRefreshDuration
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets custom refresh interval for this rule.
Definition Rule.cpp:155
hueplusplus::Rule::getCreated
time::AbsoluteTime getCreated() const
Get created time.
Definition Rule.cpp:177
hueplusplus::Rule::isEnabled
bool isEnabled() const
Get whether rule is enabled or disabled.
Definition Rule.cpp:197
hueplusplus::Rule::getLastTriggered
time::AbsoluteTime getLastTriggered() const
Get time the rule was last triggered.
Definition Rule.cpp:182
hueplusplus::Rule::setConditions
void setConditions(const std::vector< Condition > &conditions)
Set conditions for the rule.
Definition Rule.cpp:235
hueplusplus::Rule::getName
std::string getName() const
Get rule name.
Definition Rule.cpp:165
hueplusplus::Rule::refresh
void refresh(bool force=false)
Refreshes internal cached state.
Definition Rule.cpp:143
hueplusplus::Rule::setEnabled
void setEnabled(bool enabled)
Enable or disable rule.
Definition Rule.cpp:202
hueplusplus::time::AbsoluteTime
One-time, absolute time point.
Definition TimePattern.h:73
hueplusplus
Namespace for the hueplusplus library.
Definition Action.h:28
hueplusplus::FileInfo
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35