Loading...
Searching...
No Matches
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.
bool | validateReplyForLight (const nlohmann::json &request, const nlohmann::json &reply, int lightId)
bool | floatEquals (float lhs, float rhs)
| Checks equality to 4 decimal places.
template<typename... Paths>
nlohmann::json | safeGetMember (const nlohmann::json &json, Paths &&... paths)
| Returns the object/array member or null if it does not exist.

## 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

  json | The base json value
  paths | Any 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

  path | The path the PUT request was made to
  request | The request that was sent initially
  reply | The 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
| ) |  |