Commit b6d5d07cf15e2d8bd2b5fea3ea66e9af124adba7

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent 8642e827

Move everything into namespace hueplusplus.

Showing 52 changed files with 2314 additions and 2233 deletions
CMakeLists.txt
... ... @@ -11,6 +11,15 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
11 11  
12 12 project(hueplusplus LANGUAGES CXX)
13 13  
  14 +# check whether hueplusplus is compiled directly or included as a subdirectory
  15 +if(NOT DEFINED hueplusplus_master_project)
  16 + if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
  17 + set(hueplusplus_master_project ON)
  18 + else()
  19 + set(hueplusplus_master_project OFF)
  20 + endif()
  21 +endif()
  22 +
14 23 # options to set
15 24 option(hueplusplus_TESTS "Build tests" OFF)
16 25  
... ... @@ -27,7 +36,7 @@ endif()
27 36  
28 37 # Set default build type if none was specified
29 38 set(default_build_type "Release")
30   -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  39 +if(hueplusplus_master_project AND (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES))
31 40 message(STATUS "Setting build type to '${default_build_type}' as none was specified")
32 41 set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
33 42 # Set possible values for cmake-gui
... ...
README.md
... ... @@ -26,16 +26,17 @@ To start searching for a Hue Bridge you will need to choose an IHttpHandler and
26 26 Then create a HueFinder object with the handler.
27 27 The handler is needed, because it tells the finder which functions to use to communicate with a bridge or your local network.
28 28 After that you can call FindBridges(), which will return a vector containing the ip and mac address of all found Bridges.
29   -If no Bridges were found the vector is empty, so make sure that in that case you provide an ip and mac address.
30 29 ```C++
31   -// For windows use std::make_shared<WinHttpHandler>();
32   -handler = std::make_shared<LinHttpHandler>();
33   -HueFinder finder(handler);
34   -std::vector<HueFinder::HueIdentification> bridges = finder.FindBridges();
  30 +// For windows use std::make_shared<hueplusplus::WinHttpHandler>();
  31 +handler = std::make_shared<hueplusplus::LinHttpHandler>();
  32 +hueplusplus::HueFinder finder(handler);
  33 +std::vector<hueplusplus::HueFinder::HueIdentification> bridges = finder.FindBridges();
35 34 if (bridges.empty())
36 35 {
37   - bridges.push_back({ "<ip address>", "<mac address>" });
  36 + std::cerr << "No bridges found\n";
  37 + return;
38 38 }
  39 +
39 40 ```
40 41  
41 42 ### Authenticate Bridges
... ... @@ -43,19 +44,19 @@ If you have found the Bridge you were looking for, you can then move on with the
43 44 To get a new username from the Bridge (for now) you simply call GetBridge(bridges[\<index\>]),
44 45 where index is your preferred Bridge from the part [Searching for Bridges](#searchingBridges).
45 46 ```C++
46   -Hue bridge = finder.GetBridge(bridges[0]);
  47 +hueplusplus::Hue bridge = finder.GetBridge(bridges[0]);
47 48 ```
48 49 If you on the other hand already have a username you can add your bridge like so
49 50 ```C++
50 51 finder.AddUsername(bridges[0].mac, "<username>");
51   -Hue bridge = finder.GetBridge(bridges[0]);
  52 +hueplusplus::Hue bridge = finder.GetBridge(bridges[0]);
52 53 ```
53 54 If you do not want to use the HueFinder or you already know the ip and username of your bridge you have the option to create your own Hue object.
54 55 Here you will need to provide the ip address, the port number, a username and an HttpHandler
55 56 ```C++
56   -// For windows use std::make_shared<WinHttpHandler>();
57   -handler = std::make_shared<LinHttpHandler>();
58   -Hue bridge("192.168.2.102", 80, "<username>", handler);
  57 +// For windows use std::make_shared<hueplusplus::WinHttpHandler>();
  58 +handler = std::make_shared<hueplusplus::LinHttpHandler>();
  59 +hueplusplus::Hue bridge("192.168.2.102", 80, "<username>", handler);
59 60 ```
60 61  
61 62 ### Controlling lights
... ... @@ -63,11 +64,12 @@ If you have your Bridge all set up, you can now control its lights.
63 64 For that create a new HueLight object and call getLight(\<id\>) on your bridge object to get a reference to a specific light, where id
64 65 is the id of the light set internally by the Hue Bridge.
65 66 ```C++
66   -HueLight light1 = bridge.getLight(1);
  67 +hueplusplus::HueLight light1 = bridge.getLight(1);
67 68 ```
68   -If you don't know the id of a specific light or want to get an overview over all lights that are controlled by your bridge, you can get a vector containing them by calling getAllLights() on your bridge object. If no lights are found the vector will be empty.
  69 +If you don't know the id of a specific light or want to get an overview over all lights that are controlled by your bridge,
  70 +you can get a vector containing them by calling getAllLights() on your bridge object. If no lights are found the vector will be empty.
69 71 ```C++
70   -std::vector<std::reference_wrapper<HueLight>> lights = bridge.getAllLights();
  72 +std::vector<std::reference_wrapper<hueplusplus::HueLight>> lights = bridge.getAllLights();
71 73 ```
72 74 If you now want to control a light, call a specific function of it.
73 75 ```C++
... ... @@ -84,7 +86,7 @@ specific function, but nothing will happen. For that you might want to check wha
84 86 of a light you are controlling. For that you can call the function getColorType(), which will return
85 87 a ColorType.
86 88 ```C++
87   -ColorType type1 = light1.getColorType();
  89 +hueplusplus::ColorType type1 = light1.getColorType();
88 90 ```
89 91 There's also a new way to check whether specific functions of a light are available:
90 92 ```C++
... ... @@ -126,21 +128,21 @@ If you have a project that already uses CMake you probably want to add the huepl
126 128 For that the best way is to use find_package().
127 129 When cmake finds the hueplusplus library you can then link against either the shared or static version of the library.
128 130 ```cmake
129   -find_package(hueplusplus)
  131 +find_package(hueplusplus REQUIRED)
130 132  
131   -target_link_libraries(<executable> hueplusplusstatic)
  133 +target_link_libraries(<executable> PUBLIC hueplusplusstatic)
132 134 ```
133 135 But this will only work if the hueplusplus library is already installed.
134 136 To get around this problem there is a pretty awesome way.
135 137 If you have the hueplusplus repository included in your project repository (as a submodule) or know where the folder lives you can do the following:
136 138 ```cmake
137   -find_package(hueplusplus)
  139 +find_package(hueplusplus QUIET)
138 140 if(NOT hueplusplus_FOUND)
139 141 message(STATUS "-- hueplusplus not found, building it")
140   - add_subdirectory("${CMAKE_SOURCE_DIR}/<path to directory>/hueplusplus" "${CMAKE_BINARY_DIR}/hueplusplus")
  142 + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/<path to directory>/hueplusplus" "${CMAKE_CURRENT_BINARY_DIR}/hueplusplus")
141 143 endif()
142 144  
143   -target_link_libraries(<executable> hueplusplusstatic)
  145 +target_link_libraries(<executable> PUBLIC hueplusplusstatic)
144 146 ```
145 147 This will check if the hueplusplus library was found by find_package() and if not it will use the specified path to the library source and compile it during the build process.
146 148  
... ...
include/hueplusplus/BaseHttpHandler.h
... ... @@ -32,144 +32,147 @@
32 32  
33 33 #include "json/json.hpp"
34 34  
35   -//! Base class for classes that handle http requests and multicast requests
36   -class BaseHttpHandler : public IHttpHandler
  35 +namespace hueplusplus
37 36 {
38   -public:
39   - //! \brief Virtual dtor
40   - virtual ~BaseHttpHandler() = default;
41   -
42   - //! \brief Send a message to a specified host and return the body of the response.
43   - //!
44   - //! \param msg The message that should sent to the specified address
45   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
46   - //! \param port Optional port the request is sent to, default is 80
47   - //! \return The body of the response of the host as a string
48   - //! \throws std::system_error when system or socket operations fail
49   - //! \throws HueException when response contained no body
50   - std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override;
51   -
52   - //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
53   - //!
54   - //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
55   - //! \param uri Uniform Resource Identifier in the request
56   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
57   - //! \param body Request body, may be empty
58   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
59   - //! \param port Optional port the request is sent to, default is 80
60   - //! \return Body of the response of the host
61   - //! \throws std::system_error when system or socket operations fail
62   - //! \throws HueException when response contained no body
63   - std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType,
64   - const std::string& body, const std::string& adr, int port = 80) const override;
65   -
66   - //! \brief Send a HTTP GET request to the specified host and return the body of the response.
67   - //!
68   - //! \param uri Uniform Resource Identifier in the request
69   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
70   - //! \param body Request body, may be empty
71   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
72   - //! \param port Optional port the request is sent to, default is 80
73   - //! that specifies the port to which the request is sent to. Default is 80
74   - //! \return Body of the response of the host
75   - //! \throws std::system_error when system or socket operations fail
76   - //! \throws HueException when response contained no body
77   - std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
78   - const std::string& adr, int port = 80) const override;
79   -
80   - //! \brief Send a HTTP POST request to the specified host and return the body of the response.
81   - //!
82   - //! \param uri Uniform Resource Identifier in the request
83   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
84   - //! \param body Request body, may be empty
85   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
86   - //! \param port Optional port the request is sent to, default is 80
87   - //! that specifies the port to which the request is sent to. Default is 80
88   - //! \return Body of the response of the host
89   - //! \throws std::system_error when system or socket operations fail
90   - //! \throws HueException when response contained no body
91   - std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
92   - const std::string& adr, int port = 80) const override;
93   -
94   - //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
95   - //!
96   - //! \param uri Uniform Resource Identifier in the request
97   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
98   - //! \param body Request body, may be empty
99   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
100   - //! \param port Optional port the request is sent to, default is 80
101   - //! that specifies the port to which the request is sent to. Default is 80
102   - //! \return Body of the response of the host
103   - //! \throws std::system_error when system or socket operations fail
104   - //! \throws HueException when response contained no body
105   - std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
106   - const std::string& adr, int port = 80) const override;
107   -
108   - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
109   - //!
110   - //! \param uri Uniform Resource Identifier in the request
111   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
112   - //! \param body Request body, may be empty
113   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
114   - //! \param port Optional port the request is sent to, default is 80
115   - //! that specifies the port to which the request is sent to. Default is 80
116   - //! \return Body of the response of the host
117   - //! \throws std::system_error when system or socket operations fail
118   - //! \throws HueException when response contained no body
119   - std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body,
120   - const std::string& adr, int port = 80) const override;
121   -
122   - //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
123   - //!
124   - //! \param uri Uniform Resource Identifier in the request
125   - //! \param body Request body, may be empty
126   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
127   - //! \param port Optional port the request is sent to, default is 80
128   - //! \return Parsed body of the response of the host
129   - //! \throws std::system_error when system or socket operations fail
130   - //! \throws HueException when response contained no body
131   - //! \throws nlohmann::json::parse_error when the body could not be parsed
132   - nlohmann::json GETJson(
133   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
134   -
135   - //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
136   - //!
137   - //! \param uri Uniform Resource Identifier in the request
138   - //! \param body Request body, may be empty
139   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
140   - //! \param port Optional port the request is sent to, default is 80
141   - //! \return Parsed body of the response of the host
142   - //! \throws std::system_error when system or socket operations fail
143   - //! \throws HueException when response contained no body
144   - //! \throws nlohmann::json::parse_error when the body could not be parsed
145   - nlohmann::json POSTJson(
146   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
147   -
148   - //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
149   - //!
150   - //! \param uri Uniform Resource Identifier in the request
151   - //! \param body Request body, may be empty
152   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
153   - //! \param port Optional port the request is sent to, default is 80
154   - //! \return Parsed body of the response of the host
155   - //! \throws std::system_error when system or socket operations fail
156   - //! \throws HueException when response contained no body
157   - //! \throws nlohmann::json::parse_error when the body could not be parsed
158   - nlohmann::json PUTJson(
159   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
160   -
161   - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
162   - //!
163   - //! \param uri Uniform Resource Identifier in the request
164   - //! \param body Request body, may be empty
165   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
166   - //! \param port Optional port the request is sent to, default is 80
167   - //! \return Parsed body of the response of the host
168   - //! \throws std::system_error when system or socket operations fail
169   - //! \throws HueException when response contained no body
170   - //! \throws nlohmann::json::parse_error when the body could not be parsed
171   - nlohmann::json DELETEJson(
172   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
173   -};
  37 + //! Base class for classes that handle http requests and multicast requests
  38 + class BaseHttpHandler : public IHttpHandler
  39 + {
  40 + public:
  41 + //! \brief Virtual dtor
  42 + virtual ~BaseHttpHandler() = default;
  43 +
  44 + //! \brief Send a message to a specified host and return the body of the response.
  45 + //!
  46 + //! \param msg The message that should sent to the specified address
  47 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  48 + //! \param port Optional port the request is sent to, default is 80
  49 + //! \return The body of the response of the host as a string
  50 + //! \throws std::system_error when system or socket operations fail
  51 + //! \throws HueException when response contained no body
  52 + std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const override;
  53 +
  54 + //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
  55 + //!
  56 + //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
  57 + //! \param uri Uniform Resource Identifier in the request
  58 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  59 + //! \param body Request body, may be empty
  60 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  61 + //! \param port Optional port the request is sent to, default is 80
  62 + //! \return Body of the response of the host
  63 + //! \throws std::system_error when system or socket operations fail
  64 + //! \throws HueException when response contained no body
  65 + std::string sendHTTPRequest(const std::string& method, const std::string& uri, const std::string& contentType,
  66 + const std::string& body, const std::string& adr, int port = 80) const override;
  67 +
  68 + //! \brief Send a HTTP GET request to the specified host and return the body of the response.
  69 + //!
  70 + //! \param uri Uniform Resource Identifier in the request
  71 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  72 + //! \param body Request body, may be empty
  73 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  74 + //! \param port Optional port the request is sent to, default is 80
  75 + //! that specifies the port to which the request is sent to. Default is 80
  76 + //! \return Body of the response of the host
  77 + //! \throws std::system_error when system or socket operations fail
  78 + //! \throws HueException when response contained no body
  79 + std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
  80 + const std::string& adr, int port = 80) const override;
  81 +
  82 + //! \brief Send a HTTP POST request to the specified host and return the body of the response.
  83 + //!
  84 + //! \param uri Uniform Resource Identifier in the request
  85 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  86 + //! \param body Request body, may be empty
  87 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  88 + //! \param port Optional port the request is sent to, default is 80
  89 + //! that specifies the port to which the request is sent to. Default is 80
  90 + //! \return Body of the response of the host
  91 + //! \throws std::system_error when system or socket operations fail
  92 + //! \throws HueException when response contained no body
  93 + std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
  94 + const std::string& adr, int port = 80) const override;
  95 +
  96 + //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
  97 + //!
  98 + //! \param uri Uniform Resource Identifier in the request
  99 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  100 + //! \param body Request body, may be empty
  101 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  102 + //! \param port Optional port the request is sent to, default is 80
  103 + //! that specifies the port to which the request is sent to. Default is 80
  104 + //! \return Body of the response of the host
  105 + //! \throws std::system_error when system or socket operations fail
  106 + //! \throws HueException when response contained no body
  107 + std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
  108 + const std::string& adr, int port = 80) const override;
  109 +
  110 + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
  111 + //!
  112 + //! \param uri Uniform Resource Identifier in the request
  113 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  114 + //! \param body Request body, may be empty
  115 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  116 + //! \param port Optional port the request is sent to, default is 80
  117 + //! that specifies the port to which the request is sent to. Default is 80
  118 + //! \return Body of the response of the host
  119 + //! \throws std::system_error when system or socket operations fail
  120 + //! \throws HueException when response contained no body
  121 + std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body,
  122 + const std::string& adr, int port = 80) const override;
  123 +
  124 + //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
  125 + //!
  126 + //! \param uri Uniform Resource Identifier in the request
  127 + //! \param body Request body, may be empty
  128 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  129 + //! \param port Optional port the request is sent to, default is 80
  130 + //! \return Parsed body of the response of the host
  131 + //! \throws std::system_error when system or socket operations fail
  132 + //! \throws HueException when response contained no body
  133 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  134 + nlohmann::json GETJson(
  135 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
  136 +
  137 + //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
  138 + //!
  139 + //! \param uri Uniform Resource Identifier in the request
  140 + //! \param body Request body, may be empty
  141 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  142 + //! \param port Optional port the request is sent to, default is 80
  143 + //! \return Parsed body of the response of the host
  144 + //! \throws std::system_error when system or socket operations fail
  145 + //! \throws HueException when response contained no body
  146 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  147 + nlohmann::json POSTJson(
  148 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
  149 +
  150 + //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
  151 + //!
  152 + //! \param uri Uniform Resource Identifier in the request
  153 + //! \param body Request body, may be empty
  154 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  155 + //! \param port Optional port the request is sent to, default is 80
  156 + //! \return Parsed body of the response of the host
  157 + //! \throws std::system_error when system or socket operations fail
  158 + //! \throws HueException when response contained no body
  159 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  160 + nlohmann::json PUTJson(
  161 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
  162 +
  163 + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
  164 + //!
  165 + //! \param uri Uniform Resource Identifier in the request
  166 + //! \param body Request body, may be empty
  167 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  168 + //! \param port Optional port the request is sent to, default is 80
  169 + //! \return Parsed body of the response of the host
  170 + //! \throws std::system_error when system or socket operations fail
  171 + //! \throws HueException when response contained no body
  172 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  173 + nlohmann::json DELETEJson(
  174 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const override;
  175 + };
  176 +} // namespace hueplusplus
174 177  
175 178 #endif
... ...
include/hueplusplus/BrightnessStrategy.h
... ... @@ -23,36 +23,39 @@
23 23 #ifndef _BRIGHTNESS_STRATEGY_H
24 24 #define _BRIGHTNESS_STRATEGY_H
25 25  
26   -#include <stdint.h>
  26 +#include <cstdint>
27 27  
28   -class HueLight;
29   -
30   -//! Virtual base class for all BrightnessStrategies
31   -class BrightnessStrategy
  28 +namespace hueplusplus
32 29 {
33   -public:
34   - //! \brief Virtual function for changing a lights brightness with a specified
35   - //! transition.
36   - //!
37   - //! \param bri The brightness raning from 0 = off to 255 = fully lit
38   - //! \param transition The time it takes to fade to the new brightness in
39   - //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
40   - //! light A reference of the light
41   - virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0;
42   - //! \brief Virtual function that returns the current brightnessof the light
43   - //!
44   - //! Should update the lights state by calling refreshState()
45   - //! \param light A reference of the light
46   - //! \return Unsigned int representing the brightness
47   - virtual unsigned int getBrightness(HueLight& light) const = 0;
48   - //! \brief Virtual function that returns the current brightness of the light
49   - //!
50   - //! \note This should not update the lights state
51   - //! \param light A const reference of the light
52   - //! \return Unsigned int representing the brightness
53   - virtual unsigned int getBrightness(const HueLight& light) const = 0;
54   - //! \brief Virtual dtor
55   - virtual ~BrightnessStrategy() = default;
56   -};
  30 + class HueLight;
  31 +
  32 + //! Virtual base class for all BrightnessStrategies
  33 + class BrightnessStrategy
  34 + {
  35 + public:
  36 + //! \brief Virtual function for changing a lights brightness with a specified
  37 + //! transition.
  38 + //!
  39 + //! \param bri The brightness raning from 0 = off to 255 = fully lit
  40 + //! \param transition The time it takes to fade to the new brightness in
  41 + //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
  42 + //! light A reference of the light
  43 + virtual bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const = 0;
  44 + //! \brief Virtual function that returns the current brightnessof the light
  45 + //!
  46 + //! Should update the lights state by calling refreshState()
  47 + //! \param light A reference of the light
  48 + //! \return Unsigned int representing the brightness
  49 + virtual unsigned int getBrightness(HueLight& light) const = 0;
  50 + //! \brief Virtual function that returns the current brightness of the light
  51 + //!
  52 + //! \note This should not update the lights state
  53 + //! \param light A const reference of the light
  54 + //! \return Unsigned int representing the brightness
  55 + virtual unsigned int getBrightness(const HueLight& light) const = 0;
  56 + //! \brief Virtual dtor
  57 + virtual ~BrightnessStrategy() = default;
  58 + };
  59 +} // namespace hueplusplus
57 60  
58 61 #endif
... ...
include/hueplusplus/ColorHueStrategy.h
... ... @@ -23,133 +23,135 @@
23 23 #ifndef _COLOR_HUE_STRATEGY_H
24 24 #define _COLOR_HUE_STRATEGY_H
25 25  
  26 +#include <cstdint>
26 27 #include <memory>
27 28  
28   -#include <stdint.h>
29   -
30   -class HueLight;
31   -
32   -//! Virtual base class for all ColorHueStrategies
33   -class ColorHueStrategy
  29 +namespace hueplusplus
34 30 {
35   -public:
36   - //! \brief Virtual function for changing a lights color in hue with a
37   - //! specified transition.
38   - //!
39   - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
40   - //! green and 46920 is blue. \param hue The hue of the color \param transition
41   - //! The time it takes to fade to the new color in multiples of 100ms, 4 =
42   - //! 400ms and should be seen as the default \param light A reference of the
43   - //! light
44   - virtual bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const = 0;
45   - //! \brief Virtual function for changing a lights color in saturation with a
46   - //! specified transition.
47   - //!
48   - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white)
49   - //! and 254 is most saturated (vibrant). \param sat The saturation of the
50   - //! color \param transition The time it takes to fade to the new color in
51   - //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
52   - //! light A reference of the light
53   - virtual bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const = 0;
54   - //! \brief Virtual function for changing a lights color in hue and saturation
55   - //! format with a specified transition.
56   - //!
57   - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
58   - //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
59   - //! least saturated (white) and 254 is most saturated (vibrant). \param hue
60   - //! The hue of the color \param sat The saturation of the color \param
61   - //! transition The time it takes to fade to the new color in multiples of
62   - //! 100ms, 4 = 400ms and should be seen as the default \param light A
63   - //! reference of the light
64   - virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const = 0;
65   - //! \brief Virtual function for changing a lights color in CIE format with a
66   - //! specified transition.
67   - //!
68   - //! \param x The x coordinate in CIE, ranging from 0 to 1
69   - //! \param y The y coordinate in CIE, ranging from 0 to 1
70   - //! \param transition The time it takes to fade to the new color in multiples
71   - //! of 100ms, 4 = 400ms and should be seen as the default \param light A
72   - //! reference of the light
73   - virtual bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const = 0;
74   - //! \brief Virtual function for changing a lights color in rgb format with a
75   - //! specified transition.
76   - //!
77   - //! Red, green and blue are ranging from 0 to 255.
78   - //! \param r The red portion of the color
79   - //! \param g The green portion of the color
80   - //! \param b The blue portion of the color
81   - //! \param transition The time it takes to fade to the new color in multiples
82   - //! of 100ms, 4 = 400ms and should be seen as the default \param light A
83   - //! reference of the light
84   - virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const = 0;
85   - //! \brief Virtual function for turning on/off the color loop feature of a
86   - //! light.
87   - //!
88   - //! Can be theoretically set for any light, but it only works for lights that
89   - //! support this feature. When this feature is activated the light will fade
90   - //! through every color on the current hue and saturation settings. Notice
91   - //! that none of the setter functions check whether this feature is enabled
92   - //! and the colorloop can only be disabled with this function or by simply
93   - //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
94   - //! alternatively call Off() and then use any of the setter functions. \param
95   - //! on Boolean to turn this feature on or off, true/1 for on and false/0 for
96   - //! off \param light A reference of the light
97   - virtual bool setColorLoop(bool on, HueLight& light) const = 0;
98   - //! \brief Virtual function that lets the light perform one breath cycle in
99   - //! the specified color.
100   - //!
101   - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
102   - //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
103   - //! least saturated (white) and 254 is most saturated (vibrant). \param hue
104   - //! The hue of the color \param sat The saturation of the color \param light A
105   - //! reference of the light
106   - virtual bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const = 0;
107   - //! \brief Virtual function that lets the light perform one breath cycle in
108   - //! the specified color.
109   - //!
110   - //! \param x The x coordinate in CIE, ranging from 0 to 1
111   - //! \param y The y coordinate in CIE, ranging from 0 to 1
112   - //! \param light A reference of the light
113   - virtual bool alertXY(float x, float y, HueLight& light) const = 0;
114   - //! \brief Virtual function that lets the light perform one breath cycle in
115   - //! the specified color.
116   - //!
117   - //! Red, green and blue are ranging from 0 to 255.
118   - //! \param r The red portion of the color
119   - //! \param g The green portion of the color
120   - //! \param b The blue portion of the color
121   - //! \param light A reference of the light
122   - virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0;
123   - //! \brief Virtual function that returns the current color of the light as hue
124   - //! and saturation
125   - //!
126   - //! Should update the lights state by calling refreshState()
127   - //! \param light A reference of the light
128   - //! \return Pair containing the hue as first value and saturation as second
129   - //! value
130   - virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const = 0;
131   - //! \brief Virtual function that returns the current color of the light as hue
132   - //! and saturation
133   - //!
134   - //! \note This should not update the lights state
135   - //! \param light A const reference of the light
136   - //! \return Pair containing the hue as first value and saturation as second
137   - //! value
138   - virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const = 0;
139   - //! \brief Virtual function that returns the current color of the light as xy
140   - //!
141   - //! Should update the lights state by calling refreshState()
142   - //! \param light A reference of the light
143   - //! \return Pair containing the x as first value and y as second value
144   - virtual std::pair<float, float> getColorXY(HueLight& light) const = 0;
145   - //! \brief Virtual function that returns the current color of the light as xy
146   - //!
147   - //! \note This should not update the lights state
148   - //! \param light A const reference of the light
149   - //! \return Pair containing the x as first value and y as second value
150   - virtual std::pair<float, float> getColorXY(const HueLight& light) const = 0;
151   - //! \brief Virtual dtor
152   - virtual ~ColorHueStrategy() = default;
153   -};
  31 + class HueLight;
  32 +
  33 + //! Virtual base class for all ColorHueStrategies
  34 + class ColorHueStrategy
  35 + {
  36 + public:
  37 + //! \brief Virtual function for changing a lights color in hue with a
  38 + //! specified transition.
  39 + //!
  40 + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
  41 + //! green and 46920 is blue. \param hue The hue of the color \param transition
  42 + //! The time it takes to fade to the new color in multiples of 100ms, 4 =
  43 + //! 400ms and should be seen as the default \param light A reference of the
  44 + //! light
  45 + virtual bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const = 0;
  46 + //! \brief Virtual function for changing a lights color in saturation with a
  47 + //! specified transition.
  48 + //!
  49 + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white)
  50 + //! and 254 is most saturated (vibrant). \param sat The saturation of the
  51 + //! color \param transition The time it takes to fade to the new color in
  52 + //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
  53 + //! light A reference of the light
  54 + virtual bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const = 0;
  55 + //! \brief Virtual function for changing a lights color in hue and saturation
  56 + //! format with a specified transition.
  57 + //!
  58 + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
  59 + //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
  60 + //! least saturated (white) and 254 is most saturated (vibrant). \param hue
  61 + //! The hue of the color \param sat The saturation of the color \param
  62 + //! transition The time it takes to fade to the new color in multiples of
  63 + //! 100ms, 4 = 400ms and should be seen as the default \param light A
  64 + //! reference of the light
  65 + virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const = 0;
  66 + //! \brief Virtual function for changing a lights color in CIE format with a
  67 + //! specified transition.
  68 + //!
  69 + //! \param x The x coordinate in CIE, ranging from 0 to 1
  70 + //! \param y The y coordinate in CIE, ranging from 0 to 1
  71 + //! \param transition The time it takes to fade to the new color in multiples
  72 + //! of 100ms, 4 = 400ms and should be seen as the default \param light A
  73 + //! reference of the light
  74 + virtual bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const = 0;
  75 + //! \brief Virtual function for changing a lights color in rgb format with a
  76 + //! specified transition.
  77 + //!
  78 + //! Red, green and blue are ranging from 0 to 255.
  79 + //! \param r The red portion of the color
  80 + //! \param g The green portion of the color
  81 + //! \param b The blue portion of the color
  82 + //! \param transition The time it takes to fade to the new color in multiples
  83 + //! of 100ms, 4 = 400ms and should be seen as the default \param light A
  84 + //! reference of the light
  85 + virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const = 0;
  86 + //! \brief Virtual function for turning on/off the color loop feature of a
  87 + //! light.
  88 + //!
  89 + //! Can be theoretically set for any light, but it only works for lights that
  90 + //! support this feature. When this feature is activated the light will fade
  91 + //! through every color on the current hue and saturation settings. Notice
  92 + //! that none of the setter functions check whether this feature is enabled
  93 + //! and the colorloop can only be disabled with this function or by simply
  94 + //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
  95 + //! alternatively call Off() and then use any of the setter functions. \param
  96 + //! on Boolean to turn this feature on or off, true/1 for on and false/0 for
  97 + //! off \param light A reference of the light
  98 + virtual bool setColorLoop(bool on, HueLight& light) const = 0;
  99 + //! \brief Virtual function that lets the light perform one breath cycle in
  100 + //! the specified color.
  101 + //!
  102 + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
  103 + //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
  104 + //! least saturated (white) and 254 is most saturated (vibrant). \param hue
  105 + //! The hue of the color \param sat The saturation of the color \param light A
  106 + //! reference of the light
  107 + virtual bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const = 0;
  108 + //! \brief Virtual function that lets the light perform one breath cycle in
  109 + //! the specified color.
  110 + //!
  111 + //! \param x The x coordinate in CIE, ranging from 0 to 1
  112 + //! \param y The y coordinate in CIE, ranging from 0 to 1
  113 + //! \param light A reference of the light
  114 + virtual bool alertXY(float x, float y, HueLight& light) const = 0;
  115 + //! \brief Virtual function that lets the light perform one breath cycle in
  116 + //! the specified color.
  117 + //!
  118 + //! Red, green and blue are ranging from 0 to 255.
  119 + //! \param r The red portion of the color
  120 + //! \param g The green portion of the color
  121 + //! \param b The blue portion of the color
  122 + //! \param light A reference of the light
  123 + virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const = 0;
  124 + //! \brief Virtual function that returns the current color of the light as hue
  125 + //! and saturation
  126 + //!
  127 + //! Should update the lights state by calling refreshState()
  128 + //! \param light A reference of the light
  129 + //! \return Pair containing the hue as first value and saturation as second
  130 + //! value
  131 + virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const = 0;
  132 + //! \brief Virtual function that returns the current color of the light as hue
  133 + //! and saturation
  134 + //!
  135 + //! \note This should not update the lights state
  136 + //! \param light A const reference of the light
  137 + //! \return Pair containing the hue as first value and saturation as second
  138 + //! value
  139 + virtual std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const = 0;
  140 + //! \brief Virtual function that returns the current color of the light as xy
  141 + //!
  142 + //! Should update the lights state by calling refreshState()
  143 + //! \param light A reference of the light
  144 + //! \return Pair containing the x as first value and y as second value
  145 + virtual std::pair<float, float> getColorXY(HueLight& light) const = 0;
  146 + //! \brief Virtual function that returns the current color of the light as xy
  147 + //!
  148 + //! \note This should not update the lights state
  149 + //! \param light A const reference of the light
  150 + //! \return Pair containing the x as first value and y as second value
  151 + virtual std::pair<float, float> getColorXY(const HueLight& light) const = 0;
  152 + //! \brief Virtual dtor
  153 + virtual ~ColorHueStrategy() = default;
  154 + };
  155 +} // namespace hueplusplus
154 156  
155 157 #endif
... ...
include/hueplusplus/ColorTemperatureStrategy.h
... ... @@ -25,46 +25,49 @@
25 25  
26 26 #include <stdint.h>
27 27  
28   -class HueLight;
29   -
30   -//! Virtual base class for all ColorTemperatureStrategies
31   -class ColorTemperatureStrategy
  28 +namespace hueplusplus
32 29 {
33   -public:
34   - //! \brief Virtual function for changing a lights color temperature in mired
35   - //! with a specified transition.
36   - //!
37   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
38   - //! and 500 is warm. \param mired The color temperature in mired \param
39   - //! transition The time it takes to fade to the new color in multiples of
40   - //! 100ms, 4 = 400ms and should be seen as the default \param light A
41   - //! reference of the light
42   - virtual bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const = 0;
43   - //! \brief Virtual function that lets the light perform one breath cycle in
44   - //! the specified color.
45   - //!
46   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
47   - //! and 500 is warm. \param mired The color temperature in mired \param light
48   - //! A reference of the light
49   - virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0;
50   - //! \brief Virtual function that returns the current color temperature of the
51   - //! light
52   - //!
53   - //! Should update the lights state by calling refreshState()
54   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
55   - //! and 500 is warm. \param light A reference of the light \return Unsigned
56   - //! int representing the color temperature in mired
57   - virtual unsigned int getColorTemperature(HueLight& light) const = 0;
58   - //! \brief Virtual function that returns the current color temperature of the
59   - //! light
60   - //!
61   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
62   - //! and 500 is warm. \note This should not update the lights state \param
63   - //! light A const reference of the light \return Unsigned int representing the
64   - //! color temperature in mired
65   - virtual unsigned int getColorTemperature(const HueLight& light) const = 0;
66   - //! \brief Virtual dtor
67   - virtual ~ColorTemperatureStrategy() = default;
68   -};
  30 + class HueLight;
  31 +
  32 + //! Virtual base class for all ColorTemperatureStrategies
  33 + class ColorTemperatureStrategy
  34 + {
  35 + public:
  36 + //! \brief Virtual function for changing a lights color temperature in mired
  37 + //! with a specified transition.
  38 + //!
  39 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  40 + //! and 500 is warm. \param mired The color temperature in mired \param
  41 + //! transition The time it takes to fade to the new color in multiples of
  42 + //! 100ms, 4 = 400ms and should be seen as the default \param light A
  43 + //! reference of the light
  44 + virtual bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const = 0;
  45 + //! \brief Virtual function that lets the light perform one breath cycle in
  46 + //! the specified color.
  47 + //!
  48 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  49 + //! and 500 is warm. \param mired The color temperature in mired \param light
  50 + //! A reference of the light
  51 + virtual bool alertTemperature(unsigned int mired, HueLight& light) const = 0;
  52 + //! \brief Virtual function that returns the current color temperature of the
  53 + //! light
  54 + //!
  55 + //! Should update the lights state by calling refreshState()
  56 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  57 + //! and 500 is warm. \param light A reference of the light \return Unsigned
  58 + //! int representing the color temperature in mired
  59 + virtual unsigned int getColorTemperature(HueLight& light) const = 0;
  60 + //! \brief Virtual function that returns the current color temperature of the
  61 + //! light
  62 + //!
  63 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  64 + //! and 500 is warm. \note This should not update the lights state \param
  65 + //! light A const reference of the light \return Unsigned int representing the
  66 + //! color temperature in mired
  67 + virtual unsigned int getColorTemperature(const HueLight& light) const = 0;
  68 + //! \brief Virtual dtor
  69 + virtual ~ColorTemperatureStrategy() = default;
  70 + };
  71 +} // namespace hueplusplus
69 72  
70 73 #endif
... ...
include/hueplusplus/ExtendedColorHueStrategy.h
... ... @@ -26,38 +26,41 @@
26 26 #include "HueLight.h"
27 27 #include "SimpleColorHueStrategy.h"
28 28  
29   -//! Class extending the implementation of SimpleColorHueStrategy
30   -class ExtendedColorHueStrategy : public SimpleColorHueStrategy
  29 +namespace hueplusplus
31 30 {
32   -public:
33   - //! \brief Function that lets the light perform one breath cycle in the
34   - //! specified color.
35   - //!
36   - //! It uses this_thread::sleep_for to accomodate for the time an \ref
37   - //! HueLight::alert() needs The hue ranges from 0 to 65535, whereas 65535 and
38   - //! 0 are red, 25500 is green and 46920 is blue. The saturation ranges from 0
39   - //! to 254, whereas 0 is least saturated (white) and 254 is most saturated
40   - //! (vibrant). \param hue The hue of the color \param sat The saturation of
41   - //! the color \param light A reference of the light
42   - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override;
43   - //! \brief Function that lets the light perform one breath cycle in the
44   - //! specified color.
45   - //!
46   - //! It uses this_thread::sleep_for to accomodate for the time an \ref
47   - //! HueLight::alert() needs \param x The x coordinate in CIE, ranging from 0
48   - //! to 1 \param y The y coordinate in CIE, ranging from 0 to 1 \param light A
49   - //! reference of the light
50   - bool alertXY(float x, float y, HueLight& light) const override;
51   - //! \brief Function that lets the light perform one breath cycle in the
52   - //! specified color.
53   - //!
54   - //! It uses this_thread::sleep_for to accomodate for the time an \ref
55   - //! HueLight::alert() needs Red, green and blue are ranging from 0 to 255.
56   - //! \param r The red portion of the color
57   - //! \param g The green portion of the color
58   - //! \param b The blue portion of the color
59   - //! \param light A reference of the light
60   - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override;
61   -};
  31 + //! Class extending the implementation of SimpleColorHueStrategy
  32 + class ExtendedColorHueStrategy : public SimpleColorHueStrategy
  33 + {
  34 + public:
  35 + //! \brief Function that lets the light perform one breath cycle in the
  36 + //! specified color.
  37 + //!
  38 + //! It uses this_thread::sleep_for to accomodate for the time an \ref
  39 + //! HueLight::alert() needs The hue ranges from 0 to 65535, whereas 65535 and
  40 + //! 0 are red, 25500 is green and 46920 is blue. The saturation ranges from 0
  41 + //! to 254, whereas 0 is least saturated (white) and 254 is most saturated
  42 + //! (vibrant). \param hue The hue of the color \param sat The saturation of
  43 + //! the color \param light A reference of the light
  44 + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override;
  45 + //! \brief Function that lets the light perform one breath cycle in the
  46 + //! specified color.
  47 + //!
  48 + //! It uses this_thread::sleep_for to accomodate for the time an \ref
  49 + //! HueLight::alert() needs \param x The x coordinate in CIE, ranging from 0
  50 + //! to 1 \param y The y coordinate in CIE, ranging from 0 to 1 \param light A
  51 + //! reference of the light
  52 + bool alertXY(float x, float y, HueLight& light) const override;
  53 + //! \brief Function that lets the light perform one breath cycle in the
  54 + //! specified color.
  55 + //!
  56 + //! It uses this_thread::sleep_for to accomodate for the time an \ref
  57 + //! HueLight::alert() needs Red, green and blue are ranging from 0 to 255.
  58 + //! \param r The red portion of the color
  59 + //! \param g The green portion of the color
  60 + //! \param b The blue portion of the color
  61 + //! \param light A reference of the light
  62 + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override;
  63 + };
  64 +} // namespace hueplusplus
62 65  
63 66 #endif
... ...
include/hueplusplus/ExtendedColorTemperatureStrategy.h
... ... @@ -26,27 +26,30 @@
26 26 #include "HueLight.h"
27 27 #include "SimpleColorTemperatureStrategy.h"
28 28  
29   -//! Class implementing the functions of ColorTemperatureStrategy
30   -class ExtendedColorTemperatureStrategy : public SimpleColorTemperatureStrategy
  29 +namespace hueplusplus
31 30 {
32   -public:
33   - //! \brief Function for changing a lights color temperature in mired with a
34   - //! specified transition.
35   - //!
36   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
37   - //! and 500 is warm. \param mired The color temperature in mired \param
38   - //! transition The time it takes to fade to the new color in multiples of
39   - //! 100ms, 4 = 400ms and should be seen as the default \param light A
40   - //! reference of the light
41   - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override;
42   - //! \brief Function that lets the light perform one breath cycle in the
43   - //! specified color.
44   - //!
45   - //! It uses this_thread::sleep_for to accomodate for the time an \ref
46   - //! HueLight::alert() needs The color temperature in mired ranges from 153 to
47   - //! 500 whereas 153 is cold and 500 is warm. \param mired The color
48   - //! temperature in mired \param light A reference of the light
49   - bool alertTemperature(unsigned int mired, HueLight& light) const override;
50   -};
  31 + //! Class implementing the functions of ColorTemperatureStrategy
  32 + class ExtendedColorTemperatureStrategy : public SimpleColorTemperatureStrategy
  33 + {
  34 + public:
  35 + //! \brief Function for changing a lights color temperature in mired with a
  36 + //! specified transition.
  37 + //!
  38 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  39 + //! and 500 is warm. \param mired The color temperature in mired \param
  40 + //! transition The time it takes to fade to the new color in multiples of
  41 + //! 100ms, 4 = 400ms and should be seen as the default \param light A
  42 + //! reference of the light
  43 + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override;
  44 + //! \brief Function that lets the light perform one breath cycle in the
  45 + //! specified color.
  46 + //!
  47 + //! It uses this_thread::sleep_for to accomodate for the time an \ref
  48 + //! HueLight::alert() needs The color temperature in mired ranges from 153 to
  49 + //! 500 whereas 153 is cold and 500 is warm. \param mired The color
  50 + //! temperature in mired \param light A reference of the light
  51 + bool alertTemperature(unsigned int mired, HueLight& light) const override;
  52 + };
  53 +} // namespace hueplusplus
51 54  
52 55 #endif
... ...
include/hueplusplus/Hue.h
... ... @@ -38,245 +38,248 @@
38 38  
39 39 #include "json/json.hpp"
40 40  
41   -// forward declarations
42   -class Hue;
43   -
44   -//!
45   -//! Class to find all Hue bridges on the network and create usernames for them.
46   -//!
47   -class HueFinder
  41 +namespace hueplusplus
48 42 {
49   -public:
50   - struct HueIdentification
51   - {
52   - std::string ip;
53   - int port = 80;
54   - std::string mac;
55   - };
  43 + // forward declarations
  44 + class Hue;
56 45  
57   -public:
58   - //! \brief Constructor of HueFinder class
59 46 //!
60   - //! \param handler HttpHandler of type \ref IHttpHandler for communication with the bridge
61   - HueFinder(std::shared_ptr<const IHttpHandler> handler);
62   -
63   - //! \brief Finds all bridges in the network and returns them.
64   - //!
65   - //! The user should be given the opportunity to select the correct one based on the mac address.
66   - //! \return vector containing ip and mac of all found bridges
67   - //! \throws std::system_error when system or socket operations fail
68   - //! \throws HueException when response contained no body
69   - std::vector<HueIdentification> FindBridges() const;
70   -
71   - //! \brief Gets a \ref Hue bridge based on its identification
  47 + //! Class to find all Hue bridges on the network and create usernames for them.
72 48 //!
73   - //! \param identification \ref HueIdentification that specifies a bridge
74   - //! \return \ref Hue class object
75   - //! \throws std::system_error when system or socket operations fail
76   - //! \throws HueException when response contained no body or username could not be requested
77   - //! \throws HueAPIResponseException when response contains an error
78   - //! \throws nlohmann::json::parse_error when response could not be parsed
79   - Hue GetBridge(const HueIdentification& identification);
80   -
81   - //! \brief Function that adds a username to the usernames map
82   - //!
83   - //! \param mac MAC address of Hue bridge
84   - //! \param username Username that is used to control the Hue bridge
85   - void AddUsername(const std::string& mac, const std::string& username);
86   -
87   - //! \brief Function that returns a map of mac addresses and usernames.
88   - //!
89   - //! Note these should be saved at the end and re-loaded with \ref AddUsername
90   - //! next time, so only one username is generated per bridge. \returns A map
91   - //! mapping mac address to username for every bridge
92   - const std::map<std::string, std::string>& GetAllUsernames() const;
93   -
94   - //! \brief Normalizes mac address to plain hex number.
95   - //! \returns \p input without separators and whitespace, in lower case.
96   - static std::string NormalizeMac(std::string input);
97   -
98   -private:
99   - //! \brief Parses mac address from description.xml
100   - //!
101   - //! \param description Content of description.xml file as returned by GET request.
102   - //! \returns Content of xml element \c serialNumber if description matches a Hue bridge, otherwise an empty string.
103   - static std::string ParseDescription(const std::string& description);
104   -
105   - std::map<std::string, std::string> usernames; //!< Maps all macs to usernames added by \ref
106   - //!< HueFinder::AddUsername
107   - std::shared_ptr<const IHttpHandler> http_handler;
108   -};
109   -
110   -//! Hue class
111   -class Hue
112   -{
113   - friend class HueFinder;
114   -
115   -public:
116   - //! \brief Constructor of Hue class
117   - //!
118   - //! \param ip IP address in dotted decimal notation like "192.168.2.1"
119   - //! \param port Port of the hue bridge
120   - //! \param username String that specifies the username that is used to control
121   - //! the bridge. This needs to be acquired in \ref requestUsername
122   - //! \param handler HttpHandler for communication with the bridge
123   - Hue(const std::string& ip, const int port, const std::string& username,
124   - std::shared_ptr<const IHttpHandler> handler);
125   -
126   - //! \brief Function to get the ip address of the hue bridge
127   - //!
128   - //! \return string containing ip
129   - std::string getBridgeIP();
130   -
131   - //! \brief Function to get the port of the hue bridge
132   - //!
133   - //! \return integer containing port
134   - int getBridgePort();
135   -
136   - //! \brief Send a username request to the Hue bridge.
137   - //!
138   - //! Blocks for about 30 seconds and 5 seconds to prepare.
139   - //! It automatically sets the username variable according to the username received and returns the username
140   - //! received. This function should only be called once to acquire a username to control the bridge and the username
141   - //! should be saved for future use.
142   - //! \return username for API usage
143   - //! \throws std::system_error when system or socket operations fail
144   - //! \throws HueException when response contained no body
145   - //! \throws HueAPIResponseException when response contains an error except link button not pressed.
146   - //! \throws nlohmann::json::parse_error when response could not be parsed
147   - std::string requestUsername();
148   -
149   - //! \brief Function that returns the username
150   - //!
151   - //! \return The username used for API access
152   - std::string getUsername();
153   -
154   - //! \brief Function to set the ip address of this class representing a bridge
155   - //!
156   - //! \param ip String that specifies the ip in dotted decimal notation like "192.168.2.1"
157   - void setIP(const std::string& ip);
158   -
159   - //! \brief Function to set the port of this class representing a bridge
160   - //!
161   - //! \param port Integer that specifies the port of an address like
162   - //! "192.168.2.1:8080"
163   - void setPort(const int port);
164   -
165   - //! \brief Function that returns a \ref HueLight of specified id
166   - //!
167   - //! \param id Integer that specifies the ID of a Hue light
168   - //! \return \ref HueLight that can be controlled
169   - //! \throws std::system_error when system or socket operations fail
170   - //! \throws HueException when id does not exist or type is unknown
171   - //! \throws HueAPIResponseException when response contains an error
172   - //! \throws nlohmann::json::parse_error when response could not be parsed
173   - HueLight& getLight(int id);
174   -
175   - //! \brief Function to remove a light from the bridge
176   - //!
177   - //! \attention Any use of the light after it was successfully removed results in undefined behavior
178   - //! \param id Id of the light to remove
179   - //! \return true on success
180   - //! \throws std::system_error when system or socket operations fail
181   - //! \throws HueException when response contains no body
182   - //! \throws HueAPIResponseException when response contains an error
183   - //! \throws nlohmann::json::parse_error when response could not be parsed
184   - bool removeLight(int id);
185   -
186   - //! \brief Function that returns all light types that are associated with this bridge
187   - //!
188   - //! \return A map mapping light id's to light types for every light
189   - // const std::map<uint8_t, ColorType>& getAllLightTypes();
190   -
191   - //! \brief Function that returns all lights that are associated with this
192   - //! bridge
193   - //!
194   - //! \return A vector containing references to every HueLight
195   - //! \throws std::system_error when system or socket operations fail
196   - //! \throws HueException when response contains no body
197   - //! \throws HueAPIResponseException when response contains an error
198   - //! \throws nlohmann::json::parse_error when response could not be parsed
199   - std::vector<std::reference_wrapper<HueLight>> getAllLights();
200   -
201   - //! \brief Function that tells whether a given light id represents an existing light
202   - //!
203   - //! Calls refreshState to update the local bridge state
204   - //! \param id Id of a light to check for existance
205   - //! \return Bool that is true when a light with the given id exists and false when not
206   - //! \throws std::system_error when system or socket operations fail
207   - //! \throws HueException when response contains no body
208   - //! \throws HueAPIResponseException when response contains an error
209   - //! \throws nlohmann::json::parse_error when response could not be parsed
210   - bool lightExists(int id);
211   -
212   - //! \brief Const function that tells whether a given light id represents an
213   - //! existing light
214   - //!
215   - //! \note This will not update the local state of the bridge
216   - //! \param id Id of a light to check for existance
217   - //! \return Bool that is true when a light with the given id exists and false
218   - //! when not
219   - bool lightExists(int id) const;
  49 + class HueFinder
  50 + {
  51 + public:
  52 + struct HueIdentification
  53 + {
  54 + std::string ip;
  55 + int port = 80;
  56 + std::string mac;
  57 + };
  58 +
  59 + public:
  60 + //! \brief Constructor of HueFinder class
  61 + //!
  62 + //! \param handler HttpHandler of type \ref IHttpHandler for communication with the bridge
  63 + HueFinder(std::shared_ptr<const IHttpHandler> handler);
  64 +
  65 + //! \brief Finds all bridges in the network and returns them.
  66 + //!
  67 + //! The user should be given the opportunity to select the correct one based on the mac address.
  68 + //! \return vector containing ip and mac of all found bridges
  69 + //! \throws std::system_error when system or socket operations fail
  70 + //! \throws HueException when response contained no body
  71 + std::vector<HueIdentification> FindBridges() const;
  72 +
  73 + //! \brief Gets a \ref Hue bridge based on its identification
  74 + //!
  75 + //! \param identification \ref HueIdentification that specifies a bridge
  76 + //! \return \ref Hue class object
  77 + //! \throws std::system_error when system or socket operations fail
  78 + //! \throws HueException when response contained no body or username could not be requested
  79 + //! \throws HueAPIResponseException when response contains an error
  80 + //! \throws nlohmann::json::parse_error when response could not be parsed
  81 + Hue GetBridge(const HueIdentification& identification);
  82 +
  83 + //! \brief Function that adds a username to the usernames map
  84 + //!
  85 + //! \param mac MAC address of Hue bridge
  86 + //! \param username Username that is used to control the Hue bridge
  87 + void AddUsername(const std::string& mac, const std::string& username);
  88 +
  89 + //! \brief Function that returns a map of mac addresses and usernames.
  90 + //!
  91 + //! Note these should be saved at the end and re-loaded with \ref AddUsername
  92 + //! next time, so only one username is generated per bridge. \returns A map
  93 + //! mapping mac address to username for every bridge
  94 + const std::map<std::string, std::string>& GetAllUsernames() const;
  95 +
  96 + //! \brief Normalizes mac address to plain hex number.
  97 + //! \returns \p input without separators and whitespace, in lower case.
  98 + static std::string NormalizeMac(std::string input);
  99 +
  100 + private:
  101 + //! \brief Parses mac address from description.xml
  102 + //!
  103 + //! \param description Content of description.xml file as returned by GET request.
  104 + //! \returns Content of xml element \c serialNumber if description matches a Hue bridge, otherwise an empty
  105 + //! string.
  106 + static std::string ParseDescription(const std::string& description);
  107 +
  108 + std::map<std::string, std::string> usernames; //!< Maps all macs to usernames added by \ref
  109 + //!< HueFinder::AddUsername
  110 + std::shared_ptr<const IHttpHandler> http_handler;
  111 + };
220 112  
221   - //! \brief Const function that returns the picture name of a given light id
222   - //!
223   - //! \note This will not update the local state of the bridge.
224   - //! \note This function will only return the filename without extension,
225   - //! because Philips provides different file types. \param id Id of a light to
226   - //! get the picture of \return String that either contains the filename of the
227   - //! picture of the light or if it was not found an empty string
228   - std::string getPictureOfLight(int id) const;
229   -
230   - //! \brief Const function that returns the picture name of a given model id
231   - //!
232   - //! \note This will not update the local state of the bridge.
233   - //! \note This function will only return the filename without extension,
234   - //! because Philips provides different file types. \param model_id Model Id of
235   - //! a device to get the picture of \return String that either contains the
236   - //! filename of the picture of the device or if it was not found an empty
237   - //! string
238   - std::string getPictureOfModel(const std::string& model_id) const;
239   -
240   - //! \brief Function that sets the HttpHandler and updates the HueCommandAPI.
241   - //!
242   - //! The HttpHandler and HueCommandAPI are used for bridge communication
243   - //! \param handler a HttpHandler of type \ref IHttpHandler
244   - void setHttpHandler(std::shared_ptr<const IHttpHandler> handler)
  113 + //! Hue class
  114 + class Hue
245 115 {
246   - http_handler = std::move(handler);
247   - commands = HueCommandAPI(ip, port, username, http_handler);
248   - }
249   -
250   -private:
251   - //! \brief Function that refreshes the local \ref state of the Hue bridge
252   - //! \throws std::system_error when system or socket operations fail
253   - //! \throws HueException when response contained no body
254   - //! \throws HueAPIResponseException when response contains an error
255   - //! \throws nlohmann::json::parse_error when response could not be parsed
256   - void refreshState();
257   -
258   -private:
259   - std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation
260   - //!< like "192.168.2.1"
261   - std::string username; //!< Username that is ussed to access the hue bridge
262   - int port;
263   - nlohmann::json state; //!< The state of the hue bridge as it is returned from it
264   - std::map<uint8_t, HueLight> lights; //!< Maps ids to HueLights that are controlled by this bridge
265   -
266   - std::shared_ptr<BrightnessStrategy> simpleBrightnessStrategy; //!< Strategy that is used for controlling the
267   - //!< brightness of lights
268   - std::shared_ptr<ColorHueStrategy> simpleColorHueStrategy; //!< Strategy that is used for controlling the
269   - //!< color of lights
270   - std::shared_ptr<ColorHueStrategy> extendedColorHueStrategy; //!< Strategy that is used for controlling the
271   - //!< color of lights
272   - std::shared_ptr<ColorTemperatureStrategy> simpleColorTemperatureStrategy; //!< Strategy that is used for controlling
273   - //!< the color temperature of lights
274   - std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy; //!< Strategy that is used for
275   - //!< controlling the color temperature
276   - //!< of lights
277   - std::shared_ptr<const IHttpHandler> http_handler; //!< A IHttpHandler that is used to communicate with the
278   - //!< bridge
279   - HueCommandAPI commands; //!< A HueCommandAPI that is used to communicate with the bridge
280   -};
  116 + friend class HueFinder;
  117 +
  118 + public:
  119 + //! \brief Constructor of Hue class
  120 + //!
  121 + //! \param ip IP address in dotted decimal notation like "192.168.2.1"
  122 + //! \param port Port of the hue bridge
  123 + //! \param username String that specifies the username that is used to control
  124 + //! the bridge. This needs to be acquired in \ref requestUsername
  125 + //! \param handler HttpHandler for communication with the bridge
  126 + Hue(const std::string& ip, const int port, const std::string& username,
  127 + std::shared_ptr<const IHttpHandler> handler);
  128 +
  129 + //! \brief Function to get the ip address of the hue bridge
  130 + //!
  131 + //! \return string containing ip
  132 + std::string getBridgeIP();
  133 +
  134 + //! \brief Function to get the port of the hue bridge
  135 + //!
  136 + //! \return integer containing port
  137 + int getBridgePort();
  138 +
  139 + //! \brief Send a username request to the Hue bridge.
  140 + //!
  141 + //! Blocks for about 30 seconds and 5 seconds to prepare.
  142 + //! It automatically sets the username variable according to the username received and returns the username
  143 + //! received. This function should only be called once to acquire a username to control the bridge and the
  144 + //! username should be saved for future use. \return username for API usage \throws std::system_error when
  145 + //! system or socket operations fail \throws HueException when response contained no body \throws
  146 + //! HueAPIResponseException when response contains an error except link button not pressed. \throws
  147 + //! nlohmann::json::parse_error when response could not be parsed
  148 + std::string requestUsername();
  149 +
  150 + //! \brief Function that returns the username
  151 + //!
  152 + //! \return The username used for API access
  153 + std::string getUsername();
  154 +
  155 + //! \brief Function to set the ip address of this class representing a bridge
  156 + //!
  157 + //! \param ip String that specifies the ip in dotted decimal notation like "192.168.2.1"
  158 + void setIP(const std::string& ip);
  159 +
  160 + //! \brief Function to set the port of this class representing a bridge
  161 + //!
  162 + //! \param port Integer that specifies the port of an address like
  163 + //! "192.168.2.1:8080"
  164 + void setPort(const int port);
  165 +
  166 + //! \brief Function that returns a \ref HueLight of specified id
  167 + //!
  168 + //! \param id Integer that specifies the ID of a Hue light
  169 + //! \return \ref HueLight that can be controlled
  170 + //! \throws std::system_error when system or socket operations fail
  171 + //! \throws HueException when id does not exist or type is unknown
  172 + //! \throws HueAPIResponseException when response contains an error
  173 + //! \throws nlohmann::json::parse_error when response could not be parsed
  174 + HueLight& getLight(int id);
  175 +
  176 + //! \brief Function to remove a light from the bridge
  177 + //!
  178 + //! \attention Any use of the light after it was successfully removed results in undefined behavior
  179 + //! \param id Id of the light to remove
  180 + //! \return true on success
  181 + //! \throws std::system_error when system or socket operations fail
  182 + //! \throws HueException when response contains no body
  183 + //! \throws HueAPIResponseException when response contains an error
  184 + //! \throws nlohmann::json::parse_error when response could not be parsed
  185 + bool removeLight(int id);
  186 +
  187 + //! \brief Function that returns all light types that are associated with this bridge
  188 + //!
  189 + //! \return A map mapping light id's to light types for every light
  190 + // const std::map<uint8_t, ColorType>& getAllLightTypes();
  191 +
  192 + //! \brief Function that returns all lights that are associated with this
  193 + //! bridge
  194 + //!
  195 + //! \return A vector containing references to every HueLight
  196 + //! \throws std::system_error when system or socket operations fail
  197 + //! \throws HueException when response contains no body
  198 + //! \throws HueAPIResponseException when response contains an error
  199 + //! \throws nlohmann::json::parse_error when response could not be parsed
  200 + std::vector<std::reference_wrapper<HueLight>> getAllLights();
  201 +
  202 + //! \brief Function that tells whether a given light id represents an existing light
  203 + //!
  204 + //! Calls refreshState to update the local bridge state
  205 + //! \param id Id of a light to check for existance
  206 + //! \return Bool that is true when a light with the given id exists and false when not
  207 + //! \throws std::system_error when system or socket operations fail
  208 + //! \throws HueException when response contains no body
  209 + //! \throws HueAPIResponseException when response contains an error
  210 + //! \throws nlohmann::json::parse_error when response could not be parsed
  211 + bool lightExists(int id);
  212 +
  213 + //! \brief Const function that tells whether a given light id represents an
  214 + //! existing light
  215 + //!
  216 + //! \note This will not update the local state of the bridge
  217 + //! \param id Id of a light to check for existance
  218 + //! \return Bool that is true when a light with the given id exists and false
  219 + //! when not
  220 + bool lightExists(int id) const;
  221 +
  222 + //! \brief Const function that returns the picture name of a given light id
  223 + //!
  224 + //! \note This will not update the local state of the bridge.
  225 + //! \note This function will only return the filename without extension,
  226 + //! because Philips provides different file types. \param id Id of a light to
  227 + //! get the picture of \return String that either contains the filename of the
  228 + //! picture of the light or if it was not found an empty string
  229 + std::string getPictureOfLight(int id) const;
  230 +
  231 + //! \brief Const function that returns the picture name of a given model id
  232 + //!
  233 + //! \note This will not update the local state of the bridge.
  234 + //! \note This function will only return the filename without extension,
  235 + //! because Philips provides different file types. \param model_id Model Id of
  236 + //! a device to get the picture of \return String that either contains the
  237 + //! filename of the picture of the device or if it was not found an empty
  238 + //! string
  239 + std::string getPictureOfModel(const std::string& model_id) const;
  240 +
  241 + //! \brief Function that sets the HttpHandler and updates the HueCommandAPI.
  242 + //!
  243 + //! The HttpHandler and HueCommandAPI are used for bridge communication
  244 + //! \param handler a HttpHandler of type \ref IHttpHandler
  245 + void setHttpHandler(std::shared_ptr<const IHttpHandler> handler)
  246 + {
  247 + http_handler = std::move(handler);
  248 + commands = HueCommandAPI(ip, port, username, http_handler);
  249 + }
  250 +
  251 + private:
  252 + //! \brief Function that refreshes the local \ref state of the Hue bridge
  253 + //! \throws std::system_error when system or socket operations fail
  254 + //! \throws HueException when response contained no body
  255 + //! \throws HueAPIResponseException when response contains an error
  256 + //! \throws nlohmann::json::parse_error when response could not be parsed
  257 + void refreshState();
  258 +
  259 + private:
  260 + std::string ip; //!< IP-Address of the hue bridge in dotted decimal notation
  261 + //!< like "192.168.2.1"
  262 + std::string username; //!< Username that is ussed to access the hue bridge
  263 + int port;
  264 + nlohmann::json state; //!< The state of the hue bridge as it is returned from it
  265 + std::map<uint8_t, HueLight> lights; //!< Maps ids to HueLights that are controlled by this bridge
  266 +
  267 + std::shared_ptr<BrightnessStrategy> simpleBrightnessStrategy; //!< Strategy that is used for controlling the
  268 + //!< brightness of lights
  269 + std::shared_ptr<ColorHueStrategy> simpleColorHueStrategy; //!< Strategy that is used for controlling the
  270 + //!< color of lights
  271 + std::shared_ptr<ColorHueStrategy> extendedColorHueStrategy; //!< Strategy that is used for controlling the
  272 + //!< color of lights
  273 + std::shared_ptr<ColorTemperatureStrategy>
  274 + simpleColorTemperatureStrategy; //!< Strategy that is used for controlling
  275 + //!< the color temperature of lights
  276 + std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy; //!< Strategy that is used for
  277 + //!< controlling the color
  278 + //!< temperature of lights
  279 + std::shared_ptr<const IHttpHandler> http_handler; //!< A IHttpHandler that is used to communicate with the
  280 + //!< bridge
  281 + HueCommandAPI commands; //!< A HueCommandAPI that is used to communicate with the bridge
  282 + };
  283 +} // namespace hueplusplus
281 284  
282 285 #endif
... ...
include/hueplusplus/HueCommandAPI.h
... ... @@ -30,94 +30,98 @@
30 30 #include "HueException.h"
31 31 #include "IHttpHandler.h"
32 32  
33   -//! Handles communication to the bridge via IHttpHandler and enforces a timeout
34   -//! between each request
35   -class HueCommandAPI
  33 +namespace hueplusplus
36 34 {
37   -public:
38   - //! \brief Construct from ip, username and HttpHandler
39   - //!
40   - //! \param ip ip address of the Hue bridge in dotted decimal notation like "192.168.2.1"
41   - //! \param port of the hue bridge
42   - //! \param username username that is used to control the bridge
43   - //! \param httpHandler HttpHandler for communication with the bridge
44   - HueCommandAPI(
45   - const std::string& ip, int port, const std::string& username, std::shared_ptr<const IHttpHandler> httpHandler);
46   -
47   - //! \brief Copy construct from other HueCommandAPI
48   - //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
49   - HueCommandAPI(const HueCommandAPI&) = default;
50   - //! \brief Move construct from other HueCommandAPI
51   - //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
52   - HueCommandAPI(HueCommandAPI&&) = default;
53   -
54   - //! \brief Copy assign from other HueCommandAPI
55   - //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
56   - HueCommandAPI& operator=(const HueCommandAPI&) = default;
57   - //! \brief Move assign from other HueCommandAPI
58   - //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
59   - HueCommandAPI& operator=(HueCommandAPI&&) = default;
60   -
61   - //! \brief Sends a HTTP PUT request to the bridge and returns the response
62   - //!
63   - //! This function will block until at least \ref minDelay has passed to any previous request
64   - //! \param path API request path (appended after /api/{username})
65   - //! \param request Request to the api, may be empty
66   - //! \returns The return value of the underlying \ref IHttpHandler::PUTJson call
67   - //! \throws std::system_error when system or socket operations fail
68   - //! \throws HueException when response contains no body
69   - //! \throws HueAPIResponseException when response contains an error
70   - nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request) const;
71   - nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
72   -
73   - //! \brief Sends a HTTP GET request to the bridge and returns the response
74   - //!
75   - //! This function will block until at least \ref minDelay has passed to any previous request
76   - //! \param path API request path (appended after /api/{username})
77   - //! \param request Request to the api, may be empty
78   - //! \returns The return value of the underlying \ref IHttpHandler::GETJson call
79   - //! \throws std::system_error when system or socket operations fail
80   - //! \throws HueException when response contains no body
81   - //! \throws HueAPIResponseException when response contains an error
82   - nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request) const;
83   - nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
84   -
85   - //! \brief Sends a HTTP DELETE request to the bridge and returns the response
86   - //!
87   - //! This function will block until at least \ref minDelay has passed to any previous request
88   - //! \param path API request path (appended after /api/{username})
89   - //! \param request Request to the api, may be empty
90   - //! \returns The return value of the underlying \ref IHttpHandler::DELETEJson call
91   - //! \throws std::system_error when system or socket operations fail
92   - //! \throws HueException when response contains no body
93   - //! \throws HueAPIResponseException when response contains an error
94   - nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request) const;
95   - nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
96   -
97   -private:
98   - struct TimeoutData
  35 + //! Handles communication to the bridge via IHttpHandler and enforces a timeout
  36 + //! between each request
  37 + class HueCommandAPI
99 38 {
100   - std::chrono::steady_clock::time_point timeout;
101   - std::mutex mutex;
  39 + public:
  40 + //! \brief Construct from ip, username and HttpHandler
  41 + //!
  42 + //! \param ip ip address of the Hue bridge in dotted decimal notation like "192.168.2.1"
  43 + //! \param port of the hue bridge
  44 + //! \param username username that is used to control the bridge
  45 + //! \param httpHandler HttpHandler for communication with the bridge
  46 + HueCommandAPI(const std::string& ip, int port, const std::string& username,
  47 + std::shared_ptr<const IHttpHandler> httpHandler);
  48 +
  49 + //! \brief Copy construct from other HueCommandAPI
  50 + //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
  51 + HueCommandAPI(const HueCommandAPI&) = default;
  52 + //! \brief Move construct from other HueCommandAPI
  53 + //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
  54 + HueCommandAPI(HueCommandAPI&&) = default;
  55 +
  56 + //! \brief Copy assign from other HueCommandAPI
  57 + //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
  58 + HueCommandAPI& operator=(const HueCommandAPI&) = default;
  59 + //! \brief Move assign from other HueCommandAPI
  60 + //! \note All copies refer to the same timeout data, so even calls from different objects will be delayed
  61 + HueCommandAPI& operator=(HueCommandAPI&&) = default;
  62 +
  63 + //! \brief Sends a HTTP PUT request to the bridge and returns the response
  64 + //!
  65 + //! This function will block until at least \ref minDelay has passed to any previous request
  66 + //! \param path API request path (appended after /api/{username})
  67 + //! \param request Request to the api, may be empty
  68 + //! \returns The return value of the underlying \ref IHttpHandler::PUTJson call
  69 + //! \throws std::system_error when system or socket operations fail
  70 + //! \throws HueException when response contains no body
  71 + //! \throws HueAPIResponseException when response contains an error
  72 + nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request) const;
  73 + nlohmann::json PUTRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
  74 +
  75 + //! \brief Sends a HTTP GET request to the bridge and returns the response
  76 + //!
  77 + //! This function will block until at least \ref minDelay has passed to any previous request
  78 + //! \param path API request path (appended after /api/{username})
  79 + //! \param request Request to the api, may be empty
  80 + //! \returns The return value of the underlying \ref IHttpHandler::GETJson call
  81 + //! \throws std::system_error when system or socket operations fail
  82 + //! \throws HueException when response contains no body
  83 + //! \throws HueAPIResponseException when response contains an error
  84 + nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request) const;
  85 + nlohmann::json GETRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
  86 +
  87 + //! \brief Sends a HTTP DELETE request to the bridge and returns the response
  88 + //!
  89 + //! This function will block until at least \ref minDelay has passed to any previous request
  90 + //! \param path API request path (appended after /api/{username})
  91 + //! \param request Request to the api, may be empty
  92 + //! \returns The return value of the underlying \ref IHttpHandler::DELETEJson call
  93 + //! \throws std::system_error when system or socket operations fail
  94 + //! \throws HueException when response contains no body
  95 + //! \throws HueAPIResponseException when response contains an error
  96 + nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request) const;
  97 + nlohmann::json DELETERequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const;
  98 +
  99 + private:
  100 + struct TimeoutData
  101 + {
  102 + std::chrono::steady_clock::time_point timeout;
  103 + std::mutex mutex;
  104 + };
  105 +
  106 + //! \brief Throws an exception if response contains an error, passes though value
  107 + //! \throws HueAPIResponseException when response contains an error
  108 + //! \returns \ref response if there is no error
  109 + nlohmann::json HandleError(FileInfo fileInfo, const nlohmann::json& response) const;
  110 +
  111 + //! \brief Combines path with api prefix and username
  112 + //! \returns "/api/<username>/<path>"
  113 + std::string CombinedPath(const std::string& path) const;
  114 +
  115 + public:
  116 + static constexpr std::chrono::steady_clock::duration minDelay = std::chrono::milliseconds(100);
  117 +
  118 + private:
  119 + std::string ip;
  120 + int port;
  121 + std::string username;
  122 + std::shared_ptr<const IHttpHandler> httpHandler;
  123 + std::shared_ptr<TimeoutData> timeout;
102 124 };
103   -
104   - //! \brief Throws an exception if response contains an error, passes though value
105   - //! \throws HueAPIResponseException when response contains an error
106   - //! \returns \ref response if there is no error
107   - nlohmann::json HandleError(FileInfo fileInfo, const nlohmann::json& response) const;
108   -
109   - //! \brief Combines path with api prefix and username
110   - //! \returns "/api/<username>/<path>"
111   - std::string CombinedPath(const std::string& path) const;
112   -
113   -public:
114   - static constexpr std::chrono::steady_clock::duration minDelay = std::chrono::milliseconds(100);
115   -private:
116   - std::string ip;
117   - int port;
118   - std::string username;
119   - std::shared_ptr<const IHttpHandler> httpHandler;
120   - std::shared_ptr<TimeoutData> timeout;
121   -};
  125 +} // namespace hueplusplus
122 126  
123 127 #endif
124 128 \ No newline at end of file
... ...
include/hueplusplus/HueConfig.h
... ... @@ -23,7 +23,10 @@
23 23 #ifndef _HUE_CONFIG_H
24 24 #define _HUE_CONFIG_H
25 25  
26   -const uint16_t c_PRE_ALERT_DELAY = 120; //!< Delay for advanced alerts before the actual alert
27   -const uint16_t c_POST_ALERT_DELAY = 1600; //!< Delay for advanced alerts after the actual alert
  26 +namespace hueplusplus
  27 +{
  28 + constexpr uint16_t c_PRE_ALERT_DELAY = 120; //!< Delay for advanced alerts before the actual alert
  29 + constexpr uint16_t c_POST_ALERT_DELAY = 1600; //!< Delay for advanced alerts after the actual alert
  30 +} // namespace hueplusplus
28 31  
29 32 #endif
... ...
include/hueplusplus/HueDeviceTypes.h
... ... @@ -20,7 +20,6 @@
20 20 along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
21 21 **/
22 22  
23   -
24 23 #ifndef _HUEDEVICETYPES_H
25 24 #define _HUEDEVICETYPES_H
26 25  
... ... @@ -29,15 +28,17 @@
29 28  
30 29 #include "HueLight.h"
31 30  
32   -struct MakeHueLight {
33   - auto operator()(std::string type, int id, HueCommandAPI commands,
34   - std::shared_ptr<BrightnessStrategy> simpleBrightnessStrategy,
35   - std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy,
36   - std::shared_ptr<ColorTemperatureStrategy> simpleColorTemperatureStrategy,
37   - std::shared_ptr<ColorHueStrategy> extendedColorHueStrategy,
38   - std::shared_ptr<ColorHueStrategy> simpleColorHueStrategy) -> HueLight;
39   -};
40   -
  31 +namespace hueplusplus
  32 +{
  33 + struct MakeHueLight
  34 + {
  35 + auto operator()(std::string type, int id, HueCommandAPI commands,
  36 + std::shared_ptr<BrightnessStrategy> simpleBrightnessStrategy,
  37 + std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy,
  38 + std::shared_ptr<ColorTemperatureStrategy> simpleColorTemperatureStrategy,
  39 + std::shared_ptr<ColorHueStrategy> extendedColorHueStrategy,
  40 + std::shared_ptr<ColorHueStrategy> simpleColorHueStrategy) -> HueLight;
  41 + };
  42 +} // namespace hueplusplus
41 43  
42 44 #endif
43   -
... ...
include/hueplusplus/HueException.h
... ... @@ -28,91 +28,94 @@
28 28  
29 29 #include "json/json.hpp"
30 30  
31   -//! \brief Contains information about error location, use CURRENT_FILE_INFO to create
32   -struct FileInfo
  31 +namespace hueplusplus
33 32 {
34   - //! \brief Current file name from __FILE__. Empty if unknown
35   - std::string filename;
36   - //! \brief Current line number from __LINE__. -1 if unknown
37   - int line = -1;
38   - //! \brief Current function from __func__. Empty if unknown
39   - std::string func;
40   -
41   - //! \brief String representation of func, file and line.
42   - //! \returns "<func> in <filename>:<line>" or "Unknown file" if unknown.
43   - std::string ToString() const;
44   -};
45   -
46   -//! \brief Exception class with file information. Base class of all custom exception classes
47   -class HueException : public std::exception
48   -{
49   -public:
50   - //! \brief Creates HueException with information about the error and source
51   - //! \param fileInfo Source of the error. Must not always be the throw location,
52   - //! can also be a calling function which matches the cause better.
53   - //! \param message Human readable error message.
54   - HueException(FileInfo fileInfo, const std::string& message);
55   -
56   - //! \brief What message of the exception
57   - //! \returns exception name, file info and constructor message as char* into member string
58   - const char* what() const noexcept override;
59   -
60   - //! \brief Filename and line where the exception was thrown or caused by
61   - const FileInfo& GetFile() const noexcept;
62   -
63   -protected:
64   - //! \brief Creates HueException with child class name
65   - //!
66   - //! Should be used by subclasses which can append additional information to the end of whatMessage.
67   - //! \param exceptionName class name of the subclass
68   - //! \param fileInfo Source of the error. Must not always be the throw location,
69   - //! can also be a calling function which matches the cause better.
70   - //! \param message Human readable error message
71   - HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message);
72   -
73   -private:
74   - std::string whatMessage;
75   - FileInfo fileInfo;
76   -};
77   -
78   -//! \brief Exception caused by a Hue API "error" response with additional information
79   -//!
80   -//! Refer to Hue developer documentation for more detail on specific error codes.
81   -class HueAPIResponseException : public HueException
82   -{
83   -public:
84   - //! \brief Create exception with info from Hue API error
85   - //! \param fileInfo Source of the error. Must not always be the throw location,
86   - //! can also be a calling function which matches the cause better.
87   - //! \param error Hue API error code from error response.
88   - //! \param address URI the API call referred to from error response.
89   - //! \param description Error description from response.
90   - HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description);
91   -
92   - //! \brief Error number from Hue API error response.
  33 + //! \brief Contains information about error location, use CURRENT_FILE_INFO to create
  34 + struct FileInfo
  35 + {
  36 + //! \brief Current file name from __FILE__. Empty if unknown
  37 + std::string filename;
  38 + //! \brief Current line number from __LINE__. -1 if unknown
  39 + int line = -1;
  40 + //! \brief Current function from __func__. Empty if unknown
  41 + std::string func;
  42 +
  43 + //! \brief String representation of func, file and line.
  44 + //! \returns "<func> in <filename>:<line>" or "Unknown file" if unknown.
  45 + std::string ToString() const;
  46 + };
  47 +
  48 + //! \brief Exception class with file information. Base class of all custom exception classes
  49 + class HueException : public std::exception
  50 + {
  51 + public:
  52 + //! \brief Creates HueException with information about the error and source
  53 + //! \param fileInfo Source of the error. Must not always be the throw location,
  54 + //! can also be a calling function which matches the cause better.
  55 + //! \param message Human readable error message.
  56 + HueException(FileInfo fileInfo, const std::string& message);
  57 +
  58 + //! \brief What message of the exception
  59 + //! \returns exception name, file info and constructor message as char* into member string
  60 + const char* what() const noexcept override;
  61 +
  62 + //! \brief Filename and line where the exception was thrown or caused by
  63 + const FileInfo& GetFile() const noexcept;
  64 +
  65 + protected:
  66 + //! \brief Creates HueException with child class name
  67 + //!
  68 + //! Should be used by subclasses which can append additional information to the end of whatMessage.
  69 + //! \param exceptionName class name of the subclass
  70 + //! \param fileInfo Source of the error. Must not always be the throw location,
  71 + //! can also be a calling function which matches the cause better.
  72 + //! \param message Human readable error message
  73 + HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message);
  74 +
  75 + private:
  76 + std::string whatMessage;
  77 + FileInfo fileInfo;
  78 + };
  79 +
  80 + //! \brief Exception caused by a Hue API "error" response with additional information
93 81 //!
94   - //! Refer to Hue developer documentation for meaning of error codes.
95   - int GetErrorNumber() const noexcept;
96   - //! \brief Address the API call tried to access.
97   - const std::string& GetAddress() const noexcept;
98   - //! \brief Error description
99   - const std::string& GetDescription() const noexcept;
100   -
101   - //! \brief Creates exception from API response.
102   - //! \param fileInfo Location of the cause
103   - //! \param response Hue API response. Must contain a member "error" with "type", "address" and "description".
104   - //! \returns HueAPIResponseException with info from the response.
105   - //! If response does not contain the required members, they are defaulted to -1 or "".
106   - static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json& response);
107   -
108   -private:
109   - //! \brief Creates exception message containing the given information
110   - static std::string GetMessage(int error, const std::string& addr, const std::string& description);
111   -
112   -private:
113   - int error;
114   - std::string address;
115   - std::string description;
116   -};
  82 + //! Refer to Hue developer documentation for more detail on specific error codes.
  83 + class HueAPIResponseException : public HueException
  84 + {
  85 + public:
  86 + //! \brief Create exception with info from Hue API error
  87 + //! \param fileInfo Source of the error. Must not always be the throw location,
  88 + //! can also be a calling function which matches the cause better.
  89 + //! \param error Hue API error code from error response.
  90 + //! \param address URI the API call referred to from error response.
  91 + //! \param description Error description from response.
  92 + HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description);
  93 +
  94 + //! \brief Error number from Hue API error response.
  95 + //!
  96 + //! Refer to Hue developer documentation for meaning of error codes.
  97 + int GetErrorNumber() const noexcept;
  98 + //! \brief Address the API call tried to access.
  99 + const std::string& GetAddress() const noexcept;
  100 + //! \brief Error description
  101 + const std::string& GetDescription() const noexcept;
  102 +
  103 + //! \brief Creates exception from API response.
  104 + //! \param fileInfo Location of the cause
  105 + //! \param response Hue API response. Must contain a member "error" with "type", "address" and "description".
  106 + //! \returns HueAPIResponseException with info from the response.
  107 + //! If response does not contain the required members, they are defaulted to -1 or "".
  108 + static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json& response);
  109 +
  110 + private:
  111 + //! \brief Creates exception message containing the given information
  112 + static std::string GetMessage(int error, const std::string& addr, const std::string& description);
  113 +
  114 + private:
  115 + int error;
  116 + std::string address;
  117 + std::string description;
  118 + };
  119 +} // namespace hueplusplus
117 120  
118 121 #endif
119 122 \ No newline at end of file
... ...
include/hueplusplus/HueExceptionMacro.h
... ... @@ -23,5 +23,5 @@
23 23 #include "HueException.h"
24 24  
25 25 #ifndef CURRENT_FILE_INFO
26   -#define CURRENT_FILE_INFO (FileInfo{__FILE__, __LINE__, __func__})
  26 +#define CURRENT_FILE_INFO (::hueplusplus::FileInfo{__FILE__, __LINE__, __func__})
27 27 #endif
28 28 \ No newline at end of file
... ...
include/hueplusplus/HueLight.h
... ... @@ -32,61 +32,63 @@
32 32  
33 33 #include "json/json.hpp"
34 34  
35   -/*enum ModelType
  35 +namespace hueplusplus
36 36 {
37   -UNDEFINED, // undefined model
38   -LCT001, // Hue bulb A19, Color Gamut B, ECL
39   -LCT007, // Hue bulb A19, Color Gamut B, ECL
40   -LCT010, // Hue bulb A19, Color Gamut C, ECL
41   -LCT014, // Hue bulb A19, Color Gamut C, ECL
42   -
43   -LCT002, // Hue Spot BR30, Color Gamut B, ECL
44   -LCT003, // Hue Spot GU10, Color Gamut B, ECL
45   -
46   -LCT011, // Hue BR30, Color Gamut C, ECL
47   -
48   -LST001, // Hue LightStrips, Color Gamut A, CL
49   -LST002, // Hue LightStrips Plus, Color Gamut C, ECL
50   -
51   -LLC010, // Hue Living Colors Iris, Color Gamut A, CL
52   -LLC011, // Hue Living Colors Bloom, Color Gamut A, CL
53   -LLC012, // Hue Living Colors Bloom, Color Gamut A, CL
54   -LLC006, // Living Colors Gen3 Iris, Color Gamut A, CL, NO HUE FRIEND
55   -LLC007, // Living Colors Gen3 Bloom, Aura, Color Gamut A, CL, NO HUE FRIEND
56   -LLC013, // Disney Living Colors, Color Gamut A, CL
57   -
58   -LWB004, // Hue A19 Lux, Color Gamut -, DL
59   -LWB006, // Hue A19 Lux, Color Gamut -, DL
60   -LWB007, // Hue A19 Lux, Color Gamut -, DL
61   -LWB010, // Hue A19 Lux, Color Gamut -, DL
62   -LWB014, // Hue A19 Lux, Color Gamut -, DL
63   -
64   -LLM001, // Color Light Module, Color Gamut B, ECL
65   -LLM010, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
66   -LLM011, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
67   -LLM012, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
68   -
69   -LTW001, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
70   -LTW004, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
71   -LTW013, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
72   -LTW014, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
73   -
74   -LLC020 // Hue Go, Color Gamut C, ECL
75   -};*/
76   -
77   -//! enum that specifies the color type of all HueLights
78   -enum ColorType
79   -{
80   - UNDEFINED, //!< ColorType for this light is unknown or undefined
81   - NONE, //!< light has no specific ColorType
82   - GAMUT_A,
83   - GAMUT_B,
84   - GAMUT_C,
85   - TEMPERATURE,
86   - GAMUT_A_TEMPERATURE,
87   - GAMUT_B_TEMPERATURE,
88   - GAMUT_C_TEMPERATURE
89   -};
  37 + /*enum ModelType
  38 + {
  39 + UNDEFINED, // undefined model
  40 + LCT001, // Hue bulb A19, Color Gamut B, ECL
  41 + LCT007, // Hue bulb A19, Color Gamut B, ECL
  42 + LCT010, // Hue bulb A19, Color Gamut C, ECL
  43 + LCT014, // Hue bulb A19, Color Gamut C, ECL
  44 +
  45 + LCT002, // Hue Spot BR30, Color Gamut B, ECL
  46 + LCT003, // Hue Spot GU10, Color Gamut B, ECL
  47 +
  48 + LCT011, // Hue BR30, Color Gamut C, ECL
  49 +
  50 + LST001, // Hue LightStrips, Color Gamut A, CL
  51 + LST002, // Hue LightStrips Plus, Color Gamut C, ECL
  52 +
  53 + LLC010, // Hue Living Colors Iris, Color Gamut A, CL
  54 + LLC011, // Hue Living Colors Bloom, Color Gamut A, CL
  55 + LLC012, // Hue Living Colors Bloom, Color Gamut A, CL
  56 + LLC006, // Living Colors Gen3 Iris, Color Gamut A, CL, NO HUE FRIEND
  57 + LLC007, // Living Colors Gen3 Bloom, Aura, Color Gamut A, CL, NO HUE FRIEND
  58 + LLC013, // Disney Living Colors, Color Gamut A, CL
  59 +
  60 + LWB004, // Hue A19 Lux, Color Gamut -, DL
  61 + LWB006, // Hue A19 Lux, Color Gamut -, DL
  62 + LWB007, // Hue A19 Lux, Color Gamut -, DL
  63 + LWB010, // Hue A19 Lux, Color Gamut -, DL
  64 + LWB014, // Hue A19 Lux, Color Gamut -, DL
  65 +
  66 + LLM001, // Color Light Module, Color Gamut B, ECL
  67 + LLM010, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
  68 + LLM011, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
  69 + LLM012, // Color Temperature Module, Color Gamut 2200K-6500K, CTL
  70 +
  71 + LTW001, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
  72 + LTW004, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
  73 + LTW013, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
  74 + LTW014, // Hue Spot BR30, Color Gamut 2200K-6500K, CTL
  75 +
  76 + LLC020 // Hue Go, Color Gamut C, ECL
  77 + };*/
  78 +
  79 + //! enum that specifies the color type of all HueLights
  80 + enum ColorType
  81 + {
  82 + UNDEFINED, //!< ColorType for this light is unknown or undefined
  83 + NONE, //!< light has no specific ColorType
  84 + GAMUT_A,
  85 + GAMUT_B,
  86 + GAMUT_C,
  87 + TEMPERATURE,
  88 + GAMUT_A_TEMPERATURE,
  89 + GAMUT_B_TEMPERATURE,
  90 + GAMUT_C_TEMPERATURE
  91 + };
90 92  
91 93 //!
92 94 //! Class for Hue Light fixtures
... ... @@ -101,690 +103,692 @@ class HueLight
101 103 friend class SimpleColorTemperatureStrategy;
102 104 friend class ExtendedColorTemperatureStrategy;
103 105  
104   -public:
105   - //! \brief std dtor
106   - ~HueLight() = default;
107   -
108   - //! \brief Function that turns the light on.
109   - //!
110   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
111   - //! \return true on success
112   - //! \throws std::system_error when system or socket operations fail
113   - //! \throws HueException when response contained no body
114   - //! \throws HueAPIResponseException when response contains an error
115   - //! \throws nlohmann::json::parse_error when response could not be parsed
116   - virtual bool On(uint8_t transition = 4);
117   -
118   - //! \brief Function that turns the light off.
119   - //!
120   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
121   - //! \return Bool that is true on success
122   - //! \throws std::system_error when system or socket operations fail
123   - //! \throws HueException when response contained no body
124   - //! \throws HueAPIResponseException when response contains an error
125   - //! \throws nlohmann::json::parse_error when response could not be parsed
126   - virtual bool Off(uint8_t transition = 4);
127   -
128   - //! \brief Function to check whether a light is on or off
129   - //!
130   - //! \return Bool that is true, when the light is on and false, when off
131   - //! \throws std::system_error when system or socket operations fail
132   - //! \throws HueException when response contained no body
133   - //! \throws HueAPIResponseException when response contains an error
134   - //! \throws nlohmann::json::parse_error when response could not be parsed
135   - virtual bool isOn();
136   -
137   - //! \brief Const function to check whether a light is on or off
138   - //!
139   - //! \note This will not refresh the light state
140   - //! \return Bool that is true, when the light is on and false, when off
141   - virtual bool isOn() const;
142   -
143   - //! \brief Const function that returns the id of this light
144   - //!
145   - //! \return integer representing the light id
146   - virtual int getId() const;
147   -
148   - //! \brief Const function that returns the light type
149   - //!
150   - //! \return String containing the type
151   - virtual std::string getType() const;
152   -
153   - //! \brief Function that returns the name of the light.
154   - //!
155   - //! \return String containig the name of the light
156   - //! \throws std::system_error when system or socket operations fail
157   - //! \throws HueException when response contained no body
158   - //! \throws HueAPIResponseException when response contains an error
159   - //! \throws nlohmann::json::parse_error when response could not be parsed
160   - virtual std::string getName();
161   -
162   - //! \brief Const function that returns the name of the light.
163   - //!
164   - //! \note This will not refresh the light state
165   - //! \return String containig the name of the light
166   - virtual std::string getName() const;
167   -
168   - //! \brief Const function that returns the modelid of the light
169   - //!
170   - //! \return String conatining the modelid
171   - virtual std::string getModelId() const;
172   -
173   - //! \brief Const function that returns the uniqueid of the light
174   - //!
175   - //! \note Only working on bridges with versions starting at 1.4
176   - //! \return String containing the uniqueid or an empty string when the function is not supported
177   - virtual std::string getUId() const;
178   -
179   - //! \brief Const function that returns the manufacturername of the light
180   - //!
181   - //! \note Only working on bridges with versions starting at 1.7
182   - //! \return String containing the manufacturername or an empty string when the function is not supported
183   - virtual std::string getManufacturername() const;
184   -
185   - //! \brief Const function that returns the productname of the light
186   - //!
187   - //! \note Only working on bridges with versions starting at 1.24
188   - //! \return String containing the productname or an empty string when the function is not supported
189   - virtual std::string getProductname() const;
190   -
191   - //! \brief Const function that returns the luminaireuniqueid of the light
192   - //!
193   - //! \note Only working on bridges with versions starting at 1.9
194   - //! \return String containing the luminaireuniqueid or an empty string when the function is not supported
195   - virtual std::string getLuminaireUId() const;
196   -
197   - //! \brief Function that returns the software version of the light
198   - //!
199   - //! \return String containing the software version
200   - //! \throws std::system_error when system or socket operations fail
201   - //! \throws HueException when response contained no body
202   - //! \throws HueAPIResponseException when response contains an error
203   - //! \throws nlohmann::json::parse_error when response could not be parsed
204   - virtual std::string getSwVersion();
205   -
206   - //! \brief Const function that returns the software version of the light
207   - //!
208   - //! \note This will not refresh the light state
209   - //! \return String containing the software version
210   - virtual std::string getSwVersion() const;
211   -
212   - //! \brief Function that sets the name of the light
213   - //!
214   - //! \return Bool that is true on success
215   - //! \throws std::system_error when system or socket operations fail
216   - //! \throws HueException when response contained no body
217   - //! \throws HueAPIResponseException when response contains an error
218   - //! \throws nlohmann::json::parse_error when response could not be parsed
219   - virtual bool setName(const std::string& name);
220   -
221   - //! \brief Const function that returns the color type of the light.
222   - //!
223   - //! \return ColorType containig the color type of the light
224   - virtual ColorType getColorType() const;
225   -
226   - //! \brief Const function to check whether this light has brightness control
227   - //!
228   - //! \return Bool that is true when the light has specified abilities and false
229   - //! when not
230   - virtual bool hasBrightnessControl() const { return brightnessStrategy != nullptr; };
231   -
232   - //! \brief Const function to check whether this light has color temperature
233   - //! control
234   - //!
235   - //! \return Bool that is true when the light has specified abilities and false
236   - //! when not
237   - virtual bool hasTemperatureControl() const { return colorTemperatureStrategy != nullptr; };
238   -
239   - //! \brief Connst function to check whether this light has full color control
240   - //!
241   - //! \return Bool that is true when the light has specified abilities and false
242   - //! when not
243   - virtual bool hasColorControl() const { return colorHueStrategy != nullptr; };
244   -
245   - //! \brief Const function that converts Kelvin to Mired.
246   - //!
247   - //! \param kelvin Unsigned integer value in Kelvin
248   - //! \return Unsigned integer value in Mired
249   - unsigned int KelvinToMired(unsigned int kelvin) const;
250   -
251   - //! \brief Const function that converts Mired to Kelvin.
252   - //!
253   - //! \param mired Unsigned integer value in Mired
254   - //! \return Unsigned integer value in Kelvin
255   - unsigned int MiredToKelvin(unsigned int mired) const;
256   -
257   - //! \brief Function that sets the brightness of this light.
258   - //!
259   - //! \note The brightness will only be set if the light has a reference to a
260   - //! specific \ref BrightnessStrategy. The brightness can range from 0 = off to
261   - //! 254 = fully lit.
262   - //! \param bri Unsigned int that specifies the brightness
263   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
264   - //! \return Bool that is true on success
265   - //! \throws std::system_error when system or socket operations fail
266   - //! \throws HueException when response contained no body
267   - //! \throws HueAPIResponseException when response contains an error
268   - //! \throws nlohmann::json::parse_error when response could not be parsed
269   - virtual bool setBrightness(unsigned int bri, uint8_t transition = 4)
270   - {
271   - if (brightnessStrategy)
  106 + public:
  107 + //! \brief std dtor
  108 + ~HueLight() = default;
  109 +
  110 + //! \brief Function that turns the light on.
  111 + //!
  112 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  113 + //! \return true on success
  114 + //! \throws std::system_error when system or socket operations fail
  115 + //! \throws HueException when response contained no body
  116 + //! \throws HueAPIResponseException when response contains an error
  117 + //! \throws nlohmann::json::parse_error when response could not be parsed
  118 + virtual bool On(uint8_t transition = 4);
  119 +
  120 + //! \brief Function that turns the light off.
  121 + //!
  122 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  123 + //! \return Bool that is true on success
  124 + //! \throws std::system_error when system or socket operations fail
  125 + //! \throws HueException when response contained no body
  126 + //! \throws HueAPIResponseException when response contains an error
  127 + //! \throws nlohmann::json::parse_error when response could not be parsed
  128 + virtual bool Off(uint8_t transition = 4);
  129 +
  130 + //! \brief Function to check whether a light is on or off
  131 + //!
  132 + //! \return Bool that is true, when the light is on and false, when off
  133 + //! \throws std::system_error when system or socket operations fail
  134 + //! \throws HueException when response contained no body
  135 + //! \throws HueAPIResponseException when response contains an error
  136 + //! \throws nlohmann::json::parse_error when response could not be parsed
  137 + virtual bool isOn();
  138 +
  139 + //! \brief Const function to check whether a light is on or off
  140 + //!
  141 + //! \note This will not refresh the light state
  142 + //! \return Bool that is true, when the light is on and false, when off
  143 + virtual bool isOn() const;
  144 +
  145 + //! \brief Const function that returns the id of this light
  146 + //!
  147 + //! \return integer representing the light id
  148 + virtual int getId() const;
  149 +
  150 + //! \brief Const function that returns the light type
  151 + //!
  152 + //! \return String containing the type
  153 + virtual std::string getType() const;
  154 +
  155 + //! \brief Function that returns the name of the light.
  156 + //!
  157 + //! \return String containig the name of the light
  158 + //! \throws std::system_error when system or socket operations fail
  159 + //! \throws HueException when response contained no body
  160 + //! \throws HueAPIResponseException when response contains an error
  161 + //! \throws nlohmann::json::parse_error when response could not be parsed
  162 + virtual std::string getName();
  163 +
  164 + //! \brief Const function that returns the name of the light.
  165 + //!
  166 + //! \note This will not refresh the light state
  167 + //! \return String containig the name of the light
  168 + virtual std::string getName() const;
  169 +
  170 + //! \brief Const function that returns the modelid of the light
  171 + //!
  172 + //! \return String conatining the modelid
  173 + virtual std::string getModelId() const;
  174 +
  175 + //! \brief Const function that returns the uniqueid of the light
  176 + //!
  177 + //! \note Only working on bridges with versions starting at 1.4
  178 + //! \return String containing the uniqueid or an empty string when the function is not supported
  179 + virtual std::string getUId() const;
  180 +
  181 + //! \brief Const function that returns the manufacturername of the light
  182 + //!
  183 + //! \note Only working on bridges with versions starting at 1.7
  184 + //! \return String containing the manufacturername or an empty string when the function is not supported
  185 + virtual std::string getManufacturername() const;
  186 +
  187 + //! \brief Const function that returns the productname of the light
  188 + //!
  189 + //! \note Only working on bridges with versions starting at 1.24
  190 + //! \return String containing the productname or an empty string when the function is not supported
  191 + virtual std::string getProductname() const;
  192 +
  193 + //! \brief Const function that returns the luminaireuniqueid of the light
  194 + //!
  195 + //! \note Only working on bridges with versions starting at 1.9
  196 + //! \return String containing the luminaireuniqueid or an empty string when the function is not supported
  197 + virtual std::string getLuminaireUId() const;
  198 +
  199 + //! \brief Function that returns the software version of the light
  200 + //!
  201 + //! \return String containing the software version
  202 + //! \throws std::system_error when system or socket operations fail
  203 + //! \throws HueException when response contained no body
  204 + //! \throws HueAPIResponseException when response contains an error
  205 + //! \throws nlohmann::json::parse_error when response could not be parsed
  206 + virtual std::string getSwVersion();
  207 +
  208 + //! \brief Const function that returns the software version of the light
  209 + //!
  210 + //! \note This will not refresh the light state
  211 + //! \return String containing the software version
  212 + virtual std::string getSwVersion() const;
  213 +
  214 + //! \brief Function that sets the name of the light
  215 + //!
  216 + //! \return Bool that is true on success
  217 + //! \throws std::system_error when system or socket operations fail
  218 + //! \throws HueException when response contained no body
  219 + //! \throws HueAPIResponseException when response contains an error
  220 + //! \throws nlohmann::json::parse_error when response could not be parsed
  221 + virtual bool setName(const std::string& name);
  222 +
  223 + //! \brief Const function that returns the color type of the light.
  224 + //!
  225 + //! \return ColorType containig the color type of the light
  226 + virtual ColorType getColorType() const;
  227 +
  228 + //! \brief Const function to check whether this light has brightness control
  229 + //!
  230 + //! \return Bool that is true when the light has specified abilities and false
  231 + //! when not
  232 + virtual bool hasBrightnessControl() const { return brightnessStrategy != nullptr; };
  233 +
  234 + //! \brief Const function to check whether this light has color temperature
  235 + //! control
  236 + //!
  237 + //! \return Bool that is true when the light has specified abilities and false
  238 + //! when not
  239 + virtual bool hasTemperatureControl() const { return colorTemperatureStrategy != nullptr; };
  240 +
  241 + //! \brief Connst function to check whether this light has full color control
  242 + //!
  243 + //! \return Bool that is true when the light has specified abilities and false
  244 + //! when not
  245 + virtual bool hasColorControl() const { return colorHueStrategy != nullptr; };
  246 +
  247 + //! \brief Const function that converts Kelvin to Mired.
  248 + //!
  249 + //! \param kelvin Unsigned integer value in Kelvin
  250 + //! \return Unsigned integer value in Mired
  251 + unsigned int KelvinToMired(unsigned int kelvin) const;
  252 +
  253 + //! \brief Const function that converts Mired to Kelvin.
  254 + //!
  255 + //! \param mired Unsigned integer value in Mired
  256 + //! \return Unsigned integer value in Kelvin
  257 + unsigned int MiredToKelvin(unsigned int mired) const;
  258 +
  259 + //! \brief Function that sets the brightness of this light.
  260 + //!
  261 + //! \note The brightness will only be set if the light has a reference to a
  262 + //! specific \ref BrightnessStrategy. The brightness can range from 0 = off to
  263 + //! 254 = fully lit.
  264 + //! \param bri Unsigned int that specifies the brightness
  265 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  266 + //! \return Bool that is true on success
  267 + //! \throws std::system_error when system or socket operations fail
  268 + //! \throws HueException when response contained no body
  269 + //! \throws HueAPIResponseException when response contains an error
  270 + //! \throws nlohmann::json::parse_error when response could not be parsed
  271 + virtual bool setBrightness(unsigned int bri, uint8_t transition = 4)
272 272 {
273   - return brightnessStrategy->setBrightness(bri, transition, *this);
274   - }
275   - return false;
276   - };
277   -
278   - //! \brief Const function that returns the brightness of this light.
279   - //!
280   - //! \note The brightness will only be returned if the light has a reference to
281   - //! a specific \ref BrightnessStrategy. \note This will not refresh the light
282   - //! state The brightness can range from 0 = off to 254 = fully lit. \return
283   - //! Unsigned int that is 0 when function failed
284   - virtual unsigned int getBrightness() const
285   - {
286   - if (brightnessStrategy)
  273 + if (brightnessStrategy)
  274 + {
  275 + return brightnessStrategy->setBrightness(bri, transition, *this);
  276 + }
  277 + return false;
  278 + };
  279 +
  280 + //! \brief Const function that returns the brightness of this light.
  281 + //!
  282 + //! \note The brightness will only be returned if the light has a reference to
  283 + //! a specific \ref BrightnessStrategy. \note This will not refresh the light
  284 + //! state The brightness can range from 0 = off to 254 = fully lit. \return
  285 + //! Unsigned int that is 0 when function failed
  286 + virtual unsigned int getBrightness() const
287 287 {
288   - return brightnessStrategy->getBrightness(*this);
289   - }
290   - return 0;
291   - };
292   -
293   - //! \brief Function that returns the brightness of this light.
294   - //!
295   - //! \note The brightness will only be returned if the light has a reference to
296   - //! a specific \ref BrightnessStrategy. The brightness can range from 0 = off
297   - //! to 254 = fully lit.
298   - //! \return Unsigned int that is 0 when function failed
299   - //! \throws std::system_error when system or socket operations fail
300   - //! \throws HueException when response contained no body
301   - //! \throws HueAPIResponseException when response contains an error
302   - //! \throws nlohmann::json::parse_error when response could not be parsed
303   - virtual unsigned int getBrightness()
304   - {
305   - if (brightnessStrategy)
  288 + if (brightnessStrategy)
  289 + {
  290 + return brightnessStrategy->getBrightness(*this);
  291 + }
  292 + return 0;
  293 + };
  294 +
  295 + //! \brief Function that returns the brightness of this light.
  296 + //!
  297 + //! \note The brightness will only be returned if the light has a reference to
  298 + //! a specific \ref BrightnessStrategy. The brightness can range from 0 = off
  299 + //! to 254 = fully lit.
  300 + //! \return Unsigned int that is 0 when function failed
  301 + //! \throws std::system_error when system or socket operations fail
  302 + //! \throws HueException when response contained no body
  303 + //! \throws HueAPIResponseException when response contains an error
  304 + //! \throws nlohmann::json::parse_error when response could not be parsed
  305 + virtual unsigned int getBrightness()
306 306 {
307   - return brightnessStrategy->getBrightness(*this);
308   - }
309   - return 0;
310   - };
311   -
312   - //! \brief Fucntion that sets the color temperature of this light in mired.
313   - //!
314   - //! \note The color temperature will only be set if the light has a reference
315   - //! to a specific \ref ColorTemperatureStrategy. The color temperature can
316   - //! range from 153 to 500.
317   - //! \param mired Unsigned int that specifies the color temperature in Mired
318   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
319   - //! \return Bool that is true on success
320   - //! \throws std::system_error when system or socket operations fail
321   - //! \throws HueException when response contained no body
322   - //! \throws HueAPIResponseException when response contains an error
323   - //! \throws nlohmann::json::parse_error when response could not be parsed
324   - virtual bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
325   - {
326   - if (colorTemperatureStrategy)
  307 + if (brightnessStrategy)
  308 + {
  309 + return brightnessStrategy->getBrightness(*this);
  310 + }
  311 + return 0;
  312 + };
  313 +
  314 + //! \brief Fucntion that sets the color temperature of this light in mired.
  315 + //!
  316 + //! \note The color temperature will only be set if the light has a reference
  317 + //! to a specific \ref ColorTemperatureStrategy. The color temperature can
  318 + //! range from 153 to 500.
  319 + //! \param mired Unsigned int that specifies the color temperature in Mired
  320 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  321 + //! \return Bool that is true on success
  322 + //! \throws std::system_error when system or socket operations fail
  323 + //! \throws HueException when response contained no body
  324 + //! \throws HueAPIResponseException when response contains an error
  325 + //! \throws nlohmann::json::parse_error when response could not be parsed
  326 + virtual bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
327 327 {
328   - return colorTemperatureStrategy->setColorTemperature(mired, transition, *this);
329   - }
330   - return false;
331   - };
332   -
333   - //! \brief Const function that returns the current color temperature of the
334   - //! light
335   - //!
336   - //! \note The color temperature will only be returned when the light has a
337   - //! reference to a specific \ref ColorTemperatureStrategy.
338   - //! \note This will not refresh the light state
339   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
340   - //! and 500 is warm.
341   - //! \return Unsigned int representing the color temperature in mired or 0 when failed
342   - virtual unsigned int getColorTemperature() const
343   - {
344   - if (colorTemperatureStrategy)
  328 + if (colorTemperatureStrategy)
  329 + {
  330 + return colorTemperatureStrategy->setColorTemperature(mired, transition, *this);
  331 + }
  332 + return false;
  333 + };
  334 +
  335 + //! \brief Const function that returns the current color temperature of the
  336 + //! light
  337 + //!
  338 + //! \note The color temperature will only be returned when the light has a
  339 + //! reference to a specific \ref ColorTemperatureStrategy.
  340 + //! \note This will not refresh the light state
  341 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  342 + //! and 500 is warm.
  343 + //! \return Unsigned int representing the color temperature in mired or 0 when failed
  344 + virtual unsigned int getColorTemperature() const
345 345 {
346   - return colorTemperatureStrategy->getColorTemperature(*this);
347   - }
348   - return 0;
349   - };
350   -
351   - //! \brief Function that returns the current color temperature of the light
352   - //!
353   - //! \note The color temperature will only be returned when the light has a
354   - //! reference to a specific \ref ColorTemperatureStrategy.
355   - //! Updates the lights state by calling refreshState()
356   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
357   - //! and 500 is warm.
358   - //! \return Unsigned int representing the color temperature in mired or 0 when failed
359   - //! \throws std::system_error when system or socket operations fail
360   - //! \throws HueException when response contained no body
361   - //! \throws HueAPIResponseException when response contains an error
362   - //! \throws nlohmann::json::parse_error when response could not be parsed
363   - virtual unsigned int getColorTemperature()
364   - {
365   - if (colorTemperatureStrategy)
  346 + if (colorTemperatureStrategy)
  347 + {
  348 + return colorTemperatureStrategy->getColorTemperature(*this);
  349 + }
  350 + return 0;
  351 + };
  352 +
  353 + //! \brief Function that returns the current color temperature of the light
  354 + //!
  355 + //! \note The color temperature will only be returned when the light has a
  356 + //! reference to a specific \ref ColorTemperatureStrategy.
  357 + //! Updates the lights state by calling refreshState()
  358 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  359 + //! and 500 is warm.
  360 + //! \return Unsigned int representing the color temperature in mired or 0 when failed
  361 + //! \throws std::system_error when system or socket operations fail
  362 + //! \throws HueException when response contained no body
  363 + //! \throws HueAPIResponseException when response contains an error
  364 + //! \throws nlohmann::json::parse_error when response could not be parsed
  365 + virtual unsigned int getColorTemperature()
366 366 {
367   - return colorTemperatureStrategy->getColorTemperature(*this);
368   - }
369   - return 0;
370   - };
371   -
372   - //! \brief Function to set the color of this light with specified hue.
373   - //!
374   - //! \note The color will only be set if the light has a reference to a
375   - //! specific \ref ColorHueStrategy. The hue can range from 0 to 65535, whereas
376   - //! 65535 and 0 are red, 25500 is green and 46920 is blue.
377   - //! \param hue uint16_t that specifies the hue
378   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
379   - //! \return Bool that is true on success
380   - //! \throws std::system_error when system or socket operations fail
381   - //! \throws HueException when response contained no body
382   - //! \throws HueAPIResponseException when response contains an error
383   - //! \throws nlohmann::json::parse_error when response could not be parsed
384   - virtual bool setColorHue(uint16_t hue, uint8_t transition = 4)
385   - {
386   - if (colorHueStrategy)
  367 + if (colorTemperatureStrategy)
  368 + {
  369 + return colorTemperatureStrategy->getColorTemperature(*this);
  370 + }
  371 + return 0;
  372 + };
  373 +
  374 + //! \brief Function to set the color of this light with specified hue.
  375 + //!
  376 + //! \note The color will only be set if the light has a reference to a
  377 + //! specific \ref ColorHueStrategy. The hue can range from 0 to 65535, whereas
  378 + //! 65535 and 0 are red, 25500 is green and 46920 is blue.
  379 + //! \param hue uint16_t that specifies the hue
  380 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  381 + //! \return Bool that is true on success
  382 + //! \throws std::system_error when system or socket operations fail
  383 + //! \throws HueException when response contained no body
  384 + //! \throws HueAPIResponseException when response contains an error
  385 + //! \throws nlohmann::json::parse_error when response could not be parsed
  386 + virtual bool setColorHue(uint16_t hue, uint8_t transition = 4)
387 387 {
388   - return colorHueStrategy->setColorHue(hue, transition, *this);
389   - }
390   - return false;
391   - };
392   -
393   - //! \brief Function to set the color of this light with specified saturation.
394   - //!
395   - //! \note The color will only be set if the light has a reference to a
396   - //! specific \ref ColorHueStrategy. The saturation can range from 0 to 254,
397   - //! whereas 0 is least saturated (white) and 254 is most saturated.
398   - //! \param sat uint8_t that specifies the saturation
399   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
400   - //! \return Bool that is true on success
401   - //! \throws std::system_error when system or socket operations fail
402   - //! \throws HueException when response contained no body
403   - //! \throws HueAPIResponseException when response contains an error
404   - //! \throws nlohmann::json::parse_error when response could not be parsed
405   - virtual bool setColorSaturation(uint8_t sat, uint8_t transition = 4)
406   - {
407   - if (colorHueStrategy)
  388 + if (colorHueStrategy)
  389 + {
  390 + return colorHueStrategy->setColorHue(hue, transition, *this);
  391 + }
  392 + return false;
  393 + };
  394 +
  395 + //! \brief Function to set the color of this light with specified saturation.
  396 + //!
  397 + //! \note The color will only be set if the light has a reference to a
  398 + //! specific \ref ColorHueStrategy. The saturation can range from 0 to 254,
  399 + //! whereas 0 is least saturated (white) and 254 is most saturated.
  400 + //! \param sat uint8_t that specifies the saturation
  401 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  402 + //! \return Bool that is true on success
  403 + //! \throws std::system_error when system or socket operations fail
  404 + //! \throws HueException when response contained no body
  405 + //! \throws HueAPIResponseException when response contains an error
  406 + //! \throws nlohmann::json::parse_error when response could not be parsed
  407 + virtual bool setColorSaturation(uint8_t sat, uint8_t transition = 4)
408 408 {
409   - return colorHueStrategy->setColorSaturation(sat, transition, *this);
410   - }
411   - return false;
412   - };
413   -
414   - //! \brief Function to set the color of this light with specified hue and
415   - //! saturation.
416   - //!
417   - //! \note The color will only be set if the light has a reference to a
418   - //! specific \ref ColorHueStrategy.
419   - //! \param hue uint16_t that specifies the hue
420   - //! \param sat uint8_t that specifies the saturation
421   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms.
422   - //! \return Bool that is true on success
423   - //! \throws std::system_error when system or socket operations fail
424   - //! \throws HueException when response contained no body
425   - //! \throws HueAPIResponseException when response contains an error
426   - //! \throws nlohmann::json::parse_error when response could not be parsed
427   - virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition = 4)
428   - {
429   - if (colorHueStrategy)
  409 + if (colorHueStrategy)
  410 + {
  411 + return colorHueStrategy->setColorSaturation(sat, transition, *this);
  412 + }
  413 + return false;
  414 + };
  415 +
  416 + //! \brief Function to set the color of this light with specified hue and
  417 + //! saturation.
  418 + //!
  419 + //! \note The color will only be set if the light has a reference to a
  420 + //! specific \ref ColorHueStrategy.
  421 + //! \param hue uint16_t that specifies the hue
  422 + //! \param sat uint8_t that specifies the saturation
  423 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms.
  424 + //! \return Bool that is true on success
  425 + //! \throws std::system_error when system or socket operations fail
  426 + //! \throws HueException when response contained no body
  427 + //! \throws HueAPIResponseException when response contains an error
  428 + //! \throws nlohmann::json::parse_error when response could not be parsed
  429 + virtual bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition = 4)
430 430 {
431   - return colorHueStrategy->setColorHueSaturation(hue, sat, transition, *this);
432   - }
433   - return false;
434   - };
435   -
436   - //! \brief Const function that returns the current color of the light as hue
437   - //! and saturation
438   - //!
439   - //! \note The color hue and saturation will only be returned when the light
440   - //! has a reference to a specific \ref ColorHueStrategy.
441   - //! \note This will not refresh the light state
442   - //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
443   - //! \throws std::system_error when system or socket operations fail
444   - //! \throws HueException when response contained no body
445   - //! \throws HueAPIResponseException when response contains an error
446   - //! \throws nlohmann::json::parse_error when response could not be parsed
447   - virtual std::pair<uint16_t, uint8_t> getColorHueSaturation() const
448   - {
449   - if (colorHueStrategy)
  431 + if (colorHueStrategy)
  432 + {
  433 + return colorHueStrategy->setColorHueSaturation(hue, sat, transition, *this);
  434 + }
  435 + return false;
  436 + };
  437 +
  438 + //! \brief Const function that returns the current color of the light as hue
  439 + //! and saturation
  440 + //!
  441 + //! \note The color hue and saturation will only be returned when the light
  442 + //! has a reference to a specific \ref ColorHueStrategy.
  443 + //! \note This will not refresh the light state
  444 + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
  445 + //! \throws std::system_error when system or socket operations fail
  446 + //! \throws HueException when response contained no body
  447 + //! \throws HueAPIResponseException when response contains an error
  448 + //! \throws nlohmann::json::parse_error when response could not be parsed
  449 + virtual std::pair<uint16_t, uint8_t> getColorHueSaturation() const
450 450 {
451   - return colorHueStrategy->getColorHueSaturation(*this);
452   - }
453   - return {};
454   - };
455   -
456   - //! \brief Function that returns the current color of the light as hue and
457   - //! saturation
458   - //!
459   - //! \note The color hue and saturation will only be returned when the light
460   - //! has a reference to a specific \ref ColorHueStrategy. Updates the lights
461   - //! state by calling refreshState()
462   - //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
463   - //! \throws std::system_error when system or socket operations fail
464   - //! \throws HueException when response contained no body
465   - //! \throws HueAPIResponseException when response contains an error
466   - //! \throws nlohmann::json::parse_error when response could not be parsed
467   - virtual std::pair<uint16_t, uint8_t> getColorHueSaturation()
468   - {
469   - if (colorHueStrategy)
  451 + if (colorHueStrategy)
  452 + {
  453 + return colorHueStrategy->getColorHueSaturation(*this);
  454 + }
  455 + return {};
  456 + };
  457 +
  458 + //! \brief Function that returns the current color of the light as hue and
  459 + //! saturation
  460 + //!
  461 + //! \note The color hue and saturation will only be returned when the light
  462 + //! has a reference to a specific \ref ColorHueStrategy. Updates the lights
  463 + //! state by calling refreshState()
  464 + //! \return Pair containing the hue as first value and saturation as second value or an empty one when failed
  465 + //! \throws std::system_error when system or socket operations fail
  466 + //! \throws HueException when response contained no body
  467 + //! \throws HueAPIResponseException when response contains an error
  468 + //! \throws nlohmann::json::parse_error when response could not be parsed
  469 + virtual std::pair<uint16_t, uint8_t> getColorHueSaturation()
470 470 {
471   - return colorHueStrategy->getColorHueSaturation(*this);
472   - }
473   - return {};
474   - };
475   -
476   - //! \brief Function to set the color of this light in CIE with specified x y.
477   - //!
478   - //! \note The color will only be set if the light has a reference to a
479   - //! specific \ref ColorHueStrategy. The values of x and y are ranging from 0 to 1.
480   - //! \param x float that specifies the x coordinate in CIE
481   - //! \param y float that specifies the y coordinate in CIE
482   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
483   - //! \return Bool that is true on success
484   - //! \throws std::system_error when system or socket operations fail
485   - //! \throws HueException when response contained no body
486   - //! \throws HueAPIResponseException when response contains an error
487   - //! \throws nlohmann::json::parse_error when response could not be parsed
488   - virtual bool setColorXY(float x, float y, uint8_t transition = 4)
489   - {
490   - if (colorHueStrategy)
  471 + if (colorHueStrategy)
  472 + {
  473 + return colorHueStrategy->getColorHueSaturation(*this);
  474 + }
  475 + return {};
  476 + };
  477 +
  478 + //! \brief Function to set the color of this light in CIE with specified x y.
  479 + //!
  480 + //! \note The color will only be set if the light has a reference to a
  481 + //! specific \ref ColorHueStrategy. The values of x and y are ranging from 0 to 1.
  482 + //! \param x float that specifies the x coordinate in CIE
  483 + //! \param y float that specifies the y coordinate in CIE
  484 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  485 + //! \return Bool that is true on success
  486 + //! \throws std::system_error when system or socket operations fail
  487 + //! \throws HueException when response contained no body
  488 + //! \throws HueAPIResponseException when response contains an error
  489 + //! \throws nlohmann::json::parse_error when response could not be parsed
  490 + virtual bool setColorXY(float x, float y, uint8_t transition = 4)
491 491 {
492   - return colorHueStrategy->setColorXY(x, y, transition, *this);
493   - }
494   - return false;
495   - };
496   -
497   - //! \brief Const function that returns the current color of the light as xy
498   - //!
499   - //! \note The color x and y will only be returned when the light has a
500   - //! reference to a specific \ref ColorHueStrategy.
501   - //! \note This does not update the lights state
502   - //! \return Pair containing the x as first value and y as second value or an
503   - //! empty one when failed
504   - virtual std::pair<float, float> getColorXY() const
505   - {
506   - if (colorHueStrategy)
  492 + if (colorHueStrategy)
  493 + {
  494 + return colorHueStrategy->setColorXY(x, y, transition, *this);
  495 + }
  496 + return false;
  497 + };
  498 +
  499 + //! \brief Const function that returns the current color of the light as xy
  500 + //!
  501 + //! \note The color x and y will only be returned when the light has a
  502 + //! reference to a specific \ref ColorHueStrategy.
  503 + //! \note This does not update the lights state
  504 + //! \return Pair containing the x as first value and y as second value or an
  505 + //! empty one when failed
  506 + virtual std::pair<float, float> getColorXY() const
507 507 {
508   - return colorHueStrategy->getColorXY(*this);
509   - }
510   - return {};
511   - };
512   -
513   - //! \brief Function that returns the current color of the light as xy
514   - //!
515   - //! \note The color x and y will only be returned when the light has a
516   - //! reference to a specific \ref ColorHueStrategy.
517   - //! Updates the lights state by calling refreshState()
518   - //! \return Pair containing the x as first value and y as second value or an empty one when failed
519   - //! \throws std::system_error when system or socket operations fail
520   - //! \throws HueException when response contained no body
521   - //! \throws HueAPIResponseException when response contains an error
522   - //! \throws nlohmann::json::parse_error when response could not be parsed
523   - virtual std::pair<float, float> getColorXY()
524   - {
525   - if (colorHueStrategy)
  508 + if (colorHueStrategy)
  509 + {
  510 + return colorHueStrategy->getColorXY(*this);
  511 + }
  512 + return {};
  513 + };
  514 +
  515 + //! \brief Function that returns the current color of the light as xy
  516 + //!
  517 + //! \note The color x and y will only be returned when the light has a
  518 + //! reference to a specific \ref ColorHueStrategy.
  519 + //! Updates the lights state by calling refreshState()
  520 + //! \return Pair containing the x as first value and y as second value or an empty one when failed
  521 + //! \throws std::system_error when system or socket operations fail
  522 + //! \throws HueException when response contained no body
  523 + //! \throws HueAPIResponseException when response contains an error
  524 + //! \throws nlohmann::json::parse_error when response could not be parsed
  525 + virtual std::pair<float, float> getColorXY()
526 526 {
527   - return colorHueStrategy->getColorXY(*this);
528   - }
529   - return {};
530   - };
531   -
532   - //! \brief Function to set the color of this light with red green and blue
533   - //! values.
534   - //!
535   - //! \note The color will only be set if the light has a reference to a
536   - //! specific \ref ColorHueStrategy. The values of red, green and blue are
537   - //! ranging from 0 to 255.
538   - //! \param r uint8_t that specifies the red color value
539   - //! \param g uint8_t that specifies the green color value
540   - //! \param b uint8_t that specifies the blue color value
541   - //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
542   - //! \return Bool that is true on success
543   - //! \throws std::system_error when system or socket operations fail
544   - //! \throws HueException when response contained no body
545   - //! \throws HueAPIResponseException when response contains an error
546   - //! \throws nlohmann::json::parse_error when response could not be parsed
547   - virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition = 4)
548   - {
549   - if (colorHueStrategy)
  527 + if (colorHueStrategy)
  528 + {
  529 + return colorHueStrategy->getColorXY(*this);
  530 + }
  531 + return {};
  532 + };
  533 +
  534 + //! \brief Function to set the color of this light with red green and blue
  535 + //! values.
  536 + //!
  537 + //! \note The color will only be set if the light has a reference to a
  538 + //! specific \ref ColorHueStrategy. The values of red, green and blue are
  539 + //! ranging from 0 to 255.
  540 + //! \param r uint8_t that specifies the red color value
  541 + //! \param g uint8_t that specifies the green color value
  542 + //! \param b uint8_t that specifies the blue color value
  543 + //! \param transition Optional parameter to set the transition from current state to new, standard is 4 = 400ms
  544 + //! \return Bool that is true on success
  545 + //! \throws std::system_error when system or socket operations fail
  546 + //! \throws HueException when response contained no body
  547 + //! \throws HueAPIResponseException when response contains an error
  548 + //! \throws nlohmann::json::parse_error when response could not be parsed
  549 + virtual bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition = 4)
550 550 {
551   - return colorHueStrategy->setColorRGB(r, g, b, transition, *this);
552   - }
553   - return false;
554   - };
555   -
556   - //! \brief Function that lets the light perform one breath cycle.
557   - //!
558   - //! Can be used for locating a light.
559   - //! \return bool that is true on success
560   - //! \throws std::system_error when system or socket operations fail
561   - //! \throws HueException when response contained no body
562   - //! \throws HueAPIResponseException when response contains an error
563   - //! \throws nlohmann::json::parse_error when response could not be parsed
564   - virtual bool alert();
565   -
566   - //! \brief Function that lets the light perform one breath cycle in specified
567   - //! color temperature.
568   - //!
569   - //! \note The breath cylce will only be performed if the light has a reference
570   - //! to a specific \ref ColorTemperatureStrategy.
571   - //! \param mired Color temperature in mired
572   - //! \return Bool that is true on success
573   - //! \throws std::system_error when system or socket operations fail
574   - //! \throws HueException when response contained no body
575   - //! \throws HueAPIResponseException when response contains an error
576   - //! \throws nlohmann::json::parse_error when response could not be parsed
577   - virtual bool alertTemperature(unsigned int mired)
578   - {
579   - if (colorTemperatureStrategy)
  551 + if (colorHueStrategy)
  552 + {
  553 + return colorHueStrategy->setColorRGB(r, g, b, transition, *this);
  554 + }
  555 + return false;
  556 + };
  557 +
  558 + //! \brief Function that lets the light perform one breath cycle.
  559 + //!
  560 + //! Can be used for locating a light.
  561 + //! \return bool that is true on success
  562 + //! \throws std::system_error when system or socket operations fail
  563 + //! \throws HueException when response contained no body
  564 + //! \throws HueAPIResponseException when response contains an error
  565 + //! \throws nlohmann::json::parse_error when response could not be parsed
  566 + virtual bool alert();
  567 +
  568 + //! \brief Function that lets the light perform one breath cycle in specified
  569 + //! color temperature.
  570 + //!
  571 + //! \note The breath cylce will only be performed if the light has a reference
  572 + //! to a specific \ref ColorTemperatureStrategy.
  573 + //! \param mired Color temperature in mired
  574 + //! \return Bool that is true on success
  575 + //! \throws std::system_error when system or socket operations fail
  576 + //! \throws HueException when response contained no body
  577 + //! \throws HueAPIResponseException when response contains an error
  578 + //! \throws nlohmann::json::parse_error when response could not be parsed
  579 + virtual bool alertTemperature(unsigned int mired)
580 580 {
581   - return colorTemperatureStrategy->alertTemperature(mired, *this);
582   - }
583   - return false;
584   - };
585   -
586   - //! \brief Function that lets the light perform one breath cycle in specified
587   - //! color.
588   - //!
589   - //! \note The breath cylce will only be performed if the light has a reference
590   - //! to a specific \ref ColorHueStrategy.
591   - //! \param hue uint16_t that specifies the hue
592   - //! \param sat uint8_t that specifies the saturation
593   - //! \return Bool that is true on success
594   - //! \throws std::system_error when system or socket operations fail
595   - //! \throws HueException when response contained no body
596   - //! \throws HueAPIResponseException when response contains an error
597   - //! \throws nlohmann::json::parse_error when response could not be parsed
598   - virtual bool alertHueSaturation(uint16_t hue, uint8_t sat)
599   - {
600   - if (colorHueStrategy)
  581 + if (colorTemperatureStrategy)
  582 + {
  583 + return colorTemperatureStrategy->alertTemperature(mired, *this);
  584 + }
  585 + return false;
  586 + };
  587 +
  588 + //! \brief Function that lets the light perform one breath cycle in specified
  589 + //! color.
  590 + //!
  591 + //! \note The breath cylce will only be performed if the light has a reference
  592 + //! to a specific \ref ColorHueStrategy.
  593 + //! \param hue uint16_t that specifies the hue
  594 + //! \param sat uint8_t that specifies the saturation
  595 + //! \return Bool that is true on success
  596 + //! \throws std::system_error when system or socket operations fail
  597 + //! \throws HueException when response contained no body
  598 + //! \throws HueAPIResponseException when response contains an error
  599 + //! \throws nlohmann::json::parse_error when response could not be parsed
  600 + virtual bool alertHueSaturation(uint16_t hue, uint8_t sat)
601 601 {
602   - return colorHueStrategy->alertHueSaturation(hue, sat, *this);
603   - }
604   - return false;
605   - };
606   -
607   - //! \brief Function that lets the light perform one breath cycle in specified
608   - //! color.
609   - //!
610   - //! \note The breath cylce will only be performed if the light has a reference
611   - //! to a specific \ref ColorHueStrategy. The values of x and y are ranging
612   - //! from 0 to 1.
613   - //! \param x float that specifies the x coordinate in CIE
614   - //! \param y float that specifies the y coordinate in CIE
615   - //! \return Bool that is true on success
616   - //! \throws std::system_error when system or socket operations fail
617   - //! \throws HueException when response contained no body
618   - //! \throws HueAPIResponseException when response contains an error
619   - //! \throws nlohmann::json::parse_error when response could not be parsed
620   - virtual bool alertXY(float x, float y)
621   - {
622   - if (colorHueStrategy)
  602 + if (colorHueStrategy)
  603 + {
  604 + return colorHueStrategy->alertHueSaturation(hue, sat, *this);
  605 + }
  606 + return false;
  607 + };
  608 +
  609 + //! \brief Function that lets the light perform one breath cycle in specified
  610 + //! color.
  611 + //!
  612 + //! \note The breath cylce will only be performed if the light has a reference
  613 + //! to a specific \ref ColorHueStrategy. The values of x and y are ranging
  614 + //! from 0 to 1.
  615 + //! \param x float that specifies the x coordinate in CIE
  616 + //! \param y float that specifies the y coordinate in CIE
  617 + //! \return Bool that is true on success
  618 + //! \throws std::system_error when system or socket operations fail
  619 + //! \throws HueException when response contained no body
  620 + //! \throws HueAPIResponseException when response contains an error
  621 + //! \throws nlohmann::json::parse_error when response could not be parsed
  622 + virtual bool alertXY(float x, float y)
623 623 {
624   - return colorHueStrategy->alertXY(x, y, *this);
625   - }
626   - return false;
627   - };
628   -
629   - //! \brief Function that lets the light perform one breath cycle in specified
630   - //! color.
631   - //!
632   - //! \note The breath cylce will only be performed if the light has a reference
633   - //! to a specific \ref ColorHueStrategy. The values of red, green and blue are
634   - //! ranging from 0 to 255.
635   - //! \param r uint8_t that specifies the red color value
636   - //! \param g uint8_t that specifies the green color value
637   - //! \param b uint8_t that specifies the blue color value
638   - //! \return Bool that is true on success
639   - //! \throws std::system_error when system or socket operations fail
640   - //! \throws HueException when response contained no body
641   - //! \throws HueAPIResponseException when response contains an error
642   - //! \throws nlohmann::json::parse_error when response could not be parsed
643   - virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b)
644   - {
645   - if (colorHueStrategy)
  624 + if (colorHueStrategy)
  625 + {
  626 + return colorHueStrategy->alertXY(x, y, *this);
  627 + }
  628 + return false;
  629 + };
  630 +
  631 + //! \brief Function that lets the light perform one breath cycle in specified
  632 + //! color.
  633 + //!
  634 + //! \note The breath cylce will only be performed if the light has a reference
  635 + //! to a specific \ref ColorHueStrategy. The values of red, green and blue are
  636 + //! ranging from 0 to 255.
  637 + //! \param r uint8_t that specifies the red color value
  638 + //! \param g uint8_t that specifies the green color value
  639 + //! \param b uint8_t that specifies the blue color value
  640 + //! \return Bool that is true on success
  641 + //! \throws std::system_error when system or socket operations fail
  642 + //! \throws HueException when response contained no body
  643 + //! \throws HueAPIResponseException when response contains an error
  644 + //! \throws nlohmann::json::parse_error when response could not be parsed
  645 + virtual bool alertRGB(uint8_t r, uint8_t g, uint8_t b)
646 646 {
647   - return colorHueStrategy->alertRGB(r, g, b, *this);
648   - }
649   - return false;
650   - };
651   -
652   - //! \brief Function to turn colorloop effect on/off.
653   - //!
654   - //! Notice this function will only be performed light has a reference to a
655   - //! specific \ref ColorHueStrategy. The colorloop effect will loop through all
656   - //! colors on current hue and saturation levels. Notice that none of the
657   - //! setter functions check whether this feature is enabled and the colorloop
658   - //! can only be disabled with this function or by simply calling
659   - //! Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
660   - //! alternatively call Off() and then use any of the setter functions.
661   - //! \param on bool that enables this feature when true and disables it when false
662   - //! \return Bool that is true on success
663   - //! \throws std::system_error when system or socket operations fail
664   - //! \throws HueException when response contained no body
665   - //! \throws HueAPIResponseException when response contains an error
666   - //! \throws nlohmann::json::parse_error when response could not be parsed
667   - virtual bool setColorLoop(bool on)
668   - {
669   - if (colorHueStrategy)
  647 + if (colorHueStrategy)
  648 + {
  649 + return colorHueStrategy->alertRGB(r, g, b, *this);
  650 + }
  651 + return false;
  652 + };
  653 +
  654 + //! \brief Function to turn colorloop effect on/off.
  655 + //!
  656 + //! Notice this function will only be performed light has a reference to a
  657 + //! specific \ref ColorHueStrategy. The colorloop effect will loop through all
  658 + //! colors on current hue and saturation levels. Notice that none of the
  659 + //! setter functions check whether this feature is enabled and the colorloop
  660 + //! can only be disabled with this function or by simply calling
  661 + //! Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
  662 + //! alternatively call Off() and then use any of the setter functions.
  663 + //! \param on bool that enables this feature when true and disables it when false
  664 + //! \return Bool that is true on success
  665 + //! \throws std::system_error when system or socket operations fail
  666 + //! \throws HueException when response contained no body
  667 + //! \throws HueAPIResponseException when response contains an error
  668 + //! \throws nlohmann::json::parse_error when response could not be parsed
  669 + virtual bool setColorLoop(bool on)
670 670 {
671   - return colorHueStrategy->setColorLoop(on, *this);
672   - }
673   - return false;
674   - };
675   -
676   -protected:
677   - //! \brief Protected ctor that is used by \ref Hue class.
678   - //!
679   - //! \param id Integer that specifies the id of this light
680   - //! \param commands HueCommandAPI for communication with the bridge
681   - //!
682   - //! leaves strategies unset
683   - HueLight(int id, const HueCommandAPI& commands);
684   -
685   - //! \brief Protected ctor that is used by \ref Hue class, also sets
686   - //! strategies.
687   - //!
688   - //! \param id Integer that specifies the id of this light
689   - //! \param commands HueCommandAPI for communication with the bridge
690   - //! \param brightnessStrategy Strategy for brightness. May be nullptr.
691   - //! \param colorTempStrategy Strategy for color temperature. May be nullptr.
692   - //! \param colorHueStrategy Strategy for color hue/saturation. May be nullptr.
693   - //! \throws std::system_error when system or socket operations fail
694   - //! \throws HueException when response contained no body
695   - //! \throws HueAPIResponseException when response contains an error
696   - //! \throws nlohmann::json::parse_error when response could not be parsed
697   - HueLight(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
698   - std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
699   - std::shared_ptr<const ColorHueStrategy> colorHueStrategy);
700   -
701   - //! \brief Protected function that sets the brightness strategy.
702   - //!
703   - //! The strategy defines how specific commands that deal with brightness
704   - //! control are executed \param strat a strategy of type \ref
705   - //! BrightnessStrategy
706   - virtual void setBrightnessStrategy(std::shared_ptr<const BrightnessStrategy> strat)
707   - {
708   - brightnessStrategy = std::move(strat);
709   - };
710   -
711   - //! \brief Protected function that sets the colorTemperature strategy.
712   - //!
713   - //! The strategy defines how specific commands that deal with colortemperature
714   - //! control are executed \param strat a strategy of type \ref
715   - //! ColorTemperatureStrategy
716   - virtual void setColorTemperatureStrategy(std::shared_ptr<const ColorTemperatureStrategy> strat)
717   - {
718   - colorTemperatureStrategy = std::move(strat);
719   - };
720   -
721   - //! \brief Protected function that sets the colorHue strategy.
722   - //!
723   - //! The strategy defines how specific commands that deal with color control
724   - //! are executed \param strat a strategy of type \ref ColorHueStrategy
725   - virtual void setColorHueStrategy(std::shared_ptr<const ColorHueStrategy> strat)
726   - {
727   - colorHueStrategy = std::move(strat);
  671 + if (colorHueStrategy)
  672 + {
  673 + return colorHueStrategy->setColorLoop(on, *this);
  674 + }
  675 + return false;
  676 + };
  677 +
  678 + protected:
  679 + //! \brief Protected ctor that is used by \ref Hue class.
  680 + //!
  681 + //! \param id Integer that specifies the id of this light
  682 + //! \param commands HueCommandAPI for communication with the bridge
  683 + //!
  684 + //! leaves strategies unset
  685 + HueLight(int id, const HueCommandAPI& commands);
  686 +
  687 + //! \brief Protected ctor that is used by \ref Hue class, also sets
  688 + //! strategies.
  689 + //!
  690 + //! \param id Integer that specifies the id of this light
  691 + //! \param commands HueCommandAPI for communication with the bridge
  692 + //! \param brightnessStrategy Strategy for brightness. May be nullptr.
  693 + //! \param colorTempStrategy Strategy for color temperature. May be nullptr.
  694 + //! \param colorHueStrategy Strategy for color hue/saturation. May be nullptr.
  695 + //! \throws std::system_error when system or socket operations fail
  696 + //! \throws HueException when response contained no body
  697 + //! \throws HueAPIResponseException when response contains an error
  698 + //! \throws nlohmann::json::parse_error when response could not be parsed
  699 + HueLight(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
  700 + std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
  701 + std::shared_ptr<const ColorHueStrategy> colorHueStrategy);
  702 +
  703 + //! \brief Protected function that sets the brightness strategy.
  704 + //!
  705 + //! The strategy defines how specific commands that deal with brightness
  706 + //! control are executed \param strat a strategy of type \ref
  707 + //! BrightnessStrategy
  708 + virtual void setBrightnessStrategy(std::shared_ptr<const BrightnessStrategy> strat)
  709 + {
  710 + brightnessStrategy = std::move(strat);
  711 + };
  712 +
  713 + //! \brief Protected function that sets the colorTemperature strategy.
  714 + //!
  715 + //! The strategy defines how specific commands that deal with colortemperature
  716 + //! control are executed \param strat a strategy of type \ref
  717 + //! ColorTemperatureStrategy
  718 + virtual void setColorTemperatureStrategy(std::shared_ptr<const ColorTemperatureStrategy> strat)
  719 + {
  720 + colorTemperatureStrategy = std::move(strat);
  721 + };
  722 +
  723 + //! \brief Protected function that sets the colorHue strategy.
  724 + //!
  725 + //! The strategy defines how specific commands that deal with color control
  726 + //! are executed \param strat a strategy of type \ref ColorHueStrategy
  727 + virtual void setColorHueStrategy(std::shared_ptr<const ColorHueStrategy> strat)
  728 + {
  729 + colorHueStrategy = std::move(strat);
  730 + };
  731 +
  732 + //! \brief Protected function that sets the HueCommandAPI.
  733 + //!
  734 + //! The HueCommandAPI is used for bridge communication
  735 + //! \param commandAPI the new HueCommandAPI
  736 + virtual void setCommandAPI(const HueCommandAPI& commandAPI) { commands = commandAPI; };
  737 +
  738 + //! \brief Function that turns the light on without refreshing its state.
  739 + //!
  740 + //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
  741 + //! \return Bool that is true on success
  742 + //! \throws std::system_error when system or socket operations fail
  743 + //! \throws HueException when response contained no body
  744 + //! \throws HueAPIResponseException when response contains an error
  745 + //! \throws nlohmann::json::parse_error when response could not be parsed
  746 + virtual bool OnNoRefresh(uint8_t transition = 4);
  747 +
  748 + //! \brief Function that turns the light off without refreshing its state.
  749 + //!
  750 + //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
  751 + //! \return Bool that is true on success
  752 + //! \throws std::system_error when system or socket operations fail
  753 + //! \throws HueException when response contained no body
  754 + //! \throws HueAPIResponseException when response contains an error
  755 + //! \throws nlohmann::json::parse_error when response could not be parsed
  756 + virtual bool OffNoRefresh(uint8_t transition = 4);
  757 +
  758 + //! \brief Utility function to send a put request to the light.
  759 + //!
  760 + //! \throws nlohmann::json::parse_error if the reply could not be parsed
  761 + //! \param request A nlohmann::json aka the request to send
  762 + //! \param subPath A path that is appended to the uri, note it should always start with a slash ("/")
  763 + //! \param fileInfo FileInfo from calling function for exception details.
  764 + //! \return The parsed reply
  765 + //! \throws std::system_error when system or socket operations fail
  766 + //! \throws HueException when response contained no body
  767 + //! \throws HueAPIResponseException when response contains an error
  768 + //! \throws nlohmann::json::parse_error when response could not be parsed
  769 + virtual nlohmann::json SendPutRequest(
  770 + const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo);
  771 +
  772 + //! \brief Virtual function that refreshes the \ref state of the light.
  773 + //! \throws std::system_error when system or socket operations fail
  774 + //! \throws HueException when response contained no body
  775 + //! \throws HueAPIResponseException when response contains an error
  776 + //! \throws nlohmann::json::parse_error when response could not be parsed
  777 + virtual void refreshState();
  778 +
  779 + protected:
  780 + int id; //!< holds the id of the light
  781 + nlohmann::json state; //!< holds the current state of the light updated by \ref refreshState
  782 + ColorType colorType; //!< holds the \ref ColorType of the light
  783 +
  784 + std::shared_ptr<const BrightnessStrategy>
  785 + brightnessStrategy; //!< holds a reference to the strategy that handles brightness commands
  786 + std::shared_ptr<const ColorTemperatureStrategy>
  787 + colorTemperatureStrategy; //!< holds a reference to the strategy that handles colortemperature commands
  788 + std::shared_ptr<const ColorHueStrategy>
  789 + colorHueStrategy; //!< holds a reference to the strategy that handles all color commands
  790 + HueCommandAPI commands; //!< A IHttpHandler that is used to communicate with the bridge
728 791 };
729   -
730   - //! \brief Protected function that sets the HueCommandAPI.
731   - //!
732   - //! The HueCommandAPI is used for bridge communication
733   - //! \param commandAPI the new HueCommandAPI
734   - virtual void setCommandAPI(const HueCommandAPI& commandAPI) { commands = commandAPI; };
735   -
736   - //! \brief Function that turns the light on without refreshing its state.
737   - //!
738   - //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
739   - //! \return Bool that is true on success
740   - //! \throws std::system_error when system or socket operations fail
741   - //! \throws HueException when response contained no body
742   - //! \throws HueAPIResponseException when response contains an error
743   - //! \throws nlohmann::json::parse_error when response could not be parsed
744   - virtual bool OnNoRefresh(uint8_t transition = 4);
745   -
746   - //! \brief Function that turns the light off without refreshing its state.
747   - //!
748   - //! \param transition Optional parameter to set the transition from current state to new standard is 4 = 400ms
749   - //! \return Bool that is true on success
750   - //! \throws std::system_error when system or socket operations fail
751   - //! \throws HueException when response contained no body
752   - //! \throws HueAPIResponseException when response contains an error
753   - //! \throws nlohmann::json::parse_error when response could not be parsed
754   - virtual bool OffNoRefresh(uint8_t transition = 4);
755   -
756   - //! \brief Utility function to send a put request to the light.
757   - //!
758   - //! \throws nlohmann::json::parse_error if the reply could not be parsed
759   - //! \param request A nlohmann::json aka the request to send
760   - //! \param subPath A path that is appended to the uri, note it should always start with a slash ("/")
761   - //! \param fileInfo FileInfo from calling function for exception details.
762   - //! \return The parsed reply
763   - //! \throws std::system_error when system or socket operations fail
764   - //! \throws HueException when response contained no body
765   - //! \throws HueAPIResponseException when response contains an error
766   - //! \throws nlohmann::json::parse_error when response could not be parsed
767   - virtual nlohmann::json SendPutRequest(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo);
768   -
769   - //! \brief Virtual function that refreshes the \ref state of the light.
770   - //! \throws std::system_error when system or socket operations fail
771   - //! \throws HueException when response contained no body
772   - //! \throws HueAPIResponseException when response contains an error
773   - //! \throws nlohmann::json::parse_error when response could not be parsed
774   - virtual void refreshState();
775   -
776   -protected:
777   - int id; //!< holds the id of the light
778   - nlohmann::json state; //!< holds the current state of the light updated by \ref refreshState
779   - ColorType colorType; //!< holds the \ref ColorType of the light
780   -
781   - std::shared_ptr<const BrightnessStrategy>
782   - brightnessStrategy; //!< holds a reference to the strategy that handles brightness commands
783   - std::shared_ptr<const ColorTemperatureStrategy>
784   - colorTemperatureStrategy; //!< holds a reference to the strategy that handles colortemperature commands
785   - std::shared_ptr<const ColorHueStrategy>
786   - colorHueStrategy; //!< holds a reference to the strategy that handles all color commands
787   - HueCommandAPI commands; //!< A IHttpHandler that is used to communicate with the bridge
788   -};
  792 +} // namespace hueplusplus
789 793  
790 794 #endif
... ...
include/hueplusplus/IHttpHandler.h
... ... @@ -30,167 +30,170 @@
30 30  
31 31 #include "json/json.hpp"
32 32  
33   -//! Abstract class for classes that handle http requests and multicast requests
34   -class IHttpHandler
  33 +namespace hueplusplus
35 34 {
36   -public:
37   - //! \brief Virtual dtor
38   - virtual ~IHttpHandler() = default;
39   -
40   - //! \brief Send a message to a specified host and return the response.
41   - //!
42   - //! \param msg The message that should be sent to the specified address
43   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
44   - //! \param port Optional port the request is sent to, default is 80
45   - //! \return The response of the host as a string
46   - //! \throws std::system_error when system or socket operations fail
47   - virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const = 0;
48   -
49   - //! \brief Send a message to a specified host and return the body of the response.
50   - //!
51   - //! \param msg The message that should sent to the specified address
52   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
53   - //! \param port Optional port the request is sent to, default is 80
54   - //! \return The body of the response of the host as a string
55   - //! \throws std::system_error when system or socket operations fail
56   - //! \throws HueException when response contained no body
57   - virtual std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const = 0;
58   -
59   - //! \brief Send a multicast request with a specified message.
60   - //!
61   - //! \param msg The message that should sent to the specified multicast address
62   - //! \param adr Optional ip or hostname in dotted decimal notation, default is "239.255.255.250"
63   - //! \param port Optional port the request is sent to, default is 1900
64   - //! \param timeout Optional time to wait for responses in seconds, default is 5
65   - //!
66   - //! Blocks for the duration of the timeout.
67   - //!
68   - //! \return vector of strings containing each received answer
69   - //! \throws std::system_error when system or socket operations fail
70   - virtual std::vector<std::string> sendMulticast(
71   - const std::string& msg, const std::string& adr = "239.255.255.250", int port = 1900, int timeout = 5) const = 0;
72   -
73   - //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
74   - //!
75   - //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
76   - //! \param uri Uniform Resource Identifier in the request
77   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
78   - //! \param body Request body, may be empty
79   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
80   - //! \param port Optional port the request is sent to, default is 80
81   - //! \return Body of the response of the host
82   - //! \throws std::system_error when system or socket operations fail
83   - //! \throws HueException when response contained no body
84   - virtual std::string sendHTTPRequest(const std::string& method, const std::string& uri,
85   - const std::string& contentType, const std::string& body, const std::string& adr, int port = 80) const = 0;
86   -
87   - //! \brief Send a HTTP GET request to the specified host and return the body of the response.
88   - //!
89   - //! \param uri Uniform Resource Identifier in the request
90   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
91   - //! \param body Request body, may be empty
92   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
93   - //! \param port Optional port the request is sent to, default is 80
94   - //! that specifies the port to which the request is sent to. Default is 80
95   - //! \return Body of the response of the host
96   - //! \throws std::system_error when system or socket operations fail
97   - //! \throws HueException when response contained no body
98   - virtual std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
99   - const std::string& adr, int port = 80) const = 0;
100   -
101   - //! \brief Send a HTTP POST request to the specified host and return the body of the response.
102   - //!
103   - //! \param uri Uniform Resource Identifier in the request
104   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
105   - //! \param body Request body, may be empty
106   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
107   - //! \param port Optional port the request is sent to, default is 80
108   - //! that specifies the port to which the request is sent to. Default is 80
109   - //! \return Body of the response of the host
110   - //! \throws std::system_error when system or socket operations fail
111   - //! \throws HueException when response contained no body
112   - virtual std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
113   - const std::string& adr, int port = 80) const = 0;
114   -
115   - //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
116   - //!
117   - //! \param uri Uniform Resource Identifier in the request
118   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
119   - //! \param body Request body, may be empty
120   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
121   - //! \param port Optional port the request is sent to, default is 80
122   - //! that specifies the port to which the request is sent to. Default is 80
123   - //! \return Body of the response of the host
124   - //! \throws std::system_error when system or socket operations fail
125   - //! \throws HueException when response contained no body
126   - virtual std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
127   - const std::string& adr, int port = 80) const = 0;
128   -
129   - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
130   - //!
131   - //! \param uri Uniform Resource Identifier in the request
132   - //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
133   - //! \param body Request body, may be empty
134   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
135   - //! \param port Optional port the request is sent to, default is 80
136   - //! that specifies the port to which the request is sent to. Default is 80
137   - //! \return Body of the response of the host
138   - //! \throws std::system_error when system or socket operations fail
139   - //! \throws HueException when response contained no body
140   - virtual std::string DELETEString(const std::string& uri, const std::string& contentType, const std::string& body,
141   - const std::string& adr, int port = 80) const = 0;
142   -
143   - //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
144   - //!
145   - //! \param uri Uniform Resource Identifier in the request
146   - //! \param body Request body, may be empty
147   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
148   - //! \param port Optional port the request is sent to, default is 80
149   - //! \return Parsed body of the response of the host
150   - //! \throws std::system_error when system or socket operations fail
151   - //! \throws HueException when response contained no body
152   - //! \throws nlohmann::json::parse_error when the body could not be parsed
153   - virtual nlohmann::json GETJson(
154   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
155   -
156   - //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
157   - //!
158   - //! \param uri Uniform Resource Identifier in the request
159   - //! \param body Request body, may be empty
160   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
161   - //! \param port Optional port the request is sent to, default is 80
162   - //! \return Parsed body of the response of the host
163   - //! \throws std::system_error when system or socket operations fail
164   - //! \throws HueException when response contained no body
165   - //! \throws nlohmann::json::parse_error when the body could not be parsed
166   - virtual nlohmann::json POSTJson(
167   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
168   -
169   - //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
170   - //!
171   - //! \param uri Uniform Resource Identifier in the request
172   - //! \param body Request body, may be empty
173   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
174   - //! \param port Optional port the request is sent to, default is 80
175   - //! \return Parsed body of the response of the host
176   - //! \throws std::system_error when system or socket operations fail
177   - //! \throws HueException when response contained no body
178   - //! \throws nlohmann::json::parse_error when the body could not be parsed
179   - virtual nlohmann::json PUTJson(
180   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
181   -
182   - //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
183   - //!
184   - //! \param uri Uniform Resource Identifier in the request
185   - //! \param body Request body, may be empty
186   - //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
187   - //! \param port Optional port the request is sent to, default is 80
188   - //! \return Parsed body of the response of the host
189   - //! \throws std::system_error when system or socket operations fail
190   - //! \throws HueException when response contained no body
191   - //! \throws nlohmann::json::parse_error when the body could not be parsed
192   - virtual nlohmann::json DELETEJson(
193   - const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
194   -};
  35 + //! Abstract class for classes that handle http requests and multicast requests
  36 + class IHttpHandler
  37 + {
  38 + public:
  39 + //! \brief Virtual dtor
  40 + virtual ~IHttpHandler() = default;
  41 +
  42 + //! \brief Send a message to a specified host and return the response.
  43 + //!
  44 + //! \param msg The message that should be sent to the specified address
  45 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  46 + //! \param port Optional port the request is sent to, default is 80
  47 + //! \return The response of the host as a string
  48 + //! \throws std::system_error when system or socket operations fail
  49 + virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const = 0;
  50 +
  51 + //! \brief Send a message to a specified host and return the body of the response.
  52 + //!
  53 + //! \param msg The message that should sent to the specified address
  54 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  55 + //! \param port Optional port the request is sent to, default is 80
  56 + //! \return The body of the response of the host as a string
  57 + //! \throws std::system_error when system or socket operations fail
  58 + //! \throws HueException when response contained no body
  59 + virtual std::string sendGetHTTPBody(const std::string& msg, const std::string& adr, int port = 80) const = 0;
  60 +
  61 + //! \brief Send a multicast request with a specified message.
  62 + //!
  63 + //! \param msg The message that should sent to the specified multicast address
  64 + //! \param adr Optional ip or hostname in dotted decimal notation, default is "239.255.255.250"
  65 + //! \param port Optional port the request is sent to, default is 1900
  66 + //! \param timeout Optional time to wait for responses in seconds, default is 5
  67 + //!
  68 + //! Blocks for the duration of the timeout.
  69 + //!
  70 + //! \return vector of strings containing each received answer
  71 + //! \throws std::system_error when system or socket operations fail
  72 + virtual std::vector<std::string> sendMulticast(const std::string& msg,
  73 + const std::string& adr = "239.255.255.250", int port = 1900, int timeout = 5) const = 0;
  74 +
  75 + //! \brief Send a HTTP request with the given method to the specified host and return the body of the response.
  76 + //!
  77 + //! \param method HTTP method type e.g. GET, HEAD, POST, PUT, DELETE, ...
  78 + //! \param uri Uniform Resource Identifier in the request
  79 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  80 + //! \param body Request body, may be empty
  81 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  82 + //! \param port Optional port the request is sent to, default is 80
  83 + //! \return Body of the response of the host
  84 + //! \throws std::system_error when system or socket operations fail
  85 + //! \throws HueException when response contained no body
  86 + virtual std::string sendHTTPRequest(const std::string& method, const std::string& uri,
  87 + const std::string& contentType, const std::string& body, const std::string& adr, int port = 80) const = 0;
  88 +
  89 + //! \brief Send a HTTP GET request to the specified host and return the body of the response.
  90 + //!
  91 + //! \param uri Uniform Resource Identifier in the request
  92 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  93 + //! \param body Request body, may be empty
  94 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  95 + //! \param port Optional port the request is sent to, default is 80
  96 + //! that specifies the port to which the request is sent to. Default is 80
  97 + //! \return Body of the response of the host
  98 + //! \throws std::system_error when system or socket operations fail
  99 + //! \throws HueException when response contained no body
  100 + virtual std::string GETString(const std::string& uri, const std::string& contentType, const std::string& body,
  101 + const std::string& adr, int port = 80) const = 0;
  102 +
  103 + //! \brief Send a HTTP POST request to the specified host and return the body of the response.
  104 + //!
  105 + //! \param uri Uniform Resource Identifier in the request
  106 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  107 + //! \param body Request body, may be empty
  108 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  109 + //! \param port Optional port the request is sent to, default is 80
  110 + //! that specifies the port to which the request is sent to. Default is 80
  111 + //! \return Body of the response of the host
  112 + //! \throws std::system_error when system or socket operations fail
  113 + //! \throws HueException when response contained no body
  114 + virtual std::string POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
  115 + const std::string& adr, int port = 80) const = 0;
  116 +
  117 + //! \brief Send a HTTP PUT request to the specified host and return the body of the response.
  118 + //!
  119 + //! \param uri Uniform Resource Identifier in the request
  120 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  121 + //! \param body Request body, may be empty
  122 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  123 + //! \param port Optional port the request is sent to, default is 80
  124 + //! that specifies the port to which the request is sent to. Default is 80
  125 + //! \return Body of the response of the host
  126 + //! \throws std::system_error when system or socket operations fail
  127 + //! \throws HueException when response contained no body
  128 + virtual std::string PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
  129 + const std::string& adr, int port = 80) const = 0;
  130 +
  131 + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response.
  132 + //!
  133 + //! \param uri Uniform Resource Identifier in the request
  134 + //! \param contentType MIME type of the body data e.g. "text/html", "application/json", ...
  135 + //! \param body Request body, may be empty
  136 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  137 + //! \param port Optional port the request is sent to, default is 80
  138 + //! that specifies the port to which the request is sent to. Default is 80
  139 + //! \return Body of the response of the host
  140 + //! \throws std::system_error when system or socket operations fail
  141 + //! \throws HueException when response contained no body
  142 + virtual std::string DELETEString(const std::string& uri, const std::string& contentType,
  143 + const std::string& body, const std::string& adr, int port = 80) const = 0;
  144 +
  145 + //! \brief Send a HTTP GET request to the specified host and return the body of the response parsed as JSON.
  146 + //!
  147 + //! \param uri Uniform Resource Identifier in the request
  148 + //! \param body Request body, may be empty
  149 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  150 + //! \param port Optional port the request is sent to, default is 80
  151 + //! \return Parsed body of the response of the host
  152 + //! \throws std::system_error when system or socket operations fail
  153 + //! \throws HueException when response contained no body
  154 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  155 + virtual nlohmann::json GETJson(
  156 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
  157 +
  158 + //! \brief Send a HTTP POST request to the specified host and return the body of the response parsed as JSON.
  159 + //!
  160 + //! \param uri Uniform Resource Identifier in the request
  161 + //! \param body Request body, may be empty
  162 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  163 + //! \param port Optional port the request is sent to, default is 80
  164 + //! \return Parsed body of the response of the host
  165 + //! \throws std::system_error when system or socket operations fail
  166 + //! \throws HueException when response contained no body
  167 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  168 + virtual nlohmann::json POSTJson(
  169 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
  170 +
  171 + //! \brief Send a HTTP PUT request to the specified host and return the body of the response parsed as JSON.
  172 + //!
  173 + //! \param uri Uniform Resource Identifier in the request
  174 + //! \param body Request body, may be empty
  175 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  176 + //! \param port Optional port the request is sent to, default is 80
  177 + //! \return Parsed body of the response of the host
  178 + //! \throws std::system_error when system or socket operations fail
  179 + //! \throws HueException when response contained no body
  180 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  181 + virtual nlohmann::json PUTJson(
  182 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
  183 +
  184 + //! \brief Send a HTTP DELETE request to the specified host and return the body of the response parsed as JSON.
  185 + //!
  186 + //! \param uri Uniform Resource Identifier in the request
  187 + //! \param body Request body, may be empty
  188 + //! \param adr Ip or hostname in dotted decimal notation like "192.168.2.1"
  189 + //! \param port Optional port the request is sent to, default is 80
  190 + //! \return Parsed body of the response of the host
  191 + //! \throws std::system_error when system or socket operations fail
  192 + //! \throws HueException when response contained no body
  193 + //! \throws nlohmann::json::parse_error when the body could not be parsed
  194 + virtual nlohmann::json DELETEJson(
  195 + const std::string& uri, const nlohmann::json& body, const std::string& adr, int port = 80) const = 0;
  196 + };
  197 +} // namespace hueplusplus
195 198  
196 199 #endif
... ...
include/hueplusplus/LinHttpHandler.h
... ... @@ -30,31 +30,34 @@
30 30  
31 31 #include "json/json.hpp"
32 32  
33   -//! Class to handle http requests and multicast requests on linux systems
34   -class LinHttpHandler : public BaseHttpHandler
  33 +namespace hueplusplus
35 34 {
36   -public:
37   - //! \brief Function that sends a given message to the specified host and
38   - //! returns the response.
39   - //!
40   - //! \param msg String that contains the message that is sent to the specified
41   - //! address \param adr String that contains an ip or hostname in dotted
42   - //! decimal notation like "192.168.2.1" \param port Optional integer that
43   - //! specifies the port to which the request is sent to. Default is 80 \return
44   - //! String containing the response of the host
45   - virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const;
46   -
47   - //! \brief Function that sends a multicast request with the specified message.
48   - //!
49   - //! \param msg String that contains the request that is sent to the specified
50   - //! address \param adr Optional String that contains an ip or hostname in
51   - //! dotted decimal notation, default is "239.255.255.250" \param port Optional
52   - //! integer that specifies the port to which the request is sent. Default is
53   - //! 1900 \param timeout Optional Integer that specifies the timeout of the
54   - //! request in seconds. Default is 5 \return Vector containing strings of each
55   - //! answer received
56   - virtual std::vector<std::string> sendMulticast(
57   - const std::string& msg, const std::string& adr = "239.255.255.250", int port = 1900, int timeout = 5) const;
58   -};
  35 + //! Class to handle http requests and multicast requests on linux systems
  36 + class LinHttpHandler : public BaseHttpHandler
  37 + {
  38 + public:
  39 + //! \brief Function that sends a given message to the specified host and
  40 + //! returns the response.
  41 + //!
  42 + //! \param msg String that contains the message that is sent to the specified
  43 + //! address \param adr String that contains an ip or hostname in dotted
  44 + //! decimal notation like "192.168.2.1" \param port Optional integer that
  45 + //! specifies the port to which the request is sent to. Default is 80 \return
  46 + //! String containing the response of the host
  47 + virtual std::string send(const std::string& msg, const std::string& adr, int port = 80) const;
  48 +
  49 + //! \brief Function that sends a multicast request with the specified message.
  50 + //!
  51 + //! \param msg String that contains the request that is sent to the specified
  52 + //! address \param adr Optional String that contains an ip or hostname in
  53 + //! dotted decimal notation, default is "239.255.255.250" \param port Optional
  54 + //! integer that specifies the port to which the request is sent. Default is
  55 + //! 1900 \param timeout Optional Integer that specifies the timeout of the
  56 + //! request in seconds. Default is 5 \return Vector containing strings of each
  57 + //! answer received
  58 + virtual std::vector<std::string> sendMulticast(
  59 + const std::string& msg, const std::string& adr = "239.255.255.250", int port = 1900, int timeout = 5) const;
  60 + };
  61 +} // namespace hueplusplus
59 62  
60 63 #endif
... ...
include/hueplusplus/SimpleBrightnessStrategy.h
... ... @@ -26,30 +26,33 @@
26 26 #include "BrightnessStrategy.h"
27 27 #include "HueLight.h"
28 28  
29   -//! Class implementing the functions of BrightnessStrategy
30   -class SimpleBrightnessStrategy : public BrightnessStrategy
  29 +namespace hueplusplus
31 30 {
32   -public:
33   - //! \brief Function for changing a lights brightness with a specified
34   - //! transition.
35   - //!
36   - //! \param bri The brightness raning from 0 = off to 255 = fully lit
37   - //! \param transition The time it takes to fade to the new brightness in
38   - //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
39   - //! light A reference of the light
40   - bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override;
41   - //! \brief Function that returns the current brightness of the light
42   - //!
43   - //! Updates the lights state by calling refreshState()
44   - //! \param light A reference of the light
45   - //! \return Unsigned int representing the brightness
46   - unsigned int getBrightness(HueLight& light) const override;
47   - //! \brief Function that returns the current brightness of the light
48   - //!
49   - //! \note This does not update the lights state
50   - //! \param light A const reference of the light
51   - //! \return Unsigned int representing the brightness
52   - unsigned int getBrightness(const HueLight& light) const override;
53   -};
  31 + //! Class implementing the functions of BrightnessStrategy
  32 + class SimpleBrightnessStrategy : public BrightnessStrategy
  33 + {
  34 + public:
  35 + //! \brief Function for changing a lights brightness with a specified
  36 + //! transition.
  37 + //!
  38 + //! \param bri The brightness raning from 0 = off to 255 = fully lit
  39 + //! \param transition The time it takes to fade to the new brightness in
  40 + //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
  41 + //! light A reference of the light
  42 + bool setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const override;
  43 + //! \brief Function that returns the current brightness of the light
  44 + //!
  45 + //! Updates the lights state by calling refreshState()
  46 + //! \param light A reference of the light
  47 + //! \return Unsigned int representing the brightness
  48 + unsigned int getBrightness(HueLight& light) const override;
  49 + //! \brief Function that returns the current brightness of the light
  50 + //!
  51 + //! \note This does not update the lights state
  52 + //! \param light A const reference of the light
  53 + //! \return Unsigned int representing the brightness
  54 + unsigned int getBrightness(const HueLight& light) const override;
  55 + };
  56 +} // namespace hueplusplus
54 57  
55 58 #endif
... ...
include/hueplusplus/SimpleColorHueStrategy.h
... ... @@ -26,127 +26,130 @@
26 26 #include "ColorHueStrategy.h"
27 27 #include "HueLight.h"
28 28  
29   -//! Class implementing the functions of ColorHueStrategy
30   -class SimpleColorHueStrategy : public ColorHueStrategy
  29 +namespace hueplusplus
31 30 {
32   -public:
33   - //! \brief Function for changing a lights color in hue with a specified
34   - //! transition.
35   - //!
36   - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
37   - //! green and 46920 is blue. \param hue The hue of the color \param transition
38   - //! The time it takes to fade to the new color in multiples of 100ms, 4 =
39   - //! 400ms and should be seen as the default \param light A reference of the
40   - //! light
41   - bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const override;
42   - //! \brief Function for changing a lights color in saturation with a specified
43   - //! transition.
44   - //!
45   - //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white)
46   - //! and 254 is most saturated (vibrant). \param sat The saturation of the
47   - //! color \param transition The time it takes to fade to the new color in
48   - //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
49   - //! light A reference of the light
50   - bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const override;
51   - //! \brief Function for changing a lights color in hue and saturation format
52   - //! with a specified transition.
53   - //!
54   - //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
55   - //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
56   - //! least saturated (white) and 254 is most saturated (vibrant). \param hue
57   - //! The hue of the color \param sat The saturation of the color \param
58   - //! transition The time it takes to fade to the new color in multiples of
59   - //! 100ms, 4 = 400ms and should be seen as the default \param light A
60   - //! reference of the light
61   - bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const override;
62   - //! \brief Function for changing a lights color in CIE format with a specified
63   - //! transition.
64   - //!
65   - //! \param x The x coordinate in CIE, ranging from 0 to 1
66   - //! \param y The y coordinate in CIE, ranging from 0 to 1
67   - //! \param transition The time it takes to fade to the new color in multiples
68   - //! of 100ms, 4 = 400ms and should be seen as the default \param light A
69   - //! reference of the light
70   - bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const override;
71   - //! \brief Function for changing a lights color in rgb format with a specified
72   - //! transition.
73   - //!
74   - //! Red, green and blue are ranging from 0 to 255.
75   - //! \param r The red portion of the color
76   - //! \param g The green portion of the color
77   - //! \param b The blue portion of the color
78   - //! \param transition The time it takes to fade to the new color in multiples
79   - //! of 100ms, 4 = 400ms and should be seen as the default \param light A
80   - //! reference of the light
81   - bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const override;
82   - //! \brief Function for turning on/off the color loop feature of a light.
83   - //!
84   - //! Can be theoretically set for any light, but it only works for lights that
85   - //! support this feature. When this feature is activated the light will fade
86   - //! through every color on the current hue and saturation settings. Notice
87   - //! that none of the setter functions check whether this feature is enabled
88   - //! and the colorloop can only be disabled with this function or by simply
89   - //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
90   - //! alternatively call Off() and then use any of the setter functions.
91   - //! \param on Boolean to turn this feature on or off, true/1 for on and
92   - //! false/0 for off \param light A reference of the light
93   - bool setColorLoop(bool on, HueLight& light) const override;
94   - //! \brief Function that lets the light perform one breath cycle in the
95   - //! specified color.
96   - //!
97   - //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
98   - //! HueLight::alert() needs The hue ranges from 0 to 65535, whereas 65535 and
99   - //! 0 are red, 25500 is green and 46920 is blue. The saturation ranges from 0
100   - //! to 254, whereas 0 is least saturated (white) and 254 is most saturated
101   - //! (vibrant). \param hue The hue of the color \param sat The saturation of
102   - //! the color \param light A reference of the light
103   - bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override;
104   - //! \brief Function that lets the light perform one breath cycle in the
105   - //! specified color.
106   - //!
107   - //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
108   - //! HueLight::alert() needs \param x The x coordinate in CIE, ranging from 0
109   - //! to 1 \param y The y coordinate in CIE, ranging from 0 to 1 \param light A
110   - //! reference of the light
111   - bool alertXY(float x, float y, HueLight& light) const override;
112   - //! \brief Function that lets the light perform one breath cycle in the
113   - //! specified color.
114   - //!
115   - //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
116   - //! HueLight::alert() needs Red, green and blue are ranging from 0 to 255.
117   - //! \param r The red portion of the color
118   - //! \param g The green portion of the color
119   - //! \param b The blue portion of the color
120   - //! \param light A reference of the light
121   - bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override;
122   - //! \brief Function that returns the current color of the light as hue and
123   - //! saturation
124   - //!
125   - //! Updates the lights state by calling refreshState()
126   - //! \param light A reference of the light
127   - //! \return Pair containing the hue as first value and saturation as second
128   - //! value
129   - std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const override;
130   - //! \brief Function that returns the current color of the light as hue and
131   - //! saturation
132   - //!
133   - //! \note This does not update the lights state
134   - //! \param light A const reference of the light
135   - //! \return Pair containing the hue as first value and saturation as second
136   - //! value
137   - std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const override;
138   - //! \brief Function that returns the current color of the light as xy
139   - //!
140   - //! Updates the lights state by calling refreshState()
141   - //! \param light A reference of the light
142   - //! \return Pair containing the x as first value and y as second value
143   - std::pair<float, float> getColorXY(HueLight& light) const override;
144   - //! \brief Function that returns the current color of the light as xy
145   - //!
146   - //! \note This does not update the lights state
147   - //! \param light A const reference of the light
148   - //! \return Pair containing the x as first value and y as second value
149   - std::pair<float, float> getColorXY(const HueLight& light) const override;
150   -};
  31 + //! Class implementing the functions of ColorHueStrategy
  32 + class SimpleColorHueStrategy : public ColorHueStrategy
  33 + {
  34 + public:
  35 + //! \brief Function for changing a lights color in hue with a specified
  36 + //! transition.
  37 + //!
  38 + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
  39 + //! green and 46920 is blue. \param hue The hue of the color \param transition
  40 + //! The time it takes to fade to the new color in multiples of 100ms, 4 =
  41 + //! 400ms and should be seen as the default \param light A reference of the
  42 + //! light
  43 + bool setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const override;
  44 + //! \brief Function for changing a lights color in saturation with a specified
  45 + //! transition.
  46 + //!
  47 + //! The saturation ranges from 0 to 254, whereas 0 is least saturated (white)
  48 + //! and 254 is most saturated (vibrant). \param sat The saturation of the
  49 + //! color \param transition The time it takes to fade to the new color in
  50 + //! multiples of 100ms, 4 = 400ms and should be seen as the default \param
  51 + //! light A reference of the light
  52 + bool setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const override;
  53 + //! \brief Function for changing a lights color in hue and saturation format
  54 + //! with a specified transition.
  55 + //!
  56 + //! The hue ranges from 0 to 65535, whereas 65535 and 0 are red, 25500 is
  57 + //! green and 46920 is blue. The saturation ranges from 0 to 254, whereas 0 is
  58 + //! least saturated (white) and 254 is most saturated (vibrant). \param hue
  59 + //! The hue of the color \param sat The saturation of the color \param
  60 + //! transition The time it takes to fade to the new color in multiples of
  61 + //! 100ms, 4 = 400ms and should be seen as the default \param light A
  62 + //! reference of the light
  63 + bool setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const override;
  64 + //! \brief Function for changing a lights color in CIE format with a specified
  65 + //! transition.
  66 + //!
  67 + //! \param x The x coordinate in CIE, ranging from 0 to 1
  68 + //! \param y The y coordinate in CIE, ranging from 0 to 1
  69 + //! \param transition The time it takes to fade to the new color in multiples
  70 + //! of 100ms, 4 = 400ms and should be seen as the default \param light A
  71 + //! reference of the light
  72 + bool setColorXY(float x, float y, uint8_t transition, HueLight& light) const override;
  73 + //! \brief Function for changing a lights color in rgb format with a specified
  74 + //! transition.
  75 + //!
  76 + //! Red, green and blue are ranging from 0 to 255.
  77 + //! \param r The red portion of the color
  78 + //! \param g The green portion of the color
  79 + //! \param b The blue portion of the color
  80 + //! \param transition The time it takes to fade to the new color in multiples
  81 + //! of 100ms, 4 = 400ms and should be seen as the default \param light A
  82 + //! reference of the light
  83 + bool setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const override;
  84 + //! \brief Function for turning on/off the color loop feature of a light.
  85 + //!
  86 + //! Can be theoretically set for any light, but it only works for lights that
  87 + //! support this feature. When this feature is activated the light will fade
  88 + //! through every color on the current hue and saturation settings. Notice
  89 + //! that none of the setter functions check whether this feature is enabled
  90 + //! and the colorloop can only be disabled with this function or by simply
  91 + //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could
  92 + //! alternatively call Off() and then use any of the setter functions.
  93 + //! \param on Boolean to turn this feature on or off, true/1 for on and
  94 + //! false/0 for off \param light A reference of the light
  95 + bool setColorLoop(bool on, HueLight& light) const override;
  96 + //! \brief Function that lets the light perform one breath cycle in the
  97 + //! specified color.
  98 + //!
  99 + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
  100 + //! HueLight::alert() needs The hue ranges from 0 to 65535, whereas 65535 and
  101 + //! 0 are red, 25500 is green and 46920 is blue. The saturation ranges from 0
  102 + //! to 254, whereas 0 is least saturated (white) and 254 is most saturated
  103 + //! (vibrant). \param hue The hue of the color \param sat The saturation of
  104 + //! the color \param light A reference of the light
  105 + bool alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const override;
  106 + //! \brief Function that lets the light perform one breath cycle in the
  107 + //! specified color.
  108 + //!
  109 + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
  110 + //! HueLight::alert() needs \param x The x coordinate in CIE, ranging from 0
  111 + //! to 1 \param y The y coordinate in CIE, ranging from 0 to 1 \param light A
  112 + //! reference of the light
  113 + bool alertXY(float x, float y, HueLight& light) const override;
  114 + //! \brief Function that lets the light perform one breath cycle in the
  115 + //! specified color.
  116 + //!
  117 + //! \note It uses this_thread::sleep_for to accomodate for the time an \ref
  118 + //! HueLight::alert() needs Red, green and blue are ranging from 0 to 255.
  119 + //! \param r The red portion of the color
  120 + //! \param g The green portion of the color
  121 + //! \param b The blue portion of the color
  122 + //! \param light A reference of the light
  123 + bool alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const override;
  124 + //! \brief Function that returns the current color of the light as hue and
  125 + //! saturation
  126 + //!
  127 + //! Updates the lights state by calling refreshState()
  128 + //! \param light A reference of the light
  129 + //! \return Pair containing the hue as first value and saturation as second
  130 + //! value
  131 + std::pair<uint16_t, uint8_t> getColorHueSaturation(HueLight& light) const override;
  132 + //! \brief Function that returns the current color of the light as hue and
  133 + //! saturation
  134 + //!
  135 + //! \note This does not update the lights state
  136 + //! \param light A const reference of the light
  137 + //! \return Pair containing the hue as first value and saturation as second
  138 + //! value
  139 + std::pair<uint16_t, uint8_t> getColorHueSaturation(const HueLight& light) const override;
  140 + //! \brief Function that returns the current color of the light as xy
  141 + //!
  142 + //! Updates the lights state by calling refreshState()
  143 + //! \param light A reference of the light
  144 + //! \return Pair containing the x as first value and y as second value
  145 + std::pair<float, float> getColorXY(HueLight& light) const override;
  146 + //! \brief Function that returns the current color of the light as xy
  147 + //!
  148 + //! \note This does not update the lights state
  149 + //! \param light A const reference of the light
  150 + //! \return Pair containing the x as first value and y as second value
  151 + std::pair<float, float> getColorXY(const HueLight& light) const override;
  152 + };
  153 +} // namespace hueplusplus
151 154  
152 155 #endif
... ...
include/hueplusplus/SimpleColorTemperatureStrategy.h
... ... @@ -26,41 +26,44 @@
26 26 #include "ColorTemperatureStrategy.h"
27 27 #include "HueLight.h"
28 28  
29   -//! Class implementing the functions of ColorTemperatureStrategy
30   -class SimpleColorTemperatureStrategy : public ColorTemperatureStrategy
  29 +namespace hueplusplus
31 30 {
32   -public:
33   - //! \brief Function for changing a lights color temperature in mired with a
34   - //! specified transition.
35   - //!
36   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
37   - //! and 500 is warm. \param mired The color temperature in mired \param
38   - //! transition The time it takes to fade to the new color in multiples of
39   - //! 100ms, 4 = 400ms and should be seen as the default \param light A
40   - //! reference of the light
41   - bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override;
42   - //! \brief Function that lets the light perform one breath cycle in the
43   - //! specified color.
44   - //!
45   - //! It uses this_thread::sleep_for to accomodate for the time an \ref
46   - //! HueLight::alert() needs The color temperature in mired ranges from 153 to
47   - //! 500 whereas 153 is cold and 500 is warm. \param mired The color
48   - //! temperature in mired \param light A reference of the light
49   - bool alertTemperature(unsigned int mired, HueLight& light) const override;
50   - //! \brief Function that returns the current color temperature of the light
51   - //!
52   - //! Updates the lights state by calling refreshState()
53   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
54   - //! and 500 is warm. \param light A reference of the light \return Unsigned
55   - //! int representing the color temperature in mired
56   - unsigned int getColorTemperature(HueLight& light) const override;
57   - //! \brief Function that returns the current color temperature of the light
58   - //!
59   - //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
60   - //! and 500 is warm. \note This does not update the lights state \param light
61   - //! A const reference of the light \return Unsigned int representing the color
62   - //! temperature in mired
63   - unsigned int getColorTemperature(const HueLight& light) const override;
64   -};
  31 + //! Class implementing the functions of ColorTemperatureStrategy
  32 + class SimpleColorTemperatureStrategy : public ColorTemperatureStrategy
  33 + {
  34 + public:
  35 + //! \brief Function for changing a lights color temperature in mired with a
  36 + //! specified transition.
  37 + //!
  38 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  39 + //! and 500 is warm. \param mired The color temperature in mired \param
  40 + //! transition The time it takes to fade to the new color in multiples of
  41 + //! 100ms, 4 = 400ms and should be seen as the default \param light A
  42 + //! reference of the light
  43 + bool setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const override;
  44 + //! \brief Function that lets the light perform one breath cycle in the
  45 + //! specified color.
  46 + //!
  47 + //! It uses this_thread::sleep_for to accomodate for the time an \ref
  48 + //! HueLight::alert() needs The color temperature in mired ranges from 153 to
  49 + //! 500 whereas 153 is cold and 500 is warm. \param mired The color
  50 + //! temperature in mired \param light A reference of the light
  51 + bool alertTemperature(unsigned int mired, HueLight& light) const override;
  52 + //! \brief Function that returns the current color temperature of the light
  53 + //!
  54 + //! Updates the lights state by calling refreshState()
  55 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  56 + //! and 500 is warm. \param light A reference of the light \return Unsigned
  57 + //! int representing the color temperature in mired
  58 + unsigned int getColorTemperature(HueLight& light) const override;
  59 + //! \brief Function that returns the current color temperature of the light
  60 + //!
  61 + //! The color temperature in mired ranges from 153 to 500 whereas 153 is cold
  62 + //! and 500 is warm. \note This does not update the lights state \param light
  63 + //! A const reference of the light \return Unsigned int representing the color
  64 + //! temperature in mired
  65 + unsigned int getColorTemperature(const HueLight& light) const override;
  66 + };
  67 +} // namespace hueplusplus
65 68  
66 69 #endif
... ...
include/hueplusplus/UPnP.h
... ... @@ -29,18 +29,21 @@
29 29  
30 30 #include "IHttpHandler.h"
31 31  
32   -//! Class that looks for UPnP devices using an m-search package
33   -class UPnP
  32 +namespace hueplusplus
34 33 {
35   -public:
36   - //! \brief Searches for UPnP devices and returns all found ones.
37   - //!
38   - //! It does it by sending an m-search packet and waits for all responses.
39   - //! Since responses can be received multiple times this function conveniently removes all duplicates.
40   - //! \param handler HttpHandler for communication
41   - //! \return A vector containing pairs of address and name of all found devices
42   - //! \throws std::system_error when system or socket operations fail
43   - std::vector<std::pair<std::string, std::string>> getDevices(std::shared_ptr<const IHttpHandler> handler);
44   -};
  34 + //! Class that looks for UPnP devices using an m-search package
  35 + class UPnP
  36 + {
  37 + public:
  38 + //! \brief Searches for UPnP devices and returns all found ones.
  39 + //!
  40 + //! It does it by sending an m-search packet and waits for all responses.
  41 + //! Since responses can be received multiple times this function conveniently removes all duplicates.
  42 + //! \param handler HttpHandler for communication
  43 + //! \return A vector containing pairs of address and name of all found devices
  44 + //! \throws std::system_error when system or socket operations fail
  45 + std::vector<std::pair<std::string, std::string>> getDevices(std::shared_ptr<const IHttpHandler> handler);
  46 + };
  47 +} // namespace hueplusplus
45 48  
46 49 #endif
... ...
include/hueplusplus/Units.h
... ... @@ -23,38 +23,41 @@
23 23 #ifndef _UNITS_H
24 24 #define _UNITS_H
25 25  
26   -struct Kelvin
  26 +namespace hueplusplus
27 27 {
28   - int value;
29   -};
30   -
31   -struct Mired
32   -{
33   - int value;
34   -};
35   -
36   -struct Brightness
37   -{
38   - int value;
39   -};
40   -
41   -struct HueSaturation
42   -{
43   - int hue;
44   - int saturation;
45   -};
46   -
47   -struct XY
48   -{
49   - float x;
50   - float y;
51   -};
52   -
53   -struct RGB
54   -{
55   - uint8_t r;
56   - uint8_t g;
57   - uint8_t b;
58   -};
  28 + struct Kelvin
  29 + {
  30 + int value;
  31 + };
  32 +
  33 + struct Mired
  34 + {
  35 + int value;
  36 + };
  37 +
  38 + struct Brightness
  39 + {
  40 + int value;
  41 + };
  42 +
  43 + struct HueSaturation
  44 + {
  45 + int hue;
  46 + int saturation;
  47 + };
  48 +
  49 + struct XY
  50 + {
  51 + float x;
  52 + float y;
  53 + };
  54 +
  55 + struct RGB
  56 + {
  57 + uint8_t r;
  58 + uint8_t g;
  59 + uint8_t b;
  60 + };
  61 +} // namespace hueplusplus
59 62  
60 63 #endif
... ...
include/hueplusplus/Utils.h
... ... @@ -25,59 +25,62 @@
25 25  
26 26 #include "json/json.hpp"
27 27  
28   -namespace utils
  28 +namespace hueplusplus
29 29 {
30   - namespace detail
  30 + namespace utils
31 31 {
32   - // Forward declaration
33   - template <typename KeyT, typename... Paths>
34   - nlohmann::json safeGetMemberHelper(const nlohmann::json& json, std::size_t index, Paths&&... otherPaths);
  32 + namespace detail
  33 + {
  34 + // Forward declaration
  35 + template <typename KeyT, typename... Paths>
  36 + nlohmann::json safeGetMemberHelper(const nlohmann::json& json, std::size_t index, Paths&&... otherPaths);
35 37  
36   - inline nlohmann::json safeGetMemberHelper(const nlohmann::json& json) { return json; }
  38 + inline nlohmann::json safeGetMemberHelper(const nlohmann::json& json) { return json; }
37 39  
38   - template <typename KeyT, typename... Paths,
39   - std::enable_if_t<!std::is_integral<std::remove_reference_t<KeyT>>::value>* = nullptr>
40   - nlohmann::json safeGetMemberHelper(const nlohmann::json& json, KeyT&& key, Paths&&... otherPaths)
41   - {
42   - auto memberIt = json.find(std::forward<KeyT>(key));
43   - if (memberIt == json.end())
  40 + template <typename KeyT, typename... Paths,
  41 + std::enable_if_t<!std::is_integral<std::remove_reference_t<KeyT>>::value>* = nullptr>
  42 + nlohmann::json safeGetMemberHelper(const nlohmann::json& json, KeyT&& key, Paths&&... otherPaths)
44 43 {
45   - return nullptr;
  44 + auto memberIt = json.find(std::forward<KeyT>(key));
  45 + if (memberIt == json.end())
  46 + {
  47 + return nullptr;
  48 + }
  49 + return safeGetMemberHelper(*memberIt, std::forward<Paths>(otherPaths)...);
46 50 }
47   - return safeGetMemberHelper(*memberIt, std::forward<Paths>(otherPaths)...);
48   - }
49 51  
50   - // Needs to be after the other safeGetMemberHelper, otherwise another forward declaration is needed
51   - template <typename... Paths>
52   - nlohmann::json safeGetMemberHelper(const nlohmann::json& json, std::size_t index, Paths&&... otherPaths)
53   - {
54   - if (!json.is_array() || json.size() <= index)
  52 + // Needs to be after the other safeGetMemberHelper, otherwise another forward declaration is needed
  53 + template <typename... Paths>
  54 + nlohmann::json safeGetMemberHelper(const nlohmann::json& json, std::size_t index, Paths&&... otherPaths)
55 55 {
56   - return nullptr;
  56 + if (!json.is_array() || json.size() <= index)
  57 + {
  58 + return nullptr;
  59 + }
  60 + return safeGetMemberHelper(json[index], std::forward<Paths>(otherPaths)...);
57 61 }
58   - return safeGetMemberHelper(json[index], std::forward<Paths>(otherPaths)...);
59   - }
60   - } // namespace detail
  62 + } // namespace detail
61 63  
62   - //! \brief Function for validating that a request was executed correctly
63   - //!
64   - //! \param request The request that was sent initially
65   - //! \param reply The reply that was received
66   - //! \param lightId The identifier of the light
67   - //! \return True if request was executed correctly
68   - bool validateReplyForLight(const nlohmann::json& request, const nlohmann::json& reply, int lightId);
  64 + //! \brief Function for validating that a request was executed correctly
  65 + //!
  66 + //! \param request The request that was sent initially
  67 + //! \param reply The reply that was received
  68 + //! \param lightId The identifier of the light
  69 + //! \return True if request was executed correctly
  70 + bool validateReplyForLight(const nlohmann::json& request, const nlohmann::json& reply, int lightId);
69 71  
70   - //! \brief Returns the object/array member or null if it does not exist
71   - //!
72   - //! \param json The base json value
73   - //! \param paths Any number of child accesses (e.g. 0, "key" would access json[0]["key"])
74   - //! \returns The specified member or null if any intermediate object does not contain the specified child.
75   - template <typename... Paths>
76   - nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths)
77   - {
78   - return detail::safeGetMemberHelper(json, std::forward<Paths>(paths)...);
79   - }
  72 + //! \brief Returns the object/array member or null if it does not exist
  73 + //!
  74 + //! \param json The base json value
  75 + //! \param paths Any number of child accesses (e.g. 0, "key" would access json[0]["key"])
  76 + //! \returns The specified member or null if any intermediate object does not contain the specified child.
  77 + template <typename... Paths>
  78 + nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths)
  79 + {
  80 + return detail::safeGetMemberHelper(json, std::forward<Paths>(paths)...);
  81 + }
80 82  
81   -} // namespace utils
  83 + } // namespace utils
  84 +} // namespace hueplusplus
82 85  
83 86 #endif
84 87 \ No newline at end of file
... ...
include/hueplusplus/WinHttpHandler.h
... ... @@ -30,40 +30,43 @@
30 30  
31 31 #include "BaseHttpHandler.h"
32 32  
33   -//! Class to handle http requests and multicast requests on windows systems
34   -class WinHttpHandler : public BaseHttpHandler
  33 +namespace hueplusplus
35 34 {
36   -public:
37   - //! \brief Ctor needed for initializing wsaData
38   - WinHttpHandler();
  35 + //! Class to handle http requests and multicast requests on windows systems
  36 + class WinHttpHandler : public BaseHttpHandler
  37 + {
  38 + public:
  39 + //! \brief Ctor needed for initializing wsaData
  40 + WinHttpHandler();
39 41  
40   - //! \brief Dtor needed for wsaData cleanup
41   - ~WinHttpHandler();
  42 + //! \brief Dtor needed for wsaData cleanup
  43 + ~WinHttpHandler();
42 44  
43   - //! \brief Function that sends a given message to the specified host and
44   - //! returns the response.
45   - //!
46   - //! \param msg String that contains the message that is sent to the specified
47   - //! address \param adr String that contains an ip or hostname in dotted
48   - //! decimal notation like "192.168.2.1" \param port Optional integer that
49   - //! specifies the port to which the request is sent to. Default is 80 \return
50   - //! String containing the response of the host
51   - std::string send(const std::string& msg, const std::string& adr, int port = 80) const override;
  45 + //! \brief Function that sends a given message to the specified host and
  46 + //! returns the response.
  47 + //!
  48 + //! \param msg String that contains the message that is sent to the specified
  49 + //! address \param adr String that contains an ip or hostname in dotted
  50 + //! decimal notation like "192.168.2.1" \param port Optional integer that
  51 + //! specifies the port to which the request is sent to. Default is 80 \return
  52 + //! String containing the response of the host
  53 + std::string send(const std::string& msg, const std::string& adr, int port = 80) const override;
52 54  
53   - //! \brief Function that sends a multicast request with the specified message.
54   - //!
55   - //! \param msg String that contains the request that is sent to the specified
56   - //! address \param adr Optional String that contains an ip or hostname in
57   - //! dotted decimal notation, default is "239.255.255.250" \param port Optional
58   - //! integer that specifies the port to which the request is sent. Default is
59   - //! 1900 \param timeout Optional Integer that specifies the timeout of the
60   - //! request in seconds. Default is 5 \return Vector containing strings of each
61   - //! answer received
62   - std::vector<std::string> sendMulticast(const std::string& msg, const std::string& adr = "239.255.255.250",
63   - int port = 1900, int timeout = 5) const override;
  55 + //! \brief Function that sends a multicast request with the specified message.
  56 + //!
  57 + //! \param msg String that contains the request that is sent to the specified
  58 + //! address \param adr Optional String that contains an ip or hostname in
  59 + //! dotted decimal notation, default is "239.255.255.250" \param port Optional
  60 + //! integer that specifies the port to which the request is sent. Default is
  61 + //! 1900 \param timeout Optional Integer that specifies the timeout of the
  62 + //! request in seconds. Default is 5 \return Vector containing strings of each
  63 + //! answer received
  64 + std::vector<std::string> sendMulticast(const std::string& msg, const std::string& adr = "239.255.255.250",
  65 + int port = 1900, int timeout = 5) const override;
64 66  
65   -private:
66   - WSADATA wsaData;
67   -};
  67 + private:
  68 + WSADATA wsaData;
  69 + };
  70 +} // namespace hueplusplus
68 71  
69 72 #endif
... ...
src/BaseHttpHandler.cpp
... ... @@ -24,7 +24,7 @@
24 24  
25 25 #include "hueplusplus/HueExceptionMacro.h"
26 26  
27   -std::string BaseHttpHandler::sendGetHTTPBody(const std::string& msg, const std::string& adr, int port) const
  27 +std::string hueplusplus::BaseHttpHandler::sendGetHTTPBody(const std::string& msg, const std::string& adr, int port) const
28 28 {
29 29 std::string response = send(msg, adr, port);
30 30 size_t start = response.find("\r\n\r\n");
... ... @@ -41,7 +41,7 @@ std::string BaseHttpHandler::sendGetHTTPBody(const std::string&amp; msg, const std::
41 41 return response;
42 42 }
43 43  
44   -std::string BaseHttpHandler::sendHTTPRequest(const std::string& method, const std::string& uri,
  44 +std::string hueplusplus::BaseHttpHandler::sendHTTPRequest(const std::string& method, const std::string& uri,
45 45 const std::string& contentType, const std::string& body, const std::string& adr, int port) const
46 46 {
47 47 std::string request;
... ... @@ -68,49 +68,49 @@ std::string BaseHttpHandler::sendHTTPRequest(const std::string&amp; method, const st
68 68 return sendGetHTTPBody(request.c_str(), adr, port);
69 69 }
70 70  
71   -std::string BaseHttpHandler::GETString(const std::string& uri, const std::string& contentType, const std::string& body,
  71 +std::string hueplusplus::BaseHttpHandler::GETString(const std::string& uri, const std::string& contentType, const std::string& body,
72 72 const std::string& adr, int port) const
73 73 {
74 74 return sendHTTPRequest("GET", uri, contentType, body, adr, port);
75 75 }
76 76  
77   -std::string BaseHttpHandler::POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
  77 +std::string hueplusplus::BaseHttpHandler::POSTString(const std::string& uri, const std::string& contentType, const std::string& body,
78 78 const std::string& adr, int port) const
79 79 {
80 80 return sendHTTPRequest("POST", uri, contentType, body, adr, port);
81 81 }
82 82  
83   -std::string BaseHttpHandler::PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
  83 +std::string hueplusplus::BaseHttpHandler::PUTString(const std::string& uri, const std::string& contentType, const std::string& body,
84 84 const std::string& adr, int port) const
85 85 {
86 86 return sendHTTPRequest("PUT", uri, contentType, body, adr, port);
87 87 }
88 88  
89   -std::string BaseHttpHandler::DELETEString(const std::string& uri, const std::string& contentType,
  89 +std::string hueplusplus::BaseHttpHandler::DELETEString(const std::string& uri, const std::string& contentType,
90 90 const std::string& body, const std::string& adr, int port) const
91 91 {
92 92 return sendHTTPRequest("DELETE", uri, contentType, body, adr, port);
93 93 }
94 94  
95   -nlohmann::json BaseHttpHandler::GETJson(
  95 +nlohmann::json hueplusplus::BaseHttpHandler::GETJson(
96 96 const std::string& uri, const nlohmann::json& body, const std::string& adr, int port) const
97 97 {
98 98 return nlohmann::json::parse(GETString(uri, "application/json", body.dump(), adr, port));
99 99 }
100 100  
101   -nlohmann::json BaseHttpHandler::POSTJson(
  101 +nlohmann::json hueplusplus::BaseHttpHandler::POSTJson(
102 102 const std::string& uri, const nlohmann::json& body, const std::string& adr, int port) const
103 103 {
104 104 return nlohmann::json::parse(POSTString(uri, "application/json", body.dump(), adr, port));
105 105 }
106 106  
107   -nlohmann::json BaseHttpHandler::PUTJson(
  107 +nlohmann::json hueplusplus::BaseHttpHandler::PUTJson(
108 108 const std::string& uri, const nlohmann::json& body, const std::string& adr, int port) const
109 109 {
110 110 return nlohmann::json::parse(PUTString(uri, "application/json", body.dump(), adr, port));
111 111 }
112 112  
113   -nlohmann::json BaseHttpHandler::DELETEJson(
  113 +nlohmann::json hueplusplus::BaseHttpHandler::DELETEJson(
114 114 const std::string& uri, const nlohmann::json& body, const std::string& adr, int port) const
115 115 {
116 116 return nlohmann::json::parse(DELETEString(uri, "application/json", body.dump(), adr, port));
... ...
src/ExtendedColorHueStrategy.cpp
... ... @@ -28,7 +28,7 @@
28 28  
29 29 #include "hueplusplus/HueConfig.h"
30 30  
31   -bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
  31 +bool hueplusplus::ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
32 32 {
33 33 light.refreshState();
34 34 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -110,7 +110,7 @@ bool ExtendedColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, Hue
110 110 }
111 111 }
112 112  
113   -bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const
  113 +bool hueplusplus::ExtendedColorHueStrategy::alertXY(float x, float y, HueLight& light) const
114 114 {
115 115 light.refreshState();
116 116 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -192,7 +192,7 @@ bool ExtendedColorHueStrategy::alertXY(float x, float y, HueLight&amp; light) const
192 192 }
193 193 }
194 194  
195   -bool ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
  195 +bool hueplusplus::ExtendedColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
196 196 {
197 197 light.refreshState();
198 198 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ...
src/ExtendedColorTemperatureStrategy.cpp
... ... @@ -30,7 +30,7 @@
30 30 #include "hueplusplus/HueExceptionMacro.h"
31 31 #include "hueplusplus/Utils.h"
32 32  
33   -bool ExtendedColorTemperatureStrategy::setColorTemperature(
  33 +bool hueplusplus::ExtendedColorTemperatureStrategy::setColorTemperature(
34 34 unsigned int mired, uint8_t transition, HueLight& light) const
35 35 {
36 36 light.refreshState();
... ... @@ -68,7 +68,7 @@ bool ExtendedColorTemperatureStrategy::setColorTemperature(
68 68 return utils::validateReplyForLight(request, reply, light.id);
69 69 }
70 70  
71   -bool ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
  71 +bool hueplusplus::ExtendedColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
72 72 {
73 73 light.refreshState();
74 74 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ...
src/Hue.cpp
... ... @@ -41,9 +41,9 @@
41 41 #include "hueplusplus/UPnP.h"
42 42 #include "hueplusplus/Utils.h"
43 43  
44   -HueFinder::HueFinder(std::shared_ptr<const IHttpHandler> handler) : http_handler(std::move(handler)) {}
  44 +hueplusplus::HueFinder::HueFinder(std::shared_ptr<const IHttpHandler> handler) : http_handler(std::move(handler)) {}
45 45  
46   -std::vector<HueFinder::HueIdentification> HueFinder::FindBridges() const
  46 +std::vector<hueplusplus::HueFinder::HueIdentification> hueplusplus::HueFinder::FindBridges() const
47 47 {
48 48 UPnP uplug;
49 49 std::vector<std::pair<std::string, std::string>> foundDevices = uplug.getDevices(http_handler);
... ... @@ -71,7 +71,7 @@ std::vector&lt;HueFinder::HueIdentification&gt; HueFinder::FindBridges() const
71 71 return foundBridges;
72 72 }
73 73  
74   -Hue HueFinder::GetBridge(const HueIdentification& identification)
  74 +hueplusplus::Hue hueplusplus::HueFinder::GetBridge(const HueIdentification& identification)
75 75 {
76 76 std::string normalizedMac = NormalizeMac(identification.mac);
77 77 auto pos = usernames.find(normalizedMac);
... ... @@ -91,17 +91,17 @@ Hue HueFinder::GetBridge(const HueIdentification&amp; identification)
91 91 return bridge;
92 92 }
93 93  
94   -void HueFinder::AddUsername(const std::string& mac, const std::string& username)
  94 +void hueplusplus::HueFinder::AddUsername(const std::string& mac, const std::string& username)
95 95 {
96 96 usernames[NormalizeMac(mac)] = username;
97 97 }
98 98  
99   -const std::map<std::string, std::string>& HueFinder::GetAllUsernames() const
  99 +const std::map<std::string, std::string>& hueplusplus::HueFinder::GetAllUsernames() const
100 100 {
101 101 return usernames;
102 102 }
103 103  
104   -std::string HueFinder::NormalizeMac(std::string input)
  104 +std::string hueplusplus::HueFinder::NormalizeMac(std::string input)
105 105 {
106 106 // Remove any non alphanumeric characters (e.g. ':' and whitespace)
107 107 input.erase(std::remove_if(input.begin(), input.end(), [](char c) { return !std::isalnum(c, std::locale()); }),
... ... @@ -111,7 +111,7 @@ std::string HueFinder::NormalizeMac(std::string input)
111 111 return input;
112 112 }
113 113  
114   -std::string HueFinder::ParseDescription(const std::string& description)
  114 +std::string hueplusplus::HueFinder::ParseDescription(const std::string& description)
115 115 {
116 116 const char* model = "<modelName>Philips hue bridge";
117 117 const char* serialBegin = "<serialNumber>";
... ... @@ -133,7 +133,7 @@ std::string HueFinder::ParseDescription(const std::string&amp; description)
133 133 return std::string();
134 134 }
135 135  
136   -Hue::Hue(
  136 +hueplusplus::Hue::Hue(
137 137 const std::string& ip, const int port, const std::string& username, std::shared_ptr<const IHttpHandler> handler)
138 138 : ip(ip),
139 139 port(port),
... ... @@ -147,17 +147,17 @@ Hue::Hue(
147 147 commands(ip, port, username, http_handler)
148 148 {}
149 149  
150   -std::string Hue::getBridgeIP()
  150 +std::string hueplusplus::Hue::getBridgeIP()
151 151 {
152 152 return ip;
153 153 }
154 154  
155   -int Hue::getBridgePort()
  155 +int hueplusplus::Hue::getBridgePort()
156 156 {
157 157 return port;
158 158 }
159 159  
160   -std::string Hue::requestUsername()
  160 +std::string hueplusplus::Hue::requestUsername()
161 161 {
162 162 std::cout << "Please press the link Button! You've got 35 secs!\n"; // when the link
163 163 // button was
... ... @@ -206,22 +206,22 @@ std::string Hue::requestUsername()
206 206 return username;
207 207 }
208 208  
209   -std::string Hue::getUsername()
  209 +std::string hueplusplus::Hue::getUsername()
210 210 {
211 211 return username;
212 212 }
213 213  
214   -void Hue::setIP(const std::string& ip)
  214 +void hueplusplus::Hue::setIP(const std::string& ip)
215 215 {
216 216 this->ip = ip;
217 217 }
218 218  
219   -void Hue::setPort(const int port)
  219 +void hueplusplus::Hue::setPort(const int port)
220 220 {
221 221 this->port = port;
222 222 }
223 223  
224   -HueLight& Hue::getLight(int id)
  224 +hueplusplus::HueLight& hueplusplus::Hue::getLight(int id)
225 225 {
226 226 auto pos = lights.find(id);
227 227 if (pos != lights.end())
... ... @@ -245,7 +245,7 @@ HueLight&amp; Hue::getLight(int id)
245 245 return lights.find(id)->second;
246 246 }
247 247  
248   -bool Hue::removeLight(int id)
  248 +bool hueplusplus::Hue::removeLight(int id)
249 249 {
250 250 nlohmann::json result
251 251 = commands.DELETERequest("/lights/" + std::to_string(id), nlohmann::json::object(), CURRENT_FILE_INFO);
... ... @@ -257,7 +257,7 @@ bool Hue::removeLight(int id)
257 257 return success;
258 258 }
259 259  
260   -std::vector<std::reference_wrapper<HueLight>> Hue::getAllLights()
  260 +std::vector<std::reference_wrapper<hueplusplus::HueLight>> hueplusplus::Hue::getAllLights()
261 261 {
262 262 refreshState();
263 263 nlohmann::json lightsState = state["lights"];
... ... @@ -273,7 +273,7 @@ std::vector&lt;std::reference_wrapper&lt;HueLight&gt;&gt; Hue::getAllLights()
273 273 return result;
274 274 }
275 275  
276   -bool Hue::lightExists(int id)
  276 +bool hueplusplus::Hue::lightExists(int id)
277 277 {
278 278 refreshState();
279 279 auto pos = lights.find(id);
... ... @@ -288,7 +288,7 @@ bool Hue::lightExists(int id)
288 288 return false;
289 289 }
290 290  
291   -bool Hue::lightExists(int id) const
  291 +bool hueplusplus::Hue::lightExists(int id) const
292 292 {
293 293 auto pos = lights.find(id);
294 294 if (pos != lights.end())
... ... @@ -302,7 +302,7 @@ bool Hue::lightExists(int id) const
302 302 return false;
303 303 }
304 304  
305   -std::string Hue::getPictureOfLight(int id) const
  305 +std::string hueplusplus::Hue::getPictureOfLight(int id) const
306 306 {
307 307 std::string ret = "";
308 308 auto pos = lights.find(id);
... ... @@ -313,7 +313,7 @@ std::string Hue::getPictureOfLight(int id) const
313 313 return ret;
314 314 }
315 315  
316   -std::string Hue::getPictureOfModel(const std::string& model_id) const
  316 +std::string hueplusplus::Hue::getPictureOfModel(const std::string& model_id) const
317 317 {
318 318 std::string ret = "";
319 319 if (model_id == "LCT001" || model_id == "LCT007" || model_id == "LCT010" || model_id == "LCT014"
... ... @@ -437,7 +437,7 @@ std::string Hue::getPictureOfModel(const std::string&amp; model_id) const
437 437 return ret;
438 438 }
439 439  
440   -void Hue::refreshState()
  440 +void hueplusplus::Hue::refreshState()
441 441 {
442 442 if (username.empty())
443 443 {
... ...
src/HueCommandAPI.cpp
... ... @@ -26,7 +26,7 @@
26 26  
27 27 #include "hueplusplus/HueExceptionMacro.h"
28 28  
29   -constexpr std::chrono::steady_clock::duration HueCommandAPI::minDelay;
  29 +constexpr std::chrono::steady_clock::duration hueplusplus::HueCommandAPI::minDelay;
30 30  
31 31 namespace
32 32 {
... ... @@ -63,7 +63,7 @@ namespace
63 63 }
64 64 } // namespace
65 65  
66   -HueCommandAPI::HueCommandAPI(
  66 +hueplusplus::HueCommandAPI::HueCommandAPI(
67 67 const std::string& ip, const int port, const std::string& username, std::shared_ptr<const IHttpHandler> httpHandler)
68 68 : ip(ip),
69 69 port(port),
... ... @@ -72,43 +72,43 @@ HueCommandAPI::HueCommandAPI(
72 72 timeout(new TimeoutData{std::chrono::steady_clock::now(), {}})
73 73 {}
74 74  
75   -nlohmann::json HueCommandAPI::PUTRequest(const std::string& path, const nlohmann::json& request) const
  75 +nlohmann::json hueplusplus::HueCommandAPI::PUTRequest(const std::string& path, const nlohmann::json& request) const
76 76 {
77 77 return PUTRequest(path, request, CURRENT_FILE_INFO);
78 78 }
79 79  
80   -nlohmann::json HueCommandAPI::PUTRequest(
  80 +nlohmann::json hueplusplus::HueCommandAPI::PUTRequest(
81 81 const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const
82 82 {
83 83 return HandleError(fileInfo,
84 84 RunWithTimeout(timeout, minDelay, [&]() { return httpHandler->PUTJson(CombinedPath(path), request, ip); }));
85 85 }
86 86  
87   -nlohmann::json HueCommandAPI::GETRequest(const std::string& path, const nlohmann::json& request) const
  87 +nlohmann::json hueplusplus::HueCommandAPI::GETRequest(const std::string& path, const nlohmann::json& request) const
88 88 {
89 89 return GETRequest(path, request, CURRENT_FILE_INFO);
90 90 }
91 91  
92   -nlohmann::json HueCommandAPI::GETRequest(
  92 +nlohmann::json hueplusplus::HueCommandAPI::GETRequest(
93 93 const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const
94 94 {
95 95 return HandleError(fileInfo,
96 96 RunWithTimeout(timeout, minDelay, [&]() { return httpHandler->GETJson(CombinedPath(path), request, ip); }));
97 97 }
98 98  
99   -nlohmann::json HueCommandAPI::DELETERequest(const std::string& path, const nlohmann::json& request) const
  99 +nlohmann::json hueplusplus::HueCommandAPI::DELETERequest(const std::string& path, const nlohmann::json& request) const
100 100 {
101 101 return DELETERequest(path, request, CURRENT_FILE_INFO);
102 102 }
103 103  
104   -nlohmann::json HueCommandAPI::DELETERequest(
  104 +nlohmann::json hueplusplus::HueCommandAPI::DELETERequest(
105 105 const std::string& path, const nlohmann::json& request, FileInfo fileInfo) const
106 106 {
107 107 return HandleError(fileInfo,
108 108 RunWithTimeout(timeout, minDelay, [&]() { return httpHandler->DELETEJson(CombinedPath(path), request, ip); }));
109 109 }
110 110  
111   -nlohmann::json HueCommandAPI::HandleError(FileInfo fileInfo, const nlohmann::json& response) const
  111 +nlohmann::json hueplusplus::HueCommandAPI::HandleError(FileInfo fileInfo, const nlohmann::json& response) const
112 112 {
113 113 if (response.count("error"))
114 114 {
... ... @@ -121,7 +121,7 @@ nlohmann::json HueCommandAPI::HandleError(FileInfo fileInfo, const nlohmann::jso
121 121 return response;
122 122 }
123 123  
124   -std::string HueCommandAPI::CombinedPath(const std::string& path) const
  124 +std::string hueplusplus::HueCommandAPI::CombinedPath(const std::string& path) const
125 125 {
126 126 std::string result = "/api/";
127 127 result.append(username);
... ...
src/HueDeviceTypes.cpp
... ... @@ -20,63 +20,53 @@
20 20 along with hueplusplus. If not, see <http://www.gnu.org/licenses/>.
21 21 **/
22 22  
  23 +#include "hueplusplus/HueDeviceTypes.h"
  24 +
23 25 #include <set>
24 26  
25   -#include "hueplusplus/HueDeviceTypes.h"
26 27 #include "hueplusplus/HueExceptionMacro.h"
27 28  
28   -const std::set<std::string> getGamutBTypes()
  29 +namespace
29 30 {
30   - static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES = {
31   - "LCT001", "LCT002", "LCT003", "LCT007", "LLM001"
  31 + const std::set<std::string> getGamutBTypes()
  32 + {
  33 + static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES
  34 + = {"LCT001", "LCT002", "LCT003", "LCT007", "LLM001"};
  35 + return c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES;
32 36 };
33   - return c_EXTENDEDCOLORLIGHT_GAMUTB_TYPES;
34   -};
35 37  
  38 + const std::set<std::string> getGamutCTypes()
  39 + {
  40 + static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES
  41 + = {"LCT010", "LCT011", "LCT012", "LCT014", "LCT015", "LCT016", "LLC020", "LST002"};
  42 + return c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES;
  43 + }
36 44  
37   -const std::set<std::string> getGamutCTypes()
38   -{
39   - static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES = {
40   - "LCT010", "LCT011", "LCT012", "LCT014",
41   - "LCT015", "LCT016", "LLC020", "LST002"
42   - };
43   - return c_EXTENDEDCOLORLIGHT_GAMUTC_TYPES;
44   -}
45   -
46   -const std::set<std::string> getGamutATypes()
47   -{
48   - static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES = {
49   - "LST001", "LLC005" , "LLC006", "LLC007",
50   - "LLC010", "LLC011", "LLC012", "LLC013",
51   - "LLC014"
52   - };
53   - return c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES;
54   -}
  45 + const std::set<std::string> getGamutATypes()
  46 + {
  47 + static const std::set<std::string> c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES
  48 + = {"LST001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012", "LLC013", "LLC014"};
  49 + return c_EXTENDEDCOLORLIGHT_GAMUTA_TYPES;
  50 + }
55 51  
56   -const std::set<std::string> getNoColorTypes()
57   -{
58   - static const std::set<std::string> c_DIMMABLELIGHT_NO_COLOR_TYPES = {
59   - "LWB004", "LWB006", "LWB007", "LWB010",
60   - "LWB014", "LDF001", "LDF002", "LDD001",
61   - "LDD002", "MWM001"
62   - };
63   - return c_DIMMABLELIGHT_NO_COLOR_TYPES;
64   -}
  52 + const std::set<std::string> getNoColorTypes()
  53 + {
  54 + static const std::set<std::string> c_DIMMABLELIGHT_NO_COLOR_TYPES
  55 + = {"LWB004", "LWB006", "LWB007", "LWB010", "LWB014", "LDF001", "LDF002", "LDD001", "LDD002", "MWM001"};
  56 + return c_DIMMABLELIGHT_NO_COLOR_TYPES;
  57 + }
65 58  
66   -const std::set<std::string> getTemperatureLightTypes()
67   -{
68   - static const std::set<std::string> c_TEMPERATURELIGHT_TYPES = {
69   - "LLM010", "LLM011", "LLM012", "LTW001", "LTW004",
70   - "LTW010", "LTW011", "LTW012", "LTW013", "LTW014",
71   - "LTW015", "LTP001", "LTP002", "LTP003", "LTP004",
72   - "LTP005", "LTD003", "LTF001", "LTF002", "LTC001",
73   - "LTC002", "LTC003", "LTC004", "LTC011", "LTC012",
74   - "LTD001", "LTD002", "LFF001", "LTT001", "LDT001"
75   - };
76   - return c_TEMPERATURELIGHT_TYPES;
77   -}
  59 + const std::set<std::string> getTemperatureLightTypes()
  60 + {
  61 + static const std::set<std::string> c_TEMPERATURELIGHT_TYPES
  62 + = {"LLM010", "LLM011", "LLM012", "LTW001", "LTW004", "LTW010", "LTW011", "LTW012", "LTW013", "LTW014",
  63 + "LTW015", "LTP001", "LTP002", "LTP003", "LTP004", "LTP005", "LTD003", "LTF001", "LTF002", "LTC001",
  64 + "LTC002", "LTC003", "LTC004", "LTC011", "LTC012", "LTD001", "LTD002", "LFF001", "LTT001", "LDT001"};
  65 + return c_TEMPERATURELIGHT_TYPES;
  66 + }
  67 +} // namespace
78 68  
79   -auto MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands,
  69 +auto hueplusplus::MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands,
80 70 std::shared_ptr<BrightnessStrategy> simpleBrightnessStrategy,
81 71 std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy,
82 72 std::shared_ptr<ColorTemperatureStrategy> simpleColorTemperatureStrategy,
... ... @@ -85,14 +75,16 @@ auto MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands,
85 75 {
86 76 if (getGamutBTypes().count(type))
87 77 {
88   - auto light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy);
  78 + auto light = HueLight(
  79 + id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy);
89 80 light.colorType = ColorType::GAMUT_B;
90 81 return light;
91 82 }
92 83  
93 84 else if (getGamutCTypes().count(type))
94 85 {
95   - auto light = HueLight(id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy);
  86 + auto light = HueLight(
  87 + id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy, extendedColorHueStrategy);
96 88 light.colorType = ColorType::GAMUT_C;
97 89 return light;
98 90 }
... ...
src/HueException.cpp
... ... @@ -22,21 +22,21 @@
22 22  
23 23 #include "hueplusplus/HueException.h"
24 24  
25   -HueException::HueException(FileInfo fileInfo, const std::string& message)
  25 +hueplusplus::HueException::HueException(FileInfo fileInfo, const std::string& message)
26 26 : HueException("HueException", std::move(fileInfo), message)
27 27 {}
28 28  
29   -const char* HueException::what() const noexcept
  29 +const char* hueplusplus::HueException::what() const noexcept
30 30 {
31 31 return whatMessage.c_str();
32 32 }
33 33  
34   -const FileInfo& HueException::GetFile() const noexcept
  34 +const hueplusplus::FileInfo& hueplusplus::HueException::GetFile() const noexcept
35 35 {
36 36 return fileInfo;
37 37 }
38 38  
39   -HueException::HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message)
  39 +hueplusplus::HueException::HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message)
40 40 : fileInfo(std::move(fileInfo))
41 41 {
42 42 whatMessage = exceptionName;
... ... @@ -46,7 +46,7 @@ HueException::HueException(const char* exceptionName, FileInfo fileInfo, const s
46 46 whatMessage.append(message);
47 47 }
48 48  
49   -HueAPIResponseException::HueAPIResponseException(
  49 +hueplusplus::HueAPIResponseException::HueAPIResponseException(
50 50 FileInfo fileInfo, int error, std::string address, std::string description)
51 51 : HueException("HueApiResponseException", std::move(fileInfo), GetMessage(error, address, description)),
52 52 error(error),
... ... @@ -54,22 +54,22 @@ HueAPIResponseException::HueAPIResponseException(
54 54 description(std::move(description))
55 55 {}
56 56  
57   -int HueAPIResponseException::GetErrorNumber() const noexcept
  57 +int hueplusplus::HueAPIResponseException::GetErrorNumber() const noexcept
58 58 {
59 59 return error;
60 60 }
61 61  
62   -const std::string& HueAPIResponseException::GetAddress() const noexcept
  62 +const std::string& hueplusplus::HueAPIResponseException::GetAddress() const noexcept
63 63 {
64 64 return address;
65 65 }
66 66  
67   -const std::string& HueAPIResponseException::GetDescription() const noexcept
  67 +const std::string& hueplusplus::HueAPIResponseException::GetDescription() const noexcept
68 68 {
69 69 return description;
70 70 }
71 71  
72   -HueAPIResponseException HueAPIResponseException::Create(FileInfo fileInfo, const nlohmann::json& response)
  72 +hueplusplus::HueAPIResponseException hueplusplus::HueAPIResponseException::Create(FileInfo fileInfo, const nlohmann::json& response)
73 73 {
74 74 const nlohmann::json error = response.at("error");
75 75 int errorCode = error.value("type", -1);
... ... @@ -78,7 +78,7 @@ HueAPIResponseException HueAPIResponseException::Create(FileInfo fileInfo, const
78 78 return HueAPIResponseException(std::move(fileInfo), errorCode, std::move(address), std::move(description));
79 79 }
80 80  
81   -std::string HueAPIResponseException::GetMessage(int error, const std::string& addr, const std::string& description)
  81 +std::string hueplusplus::HueAPIResponseException::GetMessage(int error, const std::string& addr, const std::string& description)
82 82 {
83 83 std::string result = std::to_string(error);
84 84 result.append(" ");
... ... @@ -88,7 +88,7 @@ std::string HueAPIResponseException::GetMessage(int error, const std::string&amp; ad
88 88 return result;
89 89 }
90 90  
91   -std::string FileInfo::ToString() const
  91 +std::string hueplusplus::FileInfo::ToString() const
92 92 {
93 93 if (filename.empty() || line < 0)
94 94 {
... ...
src/HueLight.cpp
... ... @@ -30,56 +30,56 @@
30 30 #include "hueplusplus/Utils.h"
31 31 #include "json/json.hpp"
32 32  
33   -bool HueLight::On(uint8_t transition)
  33 +bool hueplusplus::HueLight::On(uint8_t transition)
34 34 {
35 35 refreshState();
36 36 return OnNoRefresh(transition);
37 37 }
38 38  
39   -bool HueLight::Off(uint8_t transition)
  39 +bool hueplusplus::HueLight::Off(uint8_t transition)
40 40 {
41 41 refreshState();
42 42 return OffNoRefresh(transition);
43 43 }
44 44  
45   -bool HueLight::isOn()
  45 +bool hueplusplus::HueLight::isOn()
46 46 {
47 47 refreshState();
48 48 return state["state"]["on"].get<bool>();
49 49 }
50 50  
51   -bool HueLight::isOn() const
  51 +bool hueplusplus::HueLight::isOn() const
52 52 {
53 53 return state["state"]["on"].get<bool>();
54 54 }
55 55  
56   -int HueLight::getId() const
  56 +int hueplusplus::HueLight::getId() const
57 57 {
58 58 return id;
59 59 }
60 60  
61   -std::string HueLight::getType() const
  61 +std::string hueplusplus::HueLight::getType() const
62 62 {
63 63 return state["type"].get<std::string>();
64 64 }
65 65  
66   -std::string HueLight::getName()
  66 +std::string hueplusplus::HueLight::getName()
67 67 {
68 68 refreshState();
69 69 return state["name"].get<std::string>();
70 70 }
71 71  
72   -std::string HueLight::getName() const
  72 +std::string hueplusplus::HueLight::getName() const
73 73 {
74 74 return state["name"].get<std::string>();
75 75 }
76 76  
77   -std::string HueLight::getModelId() const
  77 +std::string hueplusplus::HueLight::getModelId() const
78 78 {
79 79 return state["modelid"].get<std::string>();
80 80 }
81 81  
82   -std::string HueLight::getUId() const
  82 +std::string hueplusplus::HueLight::getUId() const
83 83 {
84 84 if (state.count("uniqueid"))
85 85 {
... ... @@ -88,7 +88,7 @@ std::string HueLight::getUId() const
88 88 return std::string();
89 89 }
90 90  
91   -std::string HueLight::getManufacturername() const
  91 +std::string hueplusplus::HueLight::getManufacturername() const
92 92 {
93 93 if (state.count("manufacturername"))
94 94 {
... ... @@ -97,7 +97,7 @@ std::string HueLight::getManufacturername() const
97 97 return std::string();
98 98 }
99 99  
100   -std::string HueLight::getProductname() const
  100 +std::string hueplusplus::HueLight::getProductname() const
101 101 {
102 102 if (state.count("productname"))
103 103 {
... ... @@ -106,7 +106,7 @@ std::string HueLight::getProductname() const
106 106 return std::string();
107 107 }
108 108  
109   -std::string HueLight::getLuminaireUId() const
  109 +std::string hueplusplus::HueLight::getLuminaireUId() const
110 110 {
111 111 if (state.count("luminaireuniqueid"))
112 112 {
... ... @@ -115,18 +115,18 @@ std::string HueLight::getLuminaireUId() const
115 115 return std::string();
116 116 }
117 117  
118   -std::string HueLight::getSwVersion()
  118 +std::string hueplusplus::HueLight::getSwVersion()
119 119 {
120 120 refreshState();
121 121 return state["swversion"].get<std::string>();
122 122 }
123 123  
124   -std::string HueLight::getSwVersion() const
  124 +std::string hueplusplus::HueLight::getSwVersion() const
125 125 {
126 126 return state["swversion"].get<std::string>();
127 127 }
128 128  
129   -bool HueLight::setName(const std::string& name)
  129 +bool hueplusplus::HueLight::setName(const std::string& name)
130 130 {
131 131 nlohmann::json request = nlohmann::json::object();
132 132 request["name"] = name;
... ... @@ -136,22 +136,22 @@ bool HueLight::setName(const std::string&amp; name)
136 136 return utils::safeGetMember(reply, 0, "success", "/lights/" + std::to_string(id) + "/name") == name;
137 137 }
138 138  
139   -ColorType HueLight::getColorType() const
  139 +hueplusplus::ColorType hueplusplus::HueLight::getColorType() const
140 140 {
141 141 return colorType;
142 142 }
143 143  
144   -unsigned int HueLight::KelvinToMired(unsigned int kelvin) const
  144 +unsigned int hueplusplus::HueLight::KelvinToMired(unsigned int kelvin) const
145 145 {
146 146 return int(0.5f + (1000000 / kelvin));
147 147 }
148 148  
149   -unsigned int HueLight::MiredToKelvin(unsigned int mired) const
  149 +unsigned int hueplusplus::HueLight::MiredToKelvin(unsigned int mired) const
150 150 {
151 151 return int(0.5f + (1000000 / mired));
152 152 }
153 153  
154   -bool HueLight::alert()
  154 +bool hueplusplus::HueLight::alert()
155 155 {
156 156 nlohmann::json request;
157 157 request["alert"] = "select";
... ... @@ -161,9 +161,9 @@ bool HueLight::alert()
161 161 return utils::validateReplyForLight(request, reply, id);
162 162 }
163 163  
164   -HueLight::HueLight(int id, const HueCommandAPI& commands) : HueLight(id, commands, nullptr, nullptr, nullptr) {}
  164 +hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands) : HueLight(id, commands, nullptr, nullptr, nullptr) {}
165 165  
166   -HueLight::HueLight(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
  166 +hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
167 167 std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
168 168 std::shared_ptr<const ColorHueStrategy> colorHueStrategy)
169 169 : id(id),
... ... @@ -176,7 +176,7 @@ HueLight::HueLight(int id, const HueCommandAPI&amp; commands, std::shared_ptr&lt;const
176 176 refreshState();
177 177 }
178 178  
179   -bool HueLight::OnNoRefresh(uint8_t transition)
  179 +bool hueplusplus::HueLight::OnNoRefresh(uint8_t transition)
180 180 {
181 181 nlohmann::json request = nlohmann::json::object();
182 182 if (transition != 4)
... ... @@ -200,7 +200,7 @@ bool HueLight::OnNoRefresh(uint8_t transition)
200 200 return utils::validateReplyForLight(request, reply, id);
201 201 }
202 202  
203   -bool HueLight::OffNoRefresh(uint8_t transition)
  203 +bool hueplusplus::HueLight::OffNoRefresh(uint8_t transition)
204 204 {
205 205 nlohmann::json request = nlohmann::json::object();
206 206 if (transition != 4)
... ... @@ -224,12 +224,12 @@ bool HueLight::OffNoRefresh(uint8_t transition)
224 224 return utils::validateReplyForLight(request, reply, id);
225 225 }
226 226  
227   -nlohmann::json HueLight::SendPutRequest(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo)
  227 +nlohmann::json hueplusplus::HueLight::SendPutRequest(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo)
228 228 {
229 229 return commands.PUTRequest("/lights/" + std::to_string(id) + subPath, request, std::move(fileInfo));
230 230 }
231 231  
232   -void HueLight::refreshState()
  232 +void hueplusplus::HueLight::refreshState()
233 233 {
234 234 // std::chrono::steady_clock::time_point start =
235 235 // std::chrono::steady_clock::now(); std::cout << "\tRefreshing lampstate of
... ...
src/LinHttpHandler.cpp
... ... @@ -48,7 +48,7 @@ private:
48 48 int s;
49 49 };
50 50  
51   -std::string LinHttpHandler::send(const std::string& msg, const std::string& adr, int port) const
  51 +std::string hueplusplus::LinHttpHandler::send(const std::string& msg, const std::string& adr, int port) const
52 52 {
53 53 // create socket
54 54 int socketFD = socket(AF_INET, SOCK_STREAM, 0);
... ... @@ -136,7 +136,7 @@ std::string LinHttpHandler::send(const std::string&amp; msg, const std::string&amp; adr,
136 136 return response;
137 137 }
138 138  
139   -std::vector<std::string> LinHttpHandler::sendMulticast(
  139 +std::vector<std::string> hueplusplus::LinHttpHandler::sendMulticast(
140 140 const std::string& msg, const std::string& adr, int port, int timeout) const
141 141 {
142 142 hostent* server; // host information
... ...
src/SimpleBrightnessStrategy.cpp
... ... @@ -29,7 +29,7 @@
29 29 #include "hueplusplus/HueExceptionMacro.h"
30 30 #include "hueplusplus/Utils.h"
31 31  
32   -bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const
  32 +bool hueplusplus::SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transition, HueLight& light) const
33 33 {
34 34 light.refreshState();
35 35 if (bri == 0)
... ... @@ -76,13 +76,13 @@ bool SimpleBrightnessStrategy::setBrightness(unsigned int bri, uint8_t transitio
76 76 }
77 77 }
78 78  
79   -unsigned int SimpleBrightnessStrategy::getBrightness(HueLight& light) const
  79 +unsigned int hueplusplus::SimpleBrightnessStrategy::getBrightness(HueLight& light) const
80 80 {
81 81 light.refreshState();
82 82 return light.state["state"]["bri"].get<unsigned int>();
83 83 }
84 84  
85   -unsigned int SimpleBrightnessStrategy::getBrightness(const HueLight& light) const
  85 +unsigned int hueplusplus::SimpleBrightnessStrategy::getBrightness(const HueLight& light) const
86 86 {
87 87 return light.state["state"]["bri"].get<unsigned int>();
88 88 }
... ...
src/SimpleColorHueStrategy.cpp
... ... @@ -30,7 +30,7 @@
30 30 #include "hueplusplus/HueExceptionMacro.h"
31 31 #include "hueplusplus/Utils.h"
32 32  
33   -bool SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const
  33 +bool hueplusplus::SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transition, HueLight& light) const
34 34 {
35 35 light.refreshState();
36 36 nlohmann::json request = nlohmann::json::object();
... ... @@ -60,7 +60,7 @@ bool SimpleColorHueStrategy::setColorHue(uint16_t hue, uint8_t transition, HueLi
60 60 return utils::validateReplyForLight(request, reply, light.id);
61 61 }
62 62  
63   -bool SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const
  63 +bool hueplusplus::SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transition, HueLight& light) const
64 64 {
65 65 light.refreshState();
66 66 nlohmann::json request = nlohmann::json::object();
... ... @@ -93,7 +93,7 @@ bool SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_t transition,
93 93 return utils::validateReplyForLight(request, reply, light.id);
94 94 }
95 95  
96   -bool SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const
  96 +bool hueplusplus::SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const
97 97 {
98 98 light.refreshState();
99 99 nlohmann::json request = nlohmann::json::object();
... ... @@ -132,7 +132,7 @@ bool SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, ui
132 132 return utils::validateReplyForLight(request, reply, light.id);
133 133 }
134 134  
135   -bool SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transition, HueLight& light) const
  135 +bool hueplusplus::SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transition, HueLight& light) const
136 136 {
137 137 light.refreshState();
138 138 nlohmann::json request = nlohmann::json::object();
... ... @@ -165,7 +165,7 @@ bool SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t transition, Hu
165 165 return utils::validateReplyForLight(request, reply, light.id);
166 166 }
167 167  
168   -bool SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const
  168 +bool hueplusplus::SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const
169 169 {
170 170 if ((r == 0) && (g == 0) && (b == 0))
171 171 {
... ... @@ -191,7 +191,7 @@ bool SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_
191 191 return light.setColorXY(x, y, transition);
192 192 }
193 193  
194   -bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const
  194 +bool hueplusplus::SimpleColorHueStrategy::setColorLoop(bool on, HueLight& light) const
195 195 {
196 196 // colorloop
197 197 light.refreshState();
... ... @@ -218,7 +218,7 @@ bool SimpleColorHueStrategy::setColorLoop(bool on, HueLight&amp; light) const
218 218 return utils::validateReplyForLight(request, reply, light.id);
219 219 }
220 220  
221   -bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
  221 +bool hueplusplus::SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLight& light) const
222 222 {
223 223 light.refreshState();
224 224 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -277,7 +277,7 @@ bool SimpleColorHueStrategy::alertHueSaturation(uint16_t hue, uint8_t sat, HueLi
277 277 }
278 278 }
279 279  
280   -bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const
  280 +bool hueplusplus::SimpleColorHueStrategy::alertXY(float x, float y, HueLight& light) const
281 281 {
282 282 light.refreshState();
283 283 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -336,7 +336,7 @@ bool SimpleColorHueStrategy::alertXY(float x, float y, HueLight&amp; light) const
336 336 }
337 337 }
338 338  
339   -bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
  339 +bool hueplusplus::SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight& light) const
340 340 {
341 341 light.refreshState();
342 342 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -395,24 +395,24 @@ bool SimpleColorHueStrategy::alertRGB(uint8_t r, uint8_t g, uint8_t b, HueLight&amp;
395 395 }
396 396 }
397 397  
398   -std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const
  398 +std::pair<uint16_t, uint8_t> hueplusplus::SimpleColorHueStrategy::getColorHueSaturation(HueLight& light) const
399 399 {
400 400 light.refreshState();
401 401 return std::make_pair(light.state["state"]["hue"].get<uint16_t>(), light.state["state"]["sat"].get<uint8_t>());
402 402 }
403 403  
404   -std::pair<uint16_t, uint8_t> SimpleColorHueStrategy::getColorHueSaturation(const HueLight& light) const
  404 +std::pair<uint16_t, uint8_t> hueplusplus::SimpleColorHueStrategy::getColorHueSaturation(const HueLight& light) const
405 405 {
406 406 return std::make_pair(light.state["state"]["hue"].get<uint16_t>(), light.state["state"]["sat"].get<uint8_t>());
407 407 }
408 408  
409   -std::pair<float, float> SimpleColorHueStrategy::getColorXY(HueLight& light) const
  409 +std::pair<float, float> hueplusplus::SimpleColorHueStrategy::getColorXY(HueLight& light) const
410 410 {
411 411 light.refreshState();
412 412 return std::make_pair(light.state["state"]["xy"][0].get<float>(), light.state["state"]["xy"][1].get<float>());
413 413 }
414 414  
415   -std::pair<float, float> SimpleColorHueStrategy::getColorXY(const HueLight& light) const
  415 +std::pair<float, float> hueplusplus::SimpleColorHueStrategy::getColorXY(const HueLight& light) const
416 416 {
417 417 return std::make_pair(light.state["state"]["xy"][0].get<float>(), light.state["state"]["xy"][1].get<float>());
418 418 }
... ...
src/SimpleColorTemperatureStrategy.cpp
... ... @@ -30,7 +30,7 @@
30 30 #include "hueplusplus/HueExceptionMacro.h"
31 31 #include "hueplusplus/Utils.h"
32 32  
33   -bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const
  33 +bool hueplusplus::SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const
34 34 {
35 35 light.refreshState();
36 36 nlohmann::json request = nlohmann::json::object();
... ... @@ -67,7 +67,7 @@ bool SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uin
67 67 return utils::validateReplyForLight(request, reply, light.id);
68 68 }
69 69  
70   -bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
  70 +bool hueplusplus::SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLight& light) const
71 71 {
72 72 light.refreshState();
73 73 std::string cType = light.state["state"]["colormode"].get<std::string>();
... ... @@ -101,13 +101,13 @@ bool SimpleColorTemperatureStrategy::alertTemperature(unsigned int mired, HueLig
101 101 }
102 102 }
103 103  
104   -unsigned int SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const
  104 +unsigned int hueplusplus::SimpleColorTemperatureStrategy::getColorTemperature(HueLight& light) const
105 105 {
106 106 light.refreshState();
107 107 return light.state["state"]["ct"].get<unsigned int>();
108 108 }
109 109  
110   -unsigned int SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const
  110 +unsigned int hueplusplus::SimpleColorTemperatureStrategy::getColorTemperature(const HueLight& light) const
111 111 {
112 112 return light.state["state"]["ct"].get<unsigned int>();
113 113 }
... ...
src/UPnP.cpp
... ... @@ -25,7 +25,7 @@
25 25 #include <algorithm>
26 26 #include <iostream>
27 27  
28   -std::vector<std::pair<std::string, std::string>> UPnP::getDevices(std::shared_ptr<const IHttpHandler> handler)
  28 +std::vector<std::pair<std::string, std::string>> hueplusplus::UPnP::getDevices(std::shared_ptr<const IHttpHandler> handler)
29 29 {
30 30 // send UPnP M-Search request
31 31 std::vector<std::string> foundDevices
... ...
src/Utils.cpp
... ... @@ -24,59 +24,55 @@
24 24  
25 25 #include <iostream>
26 26  
27   -namespace utils
  27 +bool hueplusplus::utils::validateReplyForLight(const nlohmann::json& request, const nlohmann::json& reply, int lightId)
28 28 {
29   - bool validateReplyForLight(const nlohmann::json& request, const nlohmann::json& reply, int lightId)
  29 + bool success = false;
  30 + std::string path = "/lights/" + std::to_string(lightId) + "/state/";
  31 + for (auto it = reply.begin(); it != reply.end(); ++it)
30 32 {
31   - bool success = false;
32   - std::string path = "/lights/" + std::to_string(lightId) + "/state/";
33   - for (auto it = reply.begin(); it != reply.end(); ++it)
  33 + success = it.value().count("success");
  34 + if (success)
34 35 {
35   - success = it.value().count("success");
36   - if (success)
  36 + // Traverse through first object
  37 + nlohmann::json successObject = it.value()["success"];
  38 + for (auto successIt = successObject.begin(); successIt != successObject.end(); ++successIt)
37 39 {
38   - // Traverse through first object
39   - nlohmann::json successObject = it.value()["success"];
40   - for (auto successIt = successObject.begin(); successIt != successObject.end(); ++successIt)
  40 + const std::string successPath = successIt.key();
  41 + if (successPath.find(path) == 0)
41 42 {
42   - const std::string successPath = successIt.key();
43   - if (successPath.find(path) == 0)
  43 + const std::string valueKey = successPath.substr(path.size());
  44 + auto requestIt = request.find(valueKey);
  45 + success = requestIt != request.end();
  46 + if (success)
44 47 {
45   - const std::string valueKey = successPath.substr(path.size());
46   - auto requestIt = request.find(valueKey);
47   - success = requestIt != request.end();
48   - if (success)
  48 + if (valueKey == "xy")
49 49 {
50   - if (valueKey == "xy")
51   - {
52   - success
53   - = std::abs(requestIt.value()[0].get<float>() - successIt.value()[0].get<float>())
54   - <= 1E-4f
55   - && std::abs(requestIt.value()[1].get<float>() - successIt.value()[1].get<float>())
56   - <= 1E-4f;
57   - }
58   - else
59   - {
60   - success = requestIt.value() == successIt.value();
61   - }
62   - if (!success)
63   - {
64   - std::cout << "Value " << requestIt.value() << " does not match reply "
65   - << successIt.value() << std::endl;
66   - }
  50 + success = std::abs(requestIt.value()[0].get<float>() - successIt.value()[0].get<float>())
  51 + <= 1E-4f
  52 + && std::abs(requestIt.value()[1].get<float>() - successIt.value()[1].get<float>())
  53 + <= 1E-4f;
  54 + }
  55 + else
  56 + {
  57 + success = requestIt.value() == successIt.value();
  58 + }
  59 + if (!success)
  60 + {
  61 + std::cout << "Value " << requestIt.value() << " does not match reply " << successIt.value()
  62 + << std::endl;
67 63 }
68   - }
69   - else
70   - {
71   - success = false;
72 64 }
73 65 }
  66 + else
  67 + {
  68 + success = false;
  69 + }
74 70 }
75   - if (!success) // Fail fast
76   - {
77   - break;
78   - }
79 71 }
80   - return success;
  72 + if (!success) // Fail fast
  73 + {
  74 + break;
  75 + }
81 76 }
82   -} // namespace utils
83 77 \ No newline at end of file
  78 + return success;
  79 +}
84 80 \ No newline at end of file
... ...
src/WinHttpHandler.cpp
... ... @@ -54,7 +54,7 @@ namespace
54 54 };
55 55 } // namespace
56 56  
57   -WinHttpHandler::WinHttpHandler()
  57 +hueplusplus::WinHttpHandler::WinHttpHandler()
58 58 {
59 59 // Initialize Winsock
60 60 int return_code = WSAStartup(MAKEWORD(2, 2), &wsaData);
... ... @@ -65,12 +65,12 @@ WinHttpHandler::WinHttpHandler()
65 65 }
66 66 }
67 67  
68   -WinHttpHandler::~WinHttpHandler()
  68 +hueplusplus::WinHttpHandler::~WinHttpHandler()
69 69 {
70 70 WSACleanup();
71 71 }
72 72  
73   -std::string WinHttpHandler::send(const std::string& msg, const std::string& adr, int port) const
  73 +std::string hueplusplus::WinHttpHandler::send(const std::string& msg, const std::string& adr, int port) const
74 74 {
75 75 struct addrinfo hints = {};
76 76 hints.ai_family = AF_INET;
... ... @@ -171,7 +171,7 @@ std::string WinHttpHandler::send(const std::string&amp; msg, const std::string&amp; adr,
171 171 return response;
172 172 }
173 173  
174   -std::vector<std::string> WinHttpHandler::sendMulticast(
  174 +std::vector<std::string> hueplusplus::WinHttpHandler::sendMulticast(
175 175 const std::string& msg, const std::string& adr, int port, int timeout) const
176 176 {
177 177 struct addrinfo hints = {};
... ...
test/mocks/mock_BaseHttpHandler.h
... ... @@ -32,7 +32,7 @@
32 32 #include "json/json.hpp"
33 33  
34 34 //! Mock Class
35   -class MockBaseHttpHandler : public BaseHttpHandler
  35 +class MockBaseHttpHandler : public hueplusplus::BaseHttpHandler
36 36 {
37 37 public:
38 38 MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port));
... ...
test/mocks/mock_HttpHandler.h
... ... @@ -32,7 +32,7 @@
32 32 #include "json/json.hpp"
33 33  
34 34 //! Mock Class
35   -class MockHttpHandler : public IHttpHandler
  35 +class MockHttpHandler : public hueplusplus::IHttpHandler
36 36 {
37 37 public:
38 38 MOCK_CONST_METHOD3(send, std::string(const std::string& msg, const std::string& adr, int port));
... ...
test/mocks/mock_HueLight.h
... ... @@ -33,11 +33,11 @@
33 33 #include "../testhelper.h"
34 34  
35 35 //! Mock Class
36   -class MockHueLight : public HueLight
  36 +class MockHueLight : public hueplusplus::HueLight
37 37 {
38 38 public:
39   - MockHueLight(std::shared_ptr<const IHttpHandler> handler)
40   - : HueLight(1, HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {};
  39 + MockHueLight(std::shared_ptr<const hueplusplus::IHttpHandler> handler)
  40 + : HueLight(1, hueplusplus::HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {};
41 41  
42 42 nlohmann::json& getState() { return state; };
43 43  
... ... @@ -71,7 +71,7 @@ public:
71 71  
72 72 MOCK_METHOD1(setName, bool(std::string& name));
73 73  
74   - MOCK_CONST_METHOD0(getColorType, ColorType());
  74 + MOCK_CONST_METHOD0(getColorType, hueplusplus::ColorType());
75 75  
76 76 MOCK_CONST_METHOD0(hasBrightnessControl, bool());
77 77  
... ... @@ -126,7 +126,7 @@ public:
126 126 MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition));
127 127  
128 128 MOCK_METHOD3(
129   - SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo));
  129 + SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, hueplusplus::FileInfo fileInfo));
130 130  
131 131 MOCK_METHOD0(refreshState, void());
132 132 };
... ...
test/test_BaseHttpHandler.cpp
... ... @@ -32,6 +32,8 @@
32 32 #include "mocks/mock_BaseHttpHandler.h"
33 33 #include "hueplusplus/HueException.h"
34 34  
  35 +using namespace hueplusplus;
  36 +
35 37 TEST(BaseHttpHandler, sendGetHTTPBody)
36 38 {
37 39 using namespace ::testing;
... ...
test/test_ExtendedColorHueStrategy.cpp
... ... @@ -33,6 +33,8 @@
33 33 #include "mocks/mock_HttpHandler.h"
34 34 #include "mocks/mock_HueLight.h"
35 35  
  36 +using namespace hueplusplus;
  37 +
36 38 TEST(ExtendedColorHueStrategy, alertHueSaturation)
37 39 {
38 40 using namespace ::testing;
... ...
test/test_ExtendedColorTemperatureStrategy.cpp
... ... @@ -33,6 +33,8 @@
33 33 #include "mocks/mock_HttpHandler.h"
34 34 #include "mocks/mock_HueLight.h"
35 35  
  36 +using namespace hueplusplus;
  37 +
36 38 TEST(ExtendedColorTemperatureStrategy, setColorTemperature)
37 39 {
38 40 using namespace ::testing;
... ...
test/test_Hue.cpp
... ... @@ -34,6 +34,8 @@
34 34 #include "json/json.hpp"
35 35 #include "mocks/mock_HttpHandler.h"
36 36  
  37 +using namespace hueplusplus;
  38 +
37 39 class HueFinderTest : public ::testing::Test
38 40 {
39 41 protected:
... ...
test/test_HueCommandAPI.cpp
... ... @@ -29,6 +29,8 @@
29 29 #include "json/json.hpp"
30 30 #include "mocks/mock_HttpHandler.h"
31 31  
  32 +using namespace hueplusplus;
  33 +
32 34 TEST(HueCommandAPI, PUTRequest)
33 35 {
34 36 using namespace ::testing;
... ...
test/test_HueLight.cpp
... ... @@ -30,6 +30,8 @@
30 30 #include "json/json.hpp"
31 31 #include "mocks/mock_HttpHandler.h"
32 32  
  33 +using namespace hueplusplus;
  34 +
33 35 class HueLightTest : public ::testing::Test
34 36 {
35 37 protected:
... ...
test/test_SimpleBrightnessStrategy.cpp
... ... @@ -34,6 +34,8 @@
34 34 #include "mocks/mock_HttpHandler.h"
35 35 #include "mocks/mock_HueLight.h"
36 36  
  37 +using namespace hueplusplus;
  38 +
37 39 TEST(SimpleBrightnessStrategy, setBrightness)
38 40 {
39 41 using namespace ::testing;
... ...
test/test_SimpleColorHueStrategy.cpp
... ... @@ -33,6 +33,8 @@
33 33 #include "mocks/mock_HttpHandler.h"
34 34 #include "mocks/mock_HueLight.h"
35 35  
  36 +using namespace hueplusplus;
  37 +
36 38 TEST(SimpleColorHueStrategy, setColorHue)
37 39 {
38 40 using namespace ::testing;
... ...
test/test_SimpleColorTemperatureStrategy.cpp
... ... @@ -34,6 +34,8 @@
34 34 #include "mocks/mock_HttpHandler.h"
35 35 #include "mocks/mock_HueLight.h"
36 36  
  37 +using namespace hueplusplus;
  38 +
37 39 TEST(SimpleColorTemperatureStrategy, setColorTemperature)
38 40 {
39 41 using namespace ::testing;
... ...
test/test_UPnP.cpp
... ... @@ -30,6 +30,8 @@
30 30 #include "json/json.hpp"
31 31 #include "mocks/mock_HttpHandler.h"
32 32  
  33 +using namespace hueplusplus;
  34 +
33 35 const std::vector<std::pair<std::string, std::string>> expected_uplug_dev
34 36 = {{"http://192.168.2.1:1900/gatedesc.xml", "Linux/2.6.36, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"},
35 37 {"http://192.168.2.116:80/description.xml", "Linux/3.14.0 UPnP/1.0 IpBridge/1.21.0"}};
... ...