MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / commit

Method commit

dependencies/hueplusplus-1.0.0/src/StateTransaction.cpp:36–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34{ }
35
36bool StateTransaction::commit(bool trimRequest)
37{
38 const nlohmann::json& stateJson = (state != nullptr) ? *state : nlohmann::json::object();
39 // Check this before request is trimmed
40 if (!request.count("on"))
41 {
42 if (!stateJson.value("on", false) && request.value("bri", 254) != 0
43 && (request.count("bri") || request.count("effect") || request.count("hue") || request.count("sat")
44 || request.count("xy") || request.count("ct")))
45 {
46 // Turn on if it was turned off
47 request["on"] = true;
48 }
49 else if (request.value("bri", 254) == 0 && stateJson.value("on", true))
50 {
51 // Turn off if brightness is 0
52 request["on"] = false;
53 }
54 }
55
56 if (trimRequest)
57 {
58 this->trimRequest();
59 }
60 // Empty request or request with only transition makes no sense
61 if (!request.empty() && !(request.size() == 1 && request.count("transitiontime")))
62 {
63 nlohmann::json reply = commands.PUTRequest(path, request, CURRENT_FILE_INFO);
64 if (utils::validatePUTReply(path, request, reply))
65 {
66 if (state != nullptr)
67 {
68 // Apply changes to state
69 for (auto it = request.begin(); it != request.end(); ++it)
70 {
71 if (it.key() == "transitiontime")
72 {
73 continue;
74 }
75 (*state)[it.key()] = it.value();
76 }
77 }
78 return true;
79 }
80 return false;
81 }
82 return true;
83}
84
85Action StateTransaction::toAction()
86{

Callers 15

TESTFunction · 0.80
setOnMethod · 0.80
setBrightnessMethod · 0.80
setColorMethod · 0.80
setColorTemperatureMethod · 0.80
onMethod · 0.80
offMethod · 0.80
alertMethod · 0.80
setBrightnessMethod · 0.80
setColorHueMethod · 0.80
setColorSaturationMethod · 0.80
setColorHueSaturationMethod · 0.80

Calls 10

trimRequestMethod · 0.95
validatePUTReplyFunction · 0.85
PUTRequestMethod · 0.80
countMethod · 0.45
valueMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
keyMethod · 0.45

Tested by 1

TESTFunction · 0.64