hueplusplus  1.0.0
StateTransaction.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_STATE_TRANSACTION_H
24 #define INCLUDE_HUEPLUSPLUS_STATE_TRANSACTION_H
25 
26 #include <string>
27 
28 #include "Action.h"
29 #include "ColorUnits.h"
30 #include "HueCommandAPI.h"
31 
32 #include "json/json.hpp"
33 
34 namespace hueplusplus
35 {
62 {
63 public:
69  StateTransaction(const HueCommandAPI& commands, const std::string& path, nlohmann::json* currentState);
70 
72  StateTransaction(const StateTransaction&) = delete;
74 
86  bool commit(bool trimRequest = true);
87 
90  Action toAction();
91 
95  StateTransaction& setOn(bool on);
102  StateTransaction& setBrightness(uint8_t brightness);
108  StateTransaction& setColorHue(uint16_t hue);
114  StateTransaction& setColorSaturation(uint8_t saturation);
120  StateTransaction& setColor(const HueSaturation& hueSat);
121 
127  StateTransaction& setColor(const XY& xy);
139  StateTransaction& setColorTemperature(unsigned int mired);
145  StateTransaction& setColorLoop(bool on);
150  StateTransaction& incrementBrightness(int increment);
155  StateTransaction& incrementSaturation(int increment);
160  StateTransaction& incrementHue(int increment);
171  StateTransaction& incrementColorXY(float xInc, float yInc);
177  StateTransaction& setTransition(uint16_t transition);
189 
190 protected:
192  void trimRequest();
193 
194 protected:
196  std::string path;
197  nlohmann::json* state;
198  nlohmann::json request;
199 };
200 
201 } // namespace hueplusplus
202 
203 #endif
Definition: HueCommandAPI.h:37
StateTransaction & incrementBrightness(int increment)
Increment/Decrement brightness.
Definition: StateTransaction.cpp:153
Action executed by the bridge, e.g. as a Schedule command.
Definition: Action.h:35
Namespace for the hueplusplus library.
Definition: Action.h:27
nlohmann::json * state
Definition: StateTransaction.h:197
StateTransaction & setColor(const HueSaturation &hueSat)
Set light color in hue and saturation.
Definition: StateTransaction.cpp:117
Action toAction()
Create an Action from the transaction.
Definition: StateTransaction.cpp:85
StateTransaction & stopAlert()
Stop an ongoing long alert.
Definition: StateTransaction.cpp:201
StateTransaction & longAlert()
Trigger a long alert (15s).
Definition: StateTransaction.cpp:196
StateTransaction & setColorTemperature(unsigned int mired)
Set light color temperature.
Definition: StateTransaction.cpp:140
nlohmann::json request
Definition: StateTransaction.h:198
StateTransaction & setBrightness(uint8_t brightness)
Set light brightness.
Definition: StateTransaction.cpp:97
Color and brightness in CIE.
Definition: ColorUnits.h:62
StateTransaction & incrementSaturation(int increment)
Increment/Decrement saturaction.
Definition: StateTransaction.cpp:159
StateTransaction & setOn(bool on)
Turn light on or off.
Definition: StateTransaction.cpp:91
StateTransaction(const HueCommandAPI &commands, const std::string &path, nlohmann::json *currentState)
Creates a StateTransaction to a group or light state.
Definition: StateTransaction.cpp:32
StateTransaction & setColorSaturation(uint8_t saturation)
Set light saturation.
Definition: StateTransaction.cpp:104
bool commit(bool trimRequest=true)
Commit transaction and make request.
Definition: StateTransaction.cpp:36
Transaction class which can be used for either light or group state.
Definition: StateTransaction.h:61
void trimRequest()
Remove parts from request that are already set in state.
Definition: StateTransaction.cpp:207
StateTransaction & alert()
Trigger an alert.
Definition: StateTransaction.cpp:191
const HueCommandAPI & commands
Definition: StateTransaction.h:195
Color in CIE x and y coordinates.
Definition: ColorUnits.h:47
StateTransaction & incrementHue(int increment)
Increment/Decrement hue.
Definition: StateTransaction.cpp:165
StateTransaction & incrementColorXY(float xInc, float yInc)
Increment/Decrement color xy.
Definition: StateTransaction.cpp:177
StateTransaction & setColorLoop(bool on)
Enables or disables color loop.
Definition: StateTransaction.cpp:147
std::string path
Definition: StateTransaction.h:196
StateTransaction & incrementColorTemperature(int increment)
Increment/Decrement color temperature.
Definition: StateTransaction.cpp:171
StateTransaction & setTransition(uint16_t transition)
Set transition time for the request.
Definition: StateTransaction.cpp:183
Color in hue and saturation.
Definition: ColorUnits.h:31
StateTransaction & setColorHue(uint16_t hue)
Set light hue.
Definition: StateTransaction.cpp:111