hueplusplus  1.0.0
Functions
hueplusplus::utils Namespace Reference

Utility functions used in multiple places. More...

Functions

bool validatePUTReply (const std::string &path, const nlohmann::json &request, const nlohmann::json &reply)
 Function for validating that a request was executed correctly. More...
 
bool validateReplyForLight (const nlohmann::json &request, const nlohmann::json &reply, int lightId)
 
bool floatEquals (float lhs, float rhs)
 Checks equality to 4 decimal places. More...
 
template<typename... Paths>
nlohmann::json safeGetMember (const nlohmann::json &json, Paths &&... paths)
 Returns the object/array member or null if it does not exist. More...
 

Detailed Description

Utility functions used in multiple places.

Function Documentation

◆ floatEquals()

bool hueplusplus::utils::floatEquals ( float  lhs,
float  rhs 
)
inline

Checks equality to 4 decimal places.

Floats in Hue json responses are rounded to 4 decimal places.

◆ safeGetMember()

template<typename... Paths>
nlohmann::json hueplusplus::utils::safeGetMember ( const nlohmann::json &  json,
Paths &&...  paths 
)

Returns the object/array member or null if it does not exist.

Parameters
jsonThe base json value
pathsAny number of child accesses (e.g. 0, "key" would access json[0]["key"])
Returns
The specified member or null if any intermediate object does not contain the specified child.

◆ validatePUTReply()

bool hueplusplus::utils::validatePUTReply ( const std::string &  path,
const nlohmann::json &  request,
const nlohmann::json &  reply 
)

Function for validating that a request was executed correctly.

Parameters
pathThe path the PUT request was made to
requestThe request that was sent initially
replyThe reply that was received
Returns
True if request was executed correctly

◆ validateReplyForLight()

bool hueplusplus::utils::validateReplyForLight ( const nlohmann::json &  request,
const nlohmann::json &  reply,
int  lightId 
)