hueplusplus
1.0.0
|
Transaction class which can be used for either light or group state. More...
#include <hueplusplus/StateTransaction.h>
Public Member Functions | |
StateTransaction (const HueCommandAPI &commands, const std::string &path, nlohmann::json *currentState) | |
Creates a StateTransaction to a group or light state. More... | |
StateTransaction (const StateTransaction &)=delete | |
Deleted copy constructor, do not store StateTransaction in a variable. More... | |
StateTransaction (StateTransaction &&)=default | |
bool | commit (bool trimRequest=true) |
Commit transaction and make request. More... | |
Action | toAction () |
Create an Action from the transaction. More... | |
StateTransaction & | setOn (bool on) |
Turn light on or off. More... | |
StateTransaction & | setBrightness (uint8_t brightness) |
Set light brightness. More... | |
StateTransaction & | setColorHue (uint16_t hue) |
Set light hue. More... | |
StateTransaction & | setColorSaturation (uint8_t saturation) |
Set light saturation. More... | |
StateTransaction & | setColor (const HueSaturation &hueSat) |
Set light color in hue and saturation. More... | |
StateTransaction & | setColor (const XY &xy) |
Set light color in xy space (without brightness). More... | |
StateTransaction & | setColor (const XYBrightness &xy) |
Set light color and brightness in xy space. More... | |
StateTransaction & | setColorTemperature (unsigned int mired) |
Set light color temperature. More... | |
StateTransaction & | setColorLoop (bool on) |
Enables or disables color loop. More... | |
StateTransaction & | incrementBrightness (int increment) |
Increment/Decrement brightness. More... | |
StateTransaction & | incrementSaturation (int increment) |
Increment/Decrement saturaction. More... | |
StateTransaction & | incrementHue (int increment) |
Increment/Decrement hue. More... | |
StateTransaction & | incrementColorTemperature (int increment) |
Increment/Decrement color temperature. More... | |
StateTransaction & | incrementColorXY (float xInc, float yInc) |
Increment/Decrement color xy. More... | |
StateTransaction & | setTransition (uint16_t transition) |
Set transition time for the request. More... | |
StateTransaction & | alert () |
Trigger an alert. More... | |
StateTransaction & | longAlert () |
Trigger a long alert (15s). More... | |
StateTransaction & | stopAlert () |
Stop an ongoing long alert. More... | |
Protected Member Functions | |
void | trimRequest () |
Remove parts from request that are already set in state. More... | |
Protected Attributes | |
const HueCommandAPI & | commands |
std::string | path |
nlohmann::json * | state |
nlohmann::json | request |
Transaction class which can be used for either light or group state.
This is intended to be used in-line, all calls are chained until a commit() call.
Another way to use the transaction is by storing it and building up the calls separately.
In this case, it is especially important that the light and the state of the light MUST NOT invalidate. That means
In general, this method is easier to screw up and should only be used when really necessary.
hueplusplus::StateTransaction::StateTransaction | ( | const HueCommandAPI & | commands, |
const std::string & | path, | ||
nlohmann::json * | currentState | ||
) |
Creates a StateTransaction to a group or light state.
commands | HueCommandAPI for making requests |
path | Path to which the final PUT request is made (without username) |
currentState | Optional, the current state to check whether changes are needed. Pass nullptr to always include all requests (for groups, because individual lights might be different). |
|
delete |
Deleted copy constructor, do not store StateTransaction in a variable.
|
default |
StateTransaction & hueplusplus::StateTransaction::alert | ( | ) |
Trigger an alert.
The light performs one breathe cycle.
bool hueplusplus::StateTransaction::commit | ( | bool | trimRequest = true | ) |
Commit transaction and make request.
trimRequest | Optional. When true, request parameters that are unneccessary based on the current state are removed. This reduces load on the bridge. On the other hand, an outdated state might cause requests to be dropped unexpectedly. Has no effect on groups. |
std::system_error | when system or socket operations fail |
HueException | when response contains no body |
HueAPIResponseException | when response contains an error |
nlohmann::json::parse_error | when response could not be parsed |
StateTransaction & hueplusplus::StateTransaction::incrementBrightness | ( | int | increment | ) |
Increment/Decrement brightness.
increment | Brightness change from -254 to 254. |
StateTransaction & hueplusplus::StateTransaction::incrementColorTemperature | ( | int | increment | ) |
Increment/Decrement color temperature.
increment | Color temperature change in mired from -65535 to 65535. |
StateTransaction & hueplusplus::StateTransaction::incrementColorXY | ( | float | xInc, |
float | yInc | ||
) |
Increment/Decrement color xy.
xInc | x color coordinate change from -0.5 to 0.5. |
yInc | y color coordinate change from -0.5 to 0.5. |
StateTransaction & hueplusplus::StateTransaction::incrementHue | ( | int | increment | ) |
Increment/Decrement hue.
increment | Hue change from -65535 to 65535. |
StateTransaction & hueplusplus::StateTransaction::incrementSaturation | ( | int | increment | ) |
Increment/Decrement saturaction.
increment | Saturation change from -254 to 254. |
StateTransaction & hueplusplus::StateTransaction::longAlert | ( | ) |
Trigger a long alert (15s).
StateTransaction & hueplusplus::StateTransaction::setBrightness | ( | uint8_t | brightness | ) |
Set light brightness.
brightness | Brightness from 0 = off to 254 = fully lit. |
StateTransaction & hueplusplus::StateTransaction::setColor | ( | const HueSaturation & | hueSat | ) |
Set light color in hue and saturation.
hueSat | Color in hue and saturation |
StateTransaction & hueplusplus::StateTransaction::setColor | ( | const XY & | xy | ) |
Set light color in xy space (without brightness).
xy | x and y coordinates in CIE color space |
StateTransaction & hueplusplus::StateTransaction::setColor | ( | const XYBrightness & | xy | ) |
Set light color and brightness in xy space.
xy | x,y and brightness in CIE color space |
StateTransaction & hueplusplus::StateTransaction::setColorHue | ( | uint16_t | hue | ) |
Set light hue.
hue | Color hue from 0 to 65535 |
StateTransaction & hueplusplus::StateTransaction::setColorLoop | ( | bool | on | ) |
Enables or disables color loop.
on | true to enable, false to disable color loop. |
StateTransaction & hueplusplus::StateTransaction::setColorSaturation | ( | uint8_t | saturation | ) |
Set light saturation.
saturation | Color saturation from 0 to 254 |
StateTransaction & hueplusplus::StateTransaction::setColorTemperature | ( | unsigned int | mired | ) |
Set light color temperature.
mired | Color temperature in mired from 153 to 500 |
StateTransaction & hueplusplus::StateTransaction::setOn | ( | bool | on | ) |
Turn light on or off.
on | true for on, false for off |
StateTransaction & hueplusplus::StateTransaction::setTransition | ( | uint16_t | transition | ) |
Set transition time for the request.
transition | Transition time in 100ms, default for any request is 400ms. |
StateTransaction & hueplusplus::StateTransaction::stopAlert | ( | ) |
Stop an ongoing long alert.
Action hueplusplus::StateTransaction::toAction | ( | ) |
|
protected |
Remove parts from request that are already set in state.
|
protected |
|
protected |
|
protected |
|
protected |