Commit 39ce4c01d6ea10554069be3e38e9297f5fdba47d

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent e57df540

Reformat all files with updated clang-format.

include/hueplusplus/BaseHttpHandler.h
@@ -34,145 +34,145 @@ @@ -34,145 +34,145 @@
34 34
35 namespace hueplusplus 35 namespace hueplusplus
36 { 36 {
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 - }; 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 176 } // namespace hueplusplus
177 177
178 #endif 178 #endif
include/hueplusplus/BrightnessStrategy.h
@@ -27,35 +27,35 @@ @@ -27,35 +27,35 @@
27 27
28 namespace hueplusplus 28 namespace hueplusplus
29 { 29 {
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 - }; 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 59 } // namespace hueplusplus
60 60
61 #endif 61 #endif
include/hueplusplus/ColorHueStrategy.h
@@ -28,130 +28,130 @@ @@ -28,130 +28,130 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
31 - class HueLight; 31 +class HueLight;
32 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 - }; 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 155 } // namespace hueplusplus
156 156
157 #endif 157 #endif
include/hueplusplus/ColorTemperatureStrategy.h
@@ -27,47 +27,47 @@ @@ -27,47 +27,47 @@
27 27
28 namespace hueplusplus 28 namespace hueplusplus
29 { 29 {
30 - class HueLight; 30 +class HueLight;
31 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 - }; 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 71 } // namespace hueplusplus
72 72
73 #endif 73 #endif
include/hueplusplus/ExtendedColorHueStrategy.h
@@ -28,39 +28,39 @@ @@ -28,39 +28,39 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
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 - }; 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 64 } // namespace hueplusplus
65 65
66 #endif 66 #endif
include/hueplusplus/ExtendedColorTemperatureStrategy.h
@@ -28,28 +28,28 @@ @@ -28,28 +28,28 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
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 - }; 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 53 } // namespace hueplusplus
54 54
55 #endif 55 #endif
include/hueplusplus/Hue.h
@@ -40,246 +40,245 @@ @@ -40,246 +40,245 @@
40 40
41 namespace hueplusplus 41 namespace hueplusplus
42 { 42 {
43 - // forward declarations  
44 - class Hue; 43 +// forward declarations
  44 +class Hue;
45 45
46 - //!  
47 - //! Class to find all Hue bridges on the network and create usernames for them.  
48 - //!  
49 - class HueFinder 46 +//!
  47 +//! Class to find all Hue bridges on the network and create usernames for them.
  48 +//!
  49 +class HueFinder
  50 +{
  51 +public:
  52 + struct HueIdentification
50 { 53 {
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; 54 + std::string ip;
  55 + int port = 80;
  56 + std::string mac;
111 }; 57 };
112 58
113 - //! Hue class  
114 - class Hue 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 +};
  112 +
  113 +//! Hue class
  114 +class Hue
  115 +{
  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)
115 { 246 {
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 - }; 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> simpleColorTemperatureStrategy; //!< Strategy that is used for controlling
  274 + //!< the color temperature of lights
  275 + std::shared_ptr<ColorTemperatureStrategy> extendedColorTemperatureStrategy; //!< Strategy that is used for
  276 + //!< controlling the color
  277 + //!< temperature of lights
  278 + std::shared_ptr<const IHttpHandler> http_handler; //!< A IHttpHandler that is used to communicate with the
  279 + //!< bridge
  280 + HueCommandAPI commands; //!< A HueCommandAPI that is used to communicate with the bridge
  281 +};
283 } // namespace hueplusplus 282 } // namespace hueplusplus
284 283
285 #endif 284 #endif
include/hueplusplus/HueCommandAPI.h
@@ -32,96 +32,96 @@ @@ -32,96 +32,96 @@
32 32
33 namespace hueplusplus 33 namespace hueplusplus
34 { 34 {
35 - //! Handles communication to the bridge via IHttpHandler and enforces a timeout  
36 - //! between each request  
37 - class HueCommandAPI 35 +//! Handles communication to the bridge via IHttpHandler and enforces a timeout
  36 +//! between each request
  37 +class HueCommandAPI
  38 +{
  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(
  47 + const std::string& ip, int port, const std::string& username, 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
38 { 101 {
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 + std::chrono::steady_clock::time_point timeout;
  103 + std::mutex mutex;
124 }; 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;
  124 +};
125 } // namespace hueplusplus 125 } // namespace hueplusplus
126 126
127 #endif 127 #endif
128 \ No newline at end of file 128 \ No newline at end of file
include/hueplusplus/HueConfig.h
@@ -25,8 +25,8 @@ @@ -25,8 +25,8 @@
25 25
26 namespace hueplusplus 26 namespace hueplusplus
27 { 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 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 30 } // namespace hueplusplus
31 31
32 #endif 32 #endif
include/hueplusplus/HueDeviceTypes.h
@@ -30,15 +30,15 @@ @@ -30,15 +30,15 @@
30 30
31 namespace hueplusplus 31 namespace hueplusplus
32 { 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 - }; 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 42 } // namespace hueplusplus
43 43
44 #endif 44 #endif
include/hueplusplus/HueException.h
@@ -30,92 +30,92 @@ @@ -30,92 +30,92 @@
30 30
31 namespace hueplusplus 31 namespace hueplusplus
32 { 32 {
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 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
  81 +//!
  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.
81 //! 95 //!
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 - }; 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 119 } // namespace hueplusplus
120 120
121 #endif 121 #endif
122 \ No newline at end of file 122 \ No newline at end of file
include/hueplusplus/HueLight.h
@@ -34,61 +34,61 @@ @@ -34,61 +34,61 @@
34 34
35 namespace hueplusplus 35 namespace hueplusplus
36 { 36 {
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 - }; 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 +};
92 92
93 //! 93 //!
94 //! Class for Hue Light fixtures 94 //! Class for Hue Light fixtures
@@ -103,692 +103,691 @@ class HueLight @@ -103,692 +103,691 @@ class HueLight
103 friend class SimpleColorTemperatureStrategy; 103 friend class SimpleColorTemperatureStrategy;
104 friend class ExtendedColorTemperatureStrategy; 104 friend class ExtendedColorTemperatureStrategy;
105 105
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 - {  
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 - {  
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 - {  
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) 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 + {
  273 + if (brightnessStrategy)
327 { 274 {
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 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 + {
  288 + if (brightnessStrategy)
345 { 289 {
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() 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 + {
  307 + if (brightnessStrategy)
366 { 308 {
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) 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 + {
  328 + if (colorTemperatureStrategy)
387 { 329 {
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) 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 + {
  346 + if (colorTemperatureStrategy)
408 { 347 {
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) 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 + {
  367 + if (colorTemperatureStrategy)
430 { 368 {
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 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 + {
  388 + if (colorHueStrategy)
450 { 389 {
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() 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 + {
  409 + if (colorHueStrategy)
470 { 410 {
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) 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 + {
  431 + if (colorHueStrategy)
491 { 432 {
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 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 + {
  451 + if (colorHueStrategy)
507 { 452 {
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() 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 + {
  471 + if (colorHueStrategy)
526 { 472 {
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) 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 + {
  492 + if (colorHueStrategy)
550 { 493 {
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) 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 + {
  508 + if (colorHueStrategy)
580 { 509 {
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) 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 + {
  527 + if (colorHueStrategy)
601 { 528 {
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) 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 + {
  551 + if (colorHueStrategy)
623 { 552 {
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) 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 + {
  581 + if (colorTemperatureStrategy)
646 { 582 {
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) 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 + {
  602 + if (colorHueStrategy)
670 { 603 {
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) 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 + {
  624 + if (colorHueStrategy)
709 { 625 {
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) 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 + {
  647 + if (colorHueStrategy)
719 { 648 {
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) 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 + {
  671 + if (colorHueStrategy)
728 { 672 {
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 673 + return colorHueStrategy->setColorLoop(on, *this);
  674 + }
  675 + return false;
791 }; 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(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo);
  770 +
  771 + //! \brief Virtual function that refreshes the \ref state of the light.
  772 + //! \throws std::system_error when system or socket operations fail
  773 + //! \throws HueException when response contained no body
  774 + //! \throws HueAPIResponseException when response contains an error
  775 + //! \throws nlohmann::json::parse_error when response could not be parsed
  776 + virtual void refreshState();
  777 +
  778 +protected:
  779 + int id; //!< holds the id of the light
  780 + nlohmann::json state; //!< holds the current state of the light updated by \ref refreshState
  781 + ColorType colorType; //!< holds the \ref ColorType of the light
  782 +
  783 + std::shared_ptr<const BrightnessStrategy>
  784 + brightnessStrategy; //!< holds a reference to the strategy that handles brightness commands
  785 + std::shared_ptr<const ColorTemperatureStrategy>
  786 + colorTemperatureStrategy; //!< holds a reference to the strategy that handles colortemperature commands
  787 + std::shared_ptr<const ColorHueStrategy>
  788 + colorHueStrategy; //!< holds a reference to the strategy that handles all color commands
  789 + HueCommandAPI commands; //!< A IHttpHandler that is used to communicate with the bridge
  790 +};
792 } // namespace hueplusplus 791 } // namespace hueplusplus
793 792
794 #endif 793 #endif
include/hueplusplus/IHttpHandler.h
@@ -32,168 +32,168 @@ @@ -32,168 +32,168 @@
32 32
33 namespace hueplusplus 33 namespace hueplusplus
34 { 34 {
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 - }; 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(
  73 + const std::string& msg, 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, const std::string& body,
  143 + 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 197 } // namespace hueplusplus
198 198
199 #endif 199 #endif
include/hueplusplus/LinHttpHandler.h
@@ -32,32 +32,32 @@ @@ -32,32 +32,32 @@
32 32
33 namespace hueplusplus 33 namespace hueplusplus
34 { 34 {
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 - }; 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 61 } // namespace hueplusplus
62 62
63 #endif 63 #endif
include/hueplusplus/SimpleBrightnessStrategy.h
@@ -28,31 +28,31 @@ @@ -28,31 +28,31 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
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 - }; 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 56 } // namespace hueplusplus
57 57
58 #endif 58 #endif
include/hueplusplus/SimpleColorHueStrategy.h
@@ -28,128 +28,128 @@ @@ -28,128 +28,128 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
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 - }; 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 153 } // namespace hueplusplus
154 154
155 #endif 155 #endif
include/hueplusplus/SimpleColorTemperatureStrategy.h
@@ -28,42 +28,42 @@ @@ -28,42 +28,42 @@
28 28
29 namespace hueplusplus 29 namespace hueplusplus
30 { 30 {
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 - }; 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 67 } // namespace hueplusplus
68 68
69 #endif 69 #endif
include/hueplusplus/UPnP.h
@@ -31,19 +31,19 @@ @@ -31,19 +31,19 @@
31 31
32 namespace hueplusplus 32 namespace hueplusplus
33 { 33 {
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 - }; 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 47 } // namespace hueplusplus
48 48
49 #endif 49 #endif
include/hueplusplus/Units.h
@@ -25,39 +25,39 @@ @@ -25,39 +25,39 @@
25 25
26 namespace hueplusplus 26 namespace hueplusplus
27 { 27 {
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 - }; 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 61 } // namespace hueplusplus
62 62
63 #endif 63 #endif
include/hueplusplus/Utils.h
@@ -27,60 +27,63 @@ @@ -27,60 +27,63 @@
27 27
28 namespace hueplusplus 28 namespace hueplusplus
29 { 29 {
30 - namespace utils  
31 - {  
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); 30 +namespace utils
  31 +{
  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);
37 37
38 - inline nlohmann::json safeGetMemberHelper(const nlohmann::json& json) { return json; } 38 +inline nlohmann::json safeGetMemberHelper(const nlohmann::json& json)
  39 +{
  40 + return json;
  41 +}
39 42
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)  
43 - {  
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)...);  
50 - } 43 +template <typename KeyT, typename... Paths,
  44 + std::enable_if_t<!std::is_integral<std::remove_reference_t<KeyT>>::value>* = nullptr>
  45 +nlohmann::json safeGetMemberHelper(const nlohmann::json& json, KeyT&& key, Paths&&... otherPaths)
  46 +{
  47 + auto memberIt = json.find(std::forward<KeyT>(key));
  48 + if (memberIt == json.end())
  49 + {
  50 + return nullptr;
  51 + }
  52 + return safeGetMemberHelper(*memberIt, std::forward<Paths>(otherPaths)...);
  53 +}
51 54
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 - {  
56 - if (!json.is_array() || json.size() <= index)  
57 - {  
58 - return nullptr;  
59 - }  
60 - return safeGetMemberHelper(json[index], std::forward<Paths>(otherPaths)...);  
61 - }  
62 - } // namespace detail 55 +// Needs to be after the other safeGetMemberHelper, otherwise another forward declaration is needed
  56 +template <typename... Paths>
  57 +nlohmann::json safeGetMemberHelper(const nlohmann::json& json, std::size_t index, Paths&&... otherPaths)
  58 +{
  59 + if (!json.is_array() || json.size() <= index)
  60 + {
  61 + return nullptr;
  62 + }
  63 + return safeGetMemberHelper(json[index], std::forward<Paths>(otherPaths)...);
  64 +}
  65 +} // namespace detail
63 66
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); 67 +//! \brief Function for validating that a request was executed correctly
  68 +//!
  69 +//! \param request The request that was sent initially
  70 +//! \param reply The reply that was received
  71 +//! \param lightId The identifier of the light
  72 +//! \return True if request was executed correctly
  73 +bool validateReplyForLight(const nlohmann::json& request, const nlohmann::json& reply, int lightId);
71 74
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 - } 75 +//! \brief Returns the object/array member or null if it does not exist
  76 +//!
  77 +//! \param json The base json value
  78 +//! \param paths Any number of child accesses (e.g. 0, "key" would access json[0]["key"])
  79 +//! \returns The specified member or null if any intermediate object does not contain the specified child.
  80 +template <typename... Paths>
  81 +nlohmann::json safeGetMember(const nlohmann::json& json, Paths&&... paths)
  82 +{
  83 + return detail::safeGetMemberHelper(json, std::forward<Paths>(paths)...);
  84 +}
82 85
83 - } // namespace utils 86 +} // namespace utils
84 } // namespace hueplusplus 87 } // namespace hueplusplus
85 88
86 #endif 89 #endif
87 \ No newline at end of file 90 \ No newline at end of file
include/hueplusplus/WinHttpHandler.h
@@ -32,41 +32,41 @@ @@ -32,41 +32,41 @@
32 32
33 namespace hueplusplus 33 namespace hueplusplus
34 { 34 {
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(); 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();
41 41
42 - //! \brief Dtor needed for wsaData cleanup  
43 - ~WinHttpHandler(); 42 + //! \brief Dtor needed for wsaData cleanup
  43 + ~WinHttpHandler();
44 44
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; 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;
54 54
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; 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;
66 66
67 - private:  
68 - WSADATA wsaData;  
69 - }; 67 +private:
  68 + WSADATA wsaData;
  69 +};
70 } // namespace hueplusplus 70 } // namespace hueplusplus
71 71
72 #endif 72 #endif
src/BaseHttpHandler.cpp
@@ -24,7 +24,8 @@ @@ -24,7 +24,8 @@
24 24
25 #include "hueplusplus/HueExceptionMacro.h" 25 #include "hueplusplus/HueExceptionMacro.h"
26 26
27 -std::string hueplusplus::BaseHttpHandler::sendGetHTTPBody(const std::string& msg, const std::string& adr, int port) const 27 +std::string hueplusplus::BaseHttpHandler::sendGetHTTPBody(
  28 + const std::string& msg, const std::string& adr, int port) const
28 { 29 {
29 std::string response = send(msg, adr, port); 30 std::string response = send(msg, adr, port);
30 size_t start = response.find("\r\n\r\n"); 31 size_t start = response.find("\r\n\r\n");
@@ -68,20 +69,20 @@ std::string hueplusplus::BaseHttpHandler::sendHTTPRequest(const std::string&amp; met @@ -68,20 +69,20 @@ std::string hueplusplus::BaseHttpHandler::sendHTTPRequest(const std::string&amp; met
68 return sendGetHTTPBody(request.c_str(), adr, port); 69 return sendGetHTTPBody(request.c_str(), adr, port);
69 } 70 }
70 71
71 -std::string hueplusplus::BaseHttpHandler::GETString(const std::string& uri, const std::string& contentType, const std::string& body,  
72 - const std::string& adr, int port) const 72 +std::string hueplusplus::BaseHttpHandler::GETString(const std::string& uri, const std::string& contentType,
  73 + const std::string& body, const std::string& adr, int port) const
73 { 74 {
74 return sendHTTPRequest("GET", uri, contentType, body, adr, port); 75 return sendHTTPRequest("GET", uri, contentType, body, adr, port);
75 } 76 }
76 77
77 -std::string hueplusplus::BaseHttpHandler::POSTString(const std::string& uri, const std::string& contentType, const std::string& body,  
78 - const std::string& adr, int port) const 78 +std::string hueplusplus::BaseHttpHandler::POSTString(const std::string& uri, const std::string& contentType,
  79 + const std::string& body, const std::string& adr, int port) const
79 { 80 {
80 return sendHTTPRequest("POST", uri, contentType, body, adr, port); 81 return sendHTTPRequest("POST", uri, contentType, body, adr, port);
81 } 82 }
82 83
83 -std::string hueplusplus::BaseHttpHandler::PUTString(const std::string& uri, const std::string& contentType, const std::string& body,  
84 - const std::string& adr, int port) const 84 +std::string hueplusplus::BaseHttpHandler::PUTString(const std::string& uri, const std::string& contentType,
  85 + const std::string& body, const std::string& adr, int port) const
85 { 86 {
86 return sendHTTPRequest("PUT", uri, contentType, body, adr, port); 87 return sendHTTPRequest("PUT", uri, contentType, body, adr, port);
87 } 88 }
src/Hue.cpp
@@ -31,9 +31,9 @@ @@ -31,9 +31,9 @@
31 #include <stdexcept> 31 #include <stdexcept>
32 #include <thread> 32 #include <thread>
33 33
34 -#include "hueplusplus/HueDeviceTypes.h"  
35 #include "hueplusplus/ExtendedColorHueStrategy.h" 34 #include "hueplusplus/ExtendedColorHueStrategy.h"
36 #include "hueplusplus/ExtendedColorTemperatureStrategy.h" 35 #include "hueplusplus/ExtendedColorTemperatureStrategy.h"
  36 +#include "hueplusplus/HueDeviceTypes.h"
37 #include "hueplusplus/HueExceptionMacro.h" 37 #include "hueplusplus/HueExceptionMacro.h"
38 #include "hueplusplus/SimpleBrightnessStrategy.h" 38 #include "hueplusplus/SimpleBrightnessStrategy.h"
39 #include "hueplusplus/SimpleColorHueStrategy.h" 39 #include "hueplusplus/SimpleColorHueStrategy.h"
@@ -238,9 +238,8 @@ hueplusplus::HueLight&amp; hueplusplus::Hue::getLight(int id) @@ -238,9 +238,8 @@ hueplusplus::HueLight&amp; hueplusplus::Hue::getLight(int id)
238 // std::cout << state["lights"][std::to_string(id)] << std::endl; 238 // std::cout << state["lights"][std::to_string(id)] << std::endl;
239 std::string type = state["lights"][std::to_string(id)]["modelid"].get<std::string>(); 239 std::string type = state["lights"][std::to_string(id)]["modelid"].get<std::string>();
240 // std::cout << type << std::endl; 240 // std::cout << type << std::endl;
241 - auto light = MakeHueLight()(type, id, commands, simpleBrightnessStrategy,  
242 - extendedColorTemperatureStrategy, simpleColorTemperatureStrategy, extendedColorHueStrategy,  
243 - simpleColorHueStrategy); 241 + auto light = MakeHueLight()(type, id, commands, simpleBrightnessStrategy, extendedColorTemperatureStrategy,
  242 + simpleColorTemperatureStrategy, extendedColorHueStrategy, simpleColorHueStrategy);
244 lights.emplace(id, light); 243 lights.emplace(id, light);
245 return lights.find(id)->second; 244 return lights.find(id)->second;
246 } 245 }
src/HueCommandAPI.cpp
@@ -30,37 +30,36 @@ constexpr std::chrono::steady_clock::duration hueplusplus::HueCommandAPI::minDel @@ -30,37 +30,36 @@ constexpr std::chrono::steady_clock::duration hueplusplus::HueCommandAPI::minDel
30 30
31 namespace 31 namespace
32 { 32 {
33 - // Runs functor with appropriate timeout and retries when timed out or connection reset  
34 - template <typename Timeout, typename Fun>  
35 - nlohmann::json RunWithTimeout(  
36 - std::shared_ptr<Timeout> timeout, std::chrono::steady_clock::duration minDelay, Fun fun) 33 +// Runs functor with appropriate timeout and retries when timed out or connection reset
  34 +template <typename Timeout, typename Fun>
  35 +nlohmann::json RunWithTimeout(std::shared_ptr<Timeout> timeout, std::chrono::steady_clock::duration minDelay, Fun fun)
  36 +{
  37 + auto now = std::chrono::steady_clock::now();
  38 + std::lock_guard<std::mutex> lock(timeout->mutex);
  39 + if (timeout->timeout > now)
37 { 40 {
38 - auto now = std::chrono::steady_clock::now();  
39 - std::lock_guard<std::mutex> lock(timeout->mutex);  
40 - if (timeout->timeout > now)  
41 - {  
42 - std::this_thread::sleep_until(timeout->timeout);  
43 - }  
44 - try  
45 - {  
46 - nlohmann::json response = fun();  
47 - timeout->timeout = now + minDelay;  
48 - return response;  
49 - }  
50 - catch (const std::system_error& e) 41 + std::this_thread::sleep_until(timeout->timeout);
  42 + }
  43 + try
  44 + {
  45 + nlohmann::json response = fun();
  46 + timeout->timeout = now + minDelay;
  47 + return response;
  48 + }
  49 + catch (const std::system_error& e)
  50 + {
  51 + if (e.code() == std::errc::connection_reset || e.code() == std::errc::timed_out)
51 { 52 {
52 - if (e.code() == std::errc::connection_reset || e.code() == std::errc::timed_out)  
53 - {  
54 - // Happens when hue is too busy, wait and try again (once)  
55 - std::this_thread::sleep_for(minDelay);  
56 - nlohmann::json v = fun();  
57 - timeout->timeout = std::chrono::steady_clock::now() + minDelay;  
58 - return v;  
59 - }  
60 - // Cannot recover from other types of errors  
61 - throw; 53 + // Happens when hue is too busy, wait and try again (once)
  54 + std::this_thread::sleep_for(minDelay);
  55 + nlohmann::json v = fun();
  56 + timeout->timeout = std::chrono::steady_clock::now() + minDelay;
  57 + return v;
62 } 58 }
  59 + // Cannot recover from other types of errors
  60 + throw;
63 } 61 }
  62 +}
64 } // namespace 63 } // namespace
65 64
66 hueplusplus::HueCommandAPI::HueCommandAPI( 65 hueplusplus::HueCommandAPI::HueCommandAPI(
src/HueDeviceTypes.cpp
@@ -28,42 +28,42 @@ @@ -28,42 +28,42 @@
28 28
29 namespace 29 namespace
30 { 30 {
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;  
36 - }; 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;
  36 +};
37 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 - } 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 +}
44 44
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 - } 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 +}
51 51
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 - } 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 +}
58 58
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 - } 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", "LTW015",
  63 + "LTP001", "LTP002", "LTP003", "LTP004", "LTP005", "LTD003", "LTF001", "LTF002", "LTC001", "LTC002",
  64 + "LTC003", "LTC004", "LTC011", "LTC012", "LTD001", "LTD002", "LFF001", "LTT001", "LDT001"};
  65 + return c_TEMPERATURELIGHT_TYPES;
  66 +}
67 } // namespace 67 } // namespace
68 68
69 auto hueplusplus::MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands, 69 auto hueplusplus::MakeHueLight::operator()(std::string type, int id, HueCommandAPI commands,
src/HueException.cpp
@@ -69,7 +69,8 @@ const std::string&amp; hueplusplus::HueAPIResponseException::GetDescription() const @@ -69,7 +69,8 @@ const std::string&amp; hueplusplus::HueAPIResponseException::GetDescription() const
69 return description; 69 return description;
70 } 70 }
71 71
72 -hueplusplus::HueAPIResponseException hueplusplus::HueAPIResponseException::Create(FileInfo fileInfo, const nlohmann::json& response) 72 +hueplusplus::HueAPIResponseException hueplusplus::HueAPIResponseException::Create(
  73 + FileInfo fileInfo, const nlohmann::json& response)
73 { 74 {
74 const nlohmann::json error = response.at("error"); 75 const nlohmann::json error = response.at("error");
75 int errorCode = error.value("type", -1); 76 int errorCode = error.value("type", -1);
@@ -78,7 +79,8 @@ hueplusplus::HueAPIResponseException hueplusplus::HueAPIResponseException::Creat @@ -78,7 +79,8 @@ hueplusplus::HueAPIResponseException hueplusplus::HueAPIResponseException::Creat
78 return HueAPIResponseException(std::move(fileInfo), errorCode, std::move(address), std::move(description)); 79 return HueAPIResponseException(std::move(fileInfo), errorCode, std::move(address), std::move(description));
79 } 80 }
80 81
81 -std::string hueplusplus::HueAPIResponseException::GetMessage(int error, const std::string& addr, const std::string& description) 82 +std::string hueplusplus::HueAPIResponseException::GetMessage(
  83 + int error, const std::string& addr, const std::string& description)
82 { 84 {
83 std::string result = std::to_string(error); 85 std::string result = std::to_string(error);
84 result.append(" "); 86 result.append(" ");
src/HueLight.cpp
@@ -161,9 +161,12 @@ bool hueplusplus::HueLight::alert() @@ -161,9 +161,12 @@ bool hueplusplus::HueLight::alert()
161 return utils::validateReplyForLight(request, reply, id); 161 return utils::validateReplyForLight(request, reply, id);
162 } 162 }
163 163
164 -hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands) : HueLight(id, commands, nullptr, nullptr, nullptr) {} 164 +hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands)
  165 + : HueLight(id, commands, nullptr, nullptr, nullptr)
  166 +{}
165 167
166 -hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy, 168 +hueplusplus::HueLight::HueLight(int id, const HueCommandAPI& commands,
  169 + std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
167 std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy, 170 std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
168 std::shared_ptr<const ColorHueStrategy> colorHueStrategy) 171 std::shared_ptr<const ColorHueStrategy> colorHueStrategy)
169 : id(id), 172 : id(id),
@@ -224,7 +227,8 @@ bool hueplusplus::HueLight::OffNoRefresh(uint8_t transition) @@ -224,7 +227,8 @@ bool hueplusplus::HueLight::OffNoRefresh(uint8_t transition)
224 return utils::validateReplyForLight(request, reply, id); 227 return utils::validateReplyForLight(request, reply, id);
225 } 228 }
226 229
227 -nlohmann::json hueplusplus::HueLight::SendPutRequest(const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo) 230 +nlohmann::json hueplusplus::HueLight::SendPutRequest(
  231 + const nlohmann::json& request, const std::string& subPath, FileInfo fileInfo)
228 { 232 {
229 return commands.PUTRequest("/lights/" + std::to_string(id) + subPath, request, std::move(fileInfo)); 233 return commands.PUTRequest("/lights/" + std::to_string(id) + subPath, request, std::move(fileInfo));
230 } 234 }
src/SimpleColorHueStrategy.cpp
@@ -93,7 +93,8 @@ bool hueplusplus::SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_ @@ -93,7 +93,8 @@ bool hueplusplus::SimpleColorHueStrategy::setColorSaturation(uint8_t sat, uint8_
93 return utils::validateReplyForLight(request, reply, light.id); 93 return utils::validateReplyForLight(request, reply, light.id);
94 } 94 }
95 95
96 -bool hueplusplus::SimpleColorHueStrategy::setColorHueSaturation(uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const 96 +bool hueplusplus::SimpleColorHueStrategy::setColorHueSaturation(
  97 + uint16_t hue, uint8_t sat, uint8_t transition, HueLight& light) const
97 { 98 {
98 light.refreshState(); 99 light.refreshState();
99 nlohmann::json request = nlohmann::json::object(); 100 nlohmann::json request = nlohmann::json::object();
@@ -165,7 +166,8 @@ bool hueplusplus::SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t t @@ -165,7 +166,8 @@ bool hueplusplus::SimpleColorHueStrategy::setColorXY(float x, float y, uint8_t t
165 return utils::validateReplyForLight(request, reply, light.id); 166 return utils::validateReplyForLight(request, reply, light.id);
166 } 167 }
167 168
168 -bool hueplusplus::SimpleColorHueStrategy::setColorRGB(uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const 169 +bool hueplusplus::SimpleColorHueStrategy::setColorRGB(
  170 + uint8_t r, uint8_t g, uint8_t b, uint8_t transition, HueLight& light) const
169 { 171 {
170 if ((r == 0) && (g == 0) && (b == 0)) 172 if ((r == 0) && (g == 0) && (b == 0))
171 { 173 {
src/SimpleColorTemperatureStrategy.cpp
@@ -30,7 +30,8 @@ @@ -30,7 +30,8 @@
30 #include "hueplusplus/HueExceptionMacro.h" 30 #include "hueplusplus/HueExceptionMacro.h"
31 #include "hueplusplus/Utils.h" 31 #include "hueplusplus/Utils.h"
32 32
33 -bool hueplusplus::SimpleColorTemperatureStrategy::setColorTemperature(unsigned int mired, uint8_t transition, HueLight& light) const 33 +bool hueplusplus::SimpleColorTemperatureStrategy::setColorTemperature(
  34 + unsigned int mired, uint8_t transition, HueLight& light) const
34 { 35 {
35 light.refreshState(); 36 light.refreshState();
36 nlohmann::json request = nlohmann::json::object(); 37 nlohmann::json request = nlohmann::json::object();
src/UPnP.cpp
@@ -25,7 +25,8 @@ @@ -25,7 +25,8 @@
25 #include <algorithm> 25 #include <algorithm>
26 #include <iostream> 26 #include <iostream>
27 27
28 -std::vector<std::pair<std::string, std::string>> hueplusplus::UPnP::getDevices(std::shared_ptr<const IHttpHandler> handler) 28 +std::vector<std::pair<std::string, std::string>> hueplusplus::UPnP::getDevices(
  29 + std::shared_ptr<const IHttpHandler> handler)
29 { 30 {
30 // send UPnP M-Search request 31 // send UPnP M-Search request
31 std::vector<std::string> foundDevices 32 std::vector<std::string> foundDevices
src/WinHttpHandler.cpp
@@ -34,24 +34,24 @@ @@ -34,24 +34,24 @@
34 34
35 namespace 35 namespace
36 { 36 {
37 - class AddrInfoFreer  
38 - {  
39 - public:  
40 - explicit AddrInfoFreer(addrinfo* p) : p(p) {}  
41 - ~AddrInfoFreer() { freeaddrinfo(p); }  
42 -  
43 - private:  
44 - addrinfo* p;  
45 - };  
46 - class SocketCloser  
47 - {  
48 - public:  
49 - explicit SocketCloser(SOCKET s) : s(s) {}  
50 - ~SocketCloser() { closesocket(s); } 37 +class AddrInfoFreer
  38 +{
  39 +public:
  40 + explicit AddrInfoFreer(addrinfo* p) : p(p) {}
  41 + ~AddrInfoFreer() { freeaddrinfo(p); }
  42 +
  43 +private:
  44 + addrinfo* p;
  45 +};
  46 +class SocketCloser
  47 +{
  48 +public:
  49 + explicit SocketCloser(SOCKET s) : s(s) {}
  50 + ~SocketCloser() { closesocket(s); }
51 51
52 - private:  
53 - SOCKET s;  
54 - }; 52 +private:
  53 + SOCKET s;
  54 +};
55 } // namespace 55 } // namespace
56 56
57 hueplusplus::WinHttpHandler::WinHttpHandler() 57 hueplusplus::WinHttpHandler::WinHttpHandler()
test/mocks/mock_HueLight.h
@@ -28,16 +28,16 @@ @@ -28,16 +28,16 @@
28 28
29 #include <gmock/gmock.h> 29 #include <gmock/gmock.h>
30 30
  31 +#include "../testhelper.h"
31 #include "hueplusplus/HueLight.h" 32 #include "hueplusplus/HueLight.h"
32 #include "json/json.hpp" 33 #include "json/json.hpp"
33 -#include "../testhelper.h"  
34 34
35 //! Mock Class 35 //! Mock Class
36 class MockHueLight : public hueplusplus::HueLight 36 class MockHueLight : public hueplusplus::HueLight
37 { 37 {
38 public: 38 public:
39 MockHueLight(std::shared_ptr<const hueplusplus::IHttpHandler> handler) 39 MockHueLight(std::shared_ptr<const hueplusplus::IHttpHandler> handler)
40 - : HueLight(1, hueplusplus::HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)) {}; 40 + : HueLight(1, hueplusplus::HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler)){};
41 41
42 nlohmann::json& getState() { return state; }; 42 nlohmann::json& getState() { return state; };
43 43
@@ -125,8 +125,8 @@ public: @@ -125,8 +125,8 @@ public:
125 125
126 MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition)); 126 MOCK_METHOD1(OffNoRefresh, bool(uint8_t transition));
127 127
128 - MOCK_METHOD3(  
129 - SendPutRequest, nlohmann::json(const nlohmann::json& request, const std::string& subPath, hueplusplus::FileInfo fileInfo)); 128 + MOCK_METHOD3(SendPutRequest,
  129 + nlohmann::json(const nlohmann::json& request, const std::string& subPath, hueplusplus::FileInfo fileInfo));
130 130
131 MOCK_METHOD0(refreshState, void()); 131 MOCK_METHOD0(refreshState, void());
132 }; 132 };
test/test_BaseHttpHandler.cpp
@@ -28,9 +28,9 @@ @@ -28,9 +28,9 @@
28 28
29 #include "testhelper.h" 29 #include "testhelper.h"
30 30
  31 +#include "hueplusplus/HueException.h"
31 #include "json/json.hpp" 32 #include "json/json.hpp"
32 #include "mocks/mock_BaseHttpHandler.h" 33 #include "mocks/mock_BaseHttpHandler.h"
33 -#include "hueplusplus/HueException.h"  
34 34
35 using namespace hueplusplus; 35 using namespace hueplusplus;
36 36
test/test_Hue.cpp
@@ -378,14 +378,14 @@ TEST(Hue, removeLight) @@ -378,14 +378,14 @@ TEST(Hue, removeLight)
378 { 378 {
379 using namespace ::testing; 379 using namespace ::testing;
380 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); 380 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>();
381 - nlohmann::json hue_bridge_state{ {"lights", 381 + nlohmann::json hue_bridge_state{{"lights",
382 {{"1", 382 {{"1",
383 {{"state", 383 {{"state",
384 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, 384 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
385 {"reachable", true}}}, 385 {"reachable", true}}},
386 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, 386 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
387 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, 387 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
388 - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; 388 + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
389 EXPECT_CALL( 389 EXPECT_CALL(
390 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) 390 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
391 .Times(1) 391 .Times(1)
@@ -421,14 +421,14 @@ TEST(Hue, getAllLights) @@ -421,14 +421,14 @@ TEST(Hue, getAllLights)
421 { 421 {
422 using namespace ::testing; 422 using namespace ::testing;
423 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); 423 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>();
424 - nlohmann::json hue_bridge_state{ {"lights", 424 + nlohmann::json hue_bridge_state{{"lights",
425 {{"1", 425 {{"1",
426 {{"state", 426 {{"state",
427 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, 427 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
428 {"reachable", true}}}, 428 {"reachable", true}}},
429 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, 429 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
430 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, 430 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
431 - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; 431 + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
432 432
433 EXPECT_CALL( 433 EXPECT_CALL(
434 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) 434 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
@@ -452,14 +452,14 @@ TEST(Hue, lightExists) @@ -452,14 +452,14 @@ TEST(Hue, lightExists)
452 { 452 {
453 using namespace ::testing; 453 using namespace ::testing;
454 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); 454 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>();
455 - nlohmann::json hue_bridge_state{ {"lights", 455 + nlohmann::json hue_bridge_state{{"lights",
456 {{"1", 456 {{"1",
457 {{"state", 457 {{"state",
458 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, 458 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
459 {"reachable", true}}}, 459 {"reachable", true}}},
460 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, 460 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
461 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, 461 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
462 - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; 462 + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
463 EXPECT_CALL( 463 EXPECT_CALL(
464 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) 464 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
465 .Times(AtLeast(2)) 465 .Times(AtLeast(2))
@@ -488,14 +488,14 @@ TEST(Hue, getPictureOfLight) @@ -488,14 +488,14 @@ TEST(Hue, getPictureOfLight)
488 { 488 {
489 using namespace ::testing; 489 using namespace ::testing;
490 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>(); 490 std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>();
491 - nlohmann::json hue_bridge_state{ {"lights", 491 + nlohmann::json hue_bridge_state{{"lights",
492 {{"1", 492 {{"1",
493 {{"state", 493 {{"state",
494 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, 494 {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"},
495 {"reachable", true}}}, 495 {"reachable", true}}},
496 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"}, 496 {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color temperature light"},
497 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, 497 {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"},
498 - {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}} }; 498 + {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}}}}}};
499 499
500 EXPECT_CALL( 500 EXPECT_CALL(
501 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) 501 *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort()))
test/test_HueCommandAPI.cpp
@@ -163,7 +163,7 @@ TEST(HueCommandAPI, GETRequest) @@ -163,7 +163,7 @@ TEST(HueCommandAPI, GETRequest)
163 // api returns error 163 // api returns error
164 { 164 {
165 const std::string path = "/test"; 165 const std::string path = "/test";
166 - const nlohmann::json errorResponse{ {"error", {{"type", 10}, {"address", path}, {"description", "Stuff"}}} }; 166 + const nlohmann::json errorResponse{{"error", {{"type", 10}, {"address", path}, {"description", "Stuff"}}}};
167 EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) 167 EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80))
168 .WillOnce(Return(errorResponse)); 168 .WillOnce(Return(errorResponse));
169 EXPECT_THROW(api.GETRequest(path, request), HueAPIResponseException); 169 EXPECT_THROW(api.GETRequest(path, request), HueAPIResponseException);
@@ -233,7 +233,7 @@ TEST(HueCommandAPI, DELETERequest) @@ -233,7 +233,7 @@ TEST(HueCommandAPI, DELETERequest)
233 // api returns error 233 // api returns error
234 { 234 {
235 const std::string path = "/test"; 235 const std::string path = "/test";
236 - const nlohmann::json errorResponse{ {"error", {{"type", 10}, {"address", path}, {"description", "Stuff"}}} }; 236 + const nlohmann::json errorResponse{{"error", {{"type", 10}, {"address", path}, {"description", "Stuff"}}}};
237 EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) 237 EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80))
238 .WillOnce(Return(errorResponse)); 238 .WillOnce(Return(errorResponse));
239 EXPECT_THROW(api.DELETERequest(path, request), HueAPIResponseException); 239 EXPECT_THROW(api.DELETERequest(path, request), HueAPIResponseException);
test/test_HueLight.cpp
@@ -123,7 +123,7 @@ protected: @@ -123,7 +123,7 @@ protected:
123 .Times(AtLeast(1)) 123 .Times(AtLeast(1))
124 .WillRepeatedly(Return(hue_bridge_state["lights"]["3"])); 124 .WillRepeatedly(Return(hue_bridge_state["lights"]["3"]));
125 } 125 }
126 - ~HueLightTest() {}; 126 + ~HueLightTest(){};
127 }; 127 };
128 128
129 TEST_F(HueLightTest, Constructor) 129 TEST_F(HueLightTest, Constructor)