Commit c24d3db5d7a75a885f5213f3027d8d38b2b9eb8d
Committed by
Moritz Wirger
1 parent
76ac2c83
Add documentation for CLIP sensors.
Showing
2 changed files
with
139 additions
and
0 deletions
include/hueplusplus/CLIPSensors.h
| @@ -28,116 +28,254 @@ namespace hueplusplus | @@ -28,116 +28,254 @@ namespace hueplusplus | ||
| 28 | { | 28 | { |
| 29 | namespace sensors | 29 | namespace sensors |
| 30 | { | 30 | { |
| 31 | +//! \brief Common methods for CLIP sensors | ||
| 31 | class BaseCLIP : public BaseDevice | 32 | class BaseCLIP : public BaseDevice |
| 32 | { | 33 | { |
| 33 | public: | 34 | public: |
| 35 | + //! \brief Check if sensor is on | ||
| 36 | + //! | ||
| 37 | + //! Sensors which are off do not change their status | ||
| 34 | bool isOn() const; | 38 | bool isOn() const; |
| 39 | + //! \brief Enable or disable sensor | ||
| 40 | + //! \throws std::system_error when system or socket operations fail | ||
| 41 | + //! \throws HueException when response contained no body | ||
| 42 | + //! \throws HueAPIResponseException when response contains an error | ||
| 43 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 35 | void setOn(bool on); | 44 | void setOn(bool on); |
| 36 | 45 | ||
| 46 | + //! \brief Get whether sensor has a battery state | ||
| 37 | bool hasBatteryState() const; | 47 | bool hasBatteryState() const; |
| 48 | + //! \brief Get battery state | ||
| 49 | + //! \returns Battery state in percent | ||
| 50 | + //! \throws nlohmann::json::out_of_range when sensor has no battery state. | ||
| 38 | int getBatteryState() const; | 51 | int getBatteryState() const; |
| 52 | + //! \brief Set battery state | ||
| 53 | + //! \throws std::system_error when system or socket operations fail | ||
| 54 | + //! \throws HueException when response contained no body | ||
| 55 | + //! \throws HueAPIResponseException when response contains an error | ||
| 56 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 39 | void setBatteryState(int percent); | 57 | void setBatteryState(int percent); |
| 40 | 58 | ||
| 59 | + //! \brief Get whether sensor is reachable | ||
| 60 | + //! \note Reachable verification is not implemented for CLIP sensors yet | ||
| 41 | bool isReachable() const; | 61 | bool isReachable() const; |
| 42 | 62 | ||
| 63 | + //! \brief Get whether sensor has a URL | ||
| 43 | bool hasURL() const; | 64 | bool hasURL() const; |
| 65 | + //! \brief Get sensor URL | ||
| 44 | std::string getURL() const; | 66 | std::string getURL() const; |
| 67 | + //! \brief Set sensor URL | ||
| 68 | + //! \throws std::system_error when system or socket operations fail | ||
| 69 | + //! \throws HueException when response contained no body | ||
| 70 | + //! \throws HueAPIResponseException when response contains an error | ||
| 71 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 45 | void setURL(const std::string& url); | 72 | void setURL(const std::string& url); |
| 46 | 73 | ||
| 74 | + //! \brief Get time of last status update | ||
| 75 | + //! \returns The last update time, or a time with a zero duration from epoch | ||
| 76 | + //! if the last update time is not set. | ||
| 47 | time::AbsoluteTime getLastUpdated() const; | 77 | time::AbsoluteTime getLastUpdated() const; |
| 48 | 78 | ||
| 49 | protected: | 79 | protected: |
| 80 | + //! \brief Protected constructor to be used by subclasses | ||
| 50 | explicit BaseCLIP(Sensor sensor) : BaseDevice(std::move(sensor)) { } | 81 | explicit BaseCLIP(Sensor sensor) : BaseDevice(std::move(sensor)) { } |
| 51 | }; | 82 | }; |
| 52 | 83 | ||
| 84 | +//! \brief CLIP sensor for button presses | ||
| 53 | class CLIPSwitch : public BaseCLIP | 85 | class CLIPSwitch : public BaseCLIP |
| 54 | { | 86 | { |
| 55 | public: | 87 | public: |
| 88 | + //! \brief Construct from generic sensor | ||
| 56 | explicit CLIPSwitch(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 89 | explicit CLIPSwitch(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 57 | 90 | ||
| 91 | + //! \brief Get the code of the last switch event. | ||
| 58 | int getButtonEvent() const; | 92 | int getButtonEvent() const; |
| 93 | + //! \brief Set the button event code | ||
| 94 | + //! \throws std::system_error when system or socket operations fail | ||
| 95 | + //! \throws HueException when response contained no body | ||
| 96 | + //! \throws HueAPIResponseException when response contains an error | ||
| 97 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 59 | void setButtonEvent(int code); | 98 | void setButtonEvent(int code); |
| 60 | 99 | ||
| 100 | + //! \brief CLIPSwitch sensor type name | ||
| 61 | static constexpr const char* typeStr = "CLIPSwitch"; | 101 | static constexpr const char* typeStr = "CLIPSwitch"; |
| 62 | }; | 102 | }; |
| 103 | + | ||
| 104 | +//! \brief CLIP sensor detecting whether a contact is open or closed | ||
| 63 | class CLIPOpenClose : public BaseCLIP | 105 | class CLIPOpenClose : public BaseCLIP |
| 64 | { | 106 | { |
| 65 | public: | 107 | public: |
| 108 | + //! \brief Construct from generic sensor | ||
| 66 | explicit CLIPOpenClose(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 109 | explicit CLIPOpenClose(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 67 | 110 | ||
| 111 | + //! \brief Get whether switch is open | ||
| 68 | bool isOpen() const; | 112 | bool isOpen() const; |
| 113 | + //! \brief Set switch state | ||
| 114 | + //! | ||
| 115 | + //! The sensor needs to stay in a state for at least 1s. | ||
| 116 | + //! \throws std::system_error when system or socket operations fail | ||
| 117 | + //! \throws HueException when response contained no body | ||
| 118 | + //! \throws HueAPIResponseException when response contains an error | ||
| 119 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 69 | void setOpen(bool open); | 120 | void setOpen(bool open); |
| 70 | 121 | ||
| 122 | + //! \brief CLIPOpenClose sensor type name | ||
| 71 | static constexpr const char* typeStr = "CLIPOpenClose"; | 123 | static constexpr const char* typeStr = "CLIPOpenClose"; |
| 72 | }; | 124 | }; |
| 73 | 125 | ||
| 126 | +//! \brief CLIP sensor to detect presence | ||
| 74 | class CLIPPresence : public BaseCLIP | 127 | class CLIPPresence : public BaseCLIP |
| 75 | { | 128 | { |
| 76 | public: | 129 | public: |
| 130 | + //! \brief Construct from generic sensor | ||
| 77 | explicit CLIPPresence(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 131 | explicit CLIPPresence(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 78 | 132 | ||
| 133 | + //! \brief Get whether presence was dtected | ||
| 79 | bool getPresence() const; | 134 | bool getPresence() const; |
| 135 | + //! \brief Set presence state | ||
| 136 | + //! \throws std::system_error when system or socket operations fail | ||
| 137 | + //! \throws HueException when response contained no body | ||
| 138 | + //! \throws HueAPIResponseException when response contains an error | ||
| 139 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 80 | void setPresence(bool presence); | 140 | void setPresence(bool presence); |
| 81 | 141 | ||
| 142 | + //! \brief CLIPPresence sensor type name | ||
| 82 | static constexpr const char* typeStr = "CLIPPresence"; | 143 | static constexpr const char* typeStr = "CLIPPresence"; |
| 83 | }; | 144 | }; |
| 84 | 145 | ||
| 146 | +//! \brief CLIP sensor for temperature | ||
| 85 | class CLIPTemperature : public BaseCLIP | 147 | class CLIPTemperature : public BaseCLIP |
| 86 | { | 148 | { |
| 87 | public: | 149 | public: |
| 150 | + //! \brief Construct from generic sensor | ||
| 88 | explicit CLIPTemperature(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 151 | explicit CLIPTemperature(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 89 | 152 | ||
| 153 | + //! \brief Get measured temperature | ||
| 154 | + //! \returns Temperature in 0.01 degrees Celsius. | ||
| 90 | int getTemperature() const; | 155 | int getTemperature() const; |
| 156 | + //! \brief Set temperature | ||
| 157 | + //! \param temperature Temperature in 0.01 degreese Celsius. | ||
| 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 | ||
| 91 | void setTemperature(int temperature); | 162 | void setTemperature(int temperature); |
| 92 | 163 | ||
| 164 | + //! \brief CLIPTemperature sensor type name | ||
| 93 | static constexpr const char* typeStr = "CLIPTemperature"; | 165 | static constexpr const char* typeStr = "CLIPTemperature"; |
| 94 | }; | 166 | }; |
| 167 | + | ||
| 168 | +//! \brief CLIP sensor for humidity | ||
| 95 | class CLIPHumidity : public BaseCLIP | 169 | class CLIPHumidity : public BaseCLIP |
| 96 | { | 170 | { |
| 97 | public: | 171 | public: |
| 172 | + //! \brief Construct from generic sensor | ||
| 98 | explicit CLIPHumidity(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 173 | explicit CLIPHumidity(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 99 | 174 | ||
| 175 | + //! \brief Get measured humidity | ||
| 176 | + //! \returns Humidity in 0.01% steps | ||
| 100 | int getHumidity() const; | 177 | int getHumidity() const; |
| 178 | + //! \brief Set humidity | ||
| 179 | + //! \param humidity Humidity in 0.01% | ||
| 180 | + //! \throws std::system_error when system or socket operations fail | ||
| 181 | + //! \throws HueException when response contained no body | ||
| 182 | + //! \throws HueAPIResponseException when response contains an error | ||
| 183 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 101 | void setHumidity(int humidity); | 184 | void setHumidity(int humidity); |
| 102 | 185 | ||
| 186 | + //! \brief CLIPHumidity sensor type name | ||
| 103 | static constexpr const char* typeStr = "CLIPHumidity"; | 187 | static constexpr const char* typeStr = "CLIPHumidity"; |
| 104 | }; | 188 | }; |
| 189 | + | ||
| 190 | +//! \brief CLIP sensor for light level | ||
| 105 | class CLIPLightLevel : public BaseCLIP | 191 | class CLIPLightLevel : public BaseCLIP |
| 106 | { | 192 | { |
| 107 | public: | 193 | public: |
| 194 | + //! \brief Construct from generic sensor | ||
| 108 | explicit CLIPLightLevel(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 195 | explicit CLIPLightLevel(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 109 | 196 | ||
| 197 | + //! \brief Get threshold to detect darkness | ||
| 110 | int getDarkThreshold() const; | 198 | int getDarkThreshold() const; |
| 199 | + //! \brief Set threshold to detect darkness | ||
| 200 | + //! \param threshold Light level as reported by \ref getLightLevel | ||
| 201 | + //! \throws std::system_error when system or socket operations fail | ||
| 202 | + //! \throws HueException when response contained no body | ||
| 203 | + //! \throws HueAPIResponseException when response contains an error | ||
| 204 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 111 | void setDarkThreshold(int threshold); | 205 | void setDarkThreshold(int threshold); |
| 112 | 206 | ||
| 207 | + //! \brief Get offset over dark threshold to detect daylight | ||
| 113 | int getThresholdOffset() const; | 208 | int getThresholdOffset() const; |
| 209 | + //! \brief Set offset to detect daylight | ||
| 210 | + //! \param offset Offset to dark threshold to detect daylight. Must be greater than 1. | ||
| 211 | + //! \throws std::system_error when system or socket operations fail | ||
| 212 | + //! \throws HueException when response contained no body | ||
| 213 | + //! \throws HueAPIResponseException when response contains an error | ||
| 214 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 114 | void setThresholdOffset(int offset); | 215 | void setThresholdOffset(int offset); |
| 115 | 216 | ||
| 217 | + //! \brief Get measured light level | ||
| 218 | + //! \returns Light level in <code>10000*log10(lux)+1</code> (logarithmic scale) | ||
| 116 | int getLightLevel() const; | 219 | int getLightLevel() const; |
| 220 | + //! \brief Set measured light level | ||
| 221 | + //! \param level Light level in <code>10000*log10(lux)+1</code> | ||
| 222 | + //! \throws std::system_error when system or socket operations fail | ||
| 223 | + //! \throws HueException when response contained no body | ||
| 224 | + //! \throws HueAPIResponseException when response contains an error | ||
| 225 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 117 | void setLightLevel(int level); | 226 | void setLightLevel(int level); |
| 227 | + //! \brief Check whether light level is below dark threshold | ||
| 118 | bool isDark() const; | 228 | bool isDark() const; |
| 229 | + //! \brief Check whether light level is above light threshold | ||
| 230 | + //! | ||
| 231 | + //! Light threshold is dark threshold + offset | ||
| 119 | bool isDaylight() const; | 232 | bool isDaylight() const; |
| 120 | 233 | ||
| 234 | + //! \brief CLIPLightLevel sensor type name | ||
| 121 | static constexpr const char* typeStr = "CLIPLightLevel"; | 235 | static constexpr const char* typeStr = "CLIPLightLevel"; |
| 122 | }; | 236 | }; |
| 237 | + | ||
| 238 | +//! \brief CLIP sensor for a generic 3rd party sensor. | ||
| 239 | +//! | ||
| 240 | +//! Can be created by POST. | ||
| 123 | class CLIPGenericFlag : public BaseCLIP | 241 | class CLIPGenericFlag : public BaseCLIP |
| 124 | { | 242 | { |
| 125 | public: | 243 | public: |
| 244 | + //! \brief Construct from generic sensor | ||
| 126 | explicit CLIPGenericFlag(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 245 | explicit CLIPGenericFlag(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 127 | 246 | ||
| 247 | + //! \brief Get boolean flag | ||
| 128 | bool getFlag() const; | 248 | bool getFlag() const; |
| 249 | + //! \brief Set flag | ||
| 250 | + //! \throws std::system_error when system or socket operations fail | ||
| 251 | + //! \throws HueException when response contained no body | ||
| 252 | + //! \throws HueAPIResponseException when response contains an error | ||
| 253 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 129 | void setFlag(bool flag); | 254 | void setFlag(bool flag); |
| 130 | 255 | ||
| 256 | + //! \brief CLIPGenericFlag sensor type name | ||
| 131 | static constexpr const char* typeStr = "CLIPGenericFlag"; | 257 | static constexpr const char* typeStr = "CLIPGenericFlag"; |
| 132 | }; | 258 | }; |
| 259 | + | ||
| 260 | +//! \brief CLIP sensor for a generic 3rd party status | ||
| 261 | +//! | ||
| 262 | +//! Can be created by POST. | ||
| 133 | class CLIPGenericStatus : public BaseCLIP | 263 | class CLIPGenericStatus : public BaseCLIP |
| 134 | { | 264 | { |
| 135 | public: | 265 | public: |
| 266 | + //! \brief Construct from generic sensor | ||
| 136 | explicit CLIPGenericStatus(Sensor sensor) : BaseCLIP(std::move(sensor)) { } | 267 | explicit CLIPGenericStatus(Sensor sensor) : BaseCLIP(std::move(sensor)) { } |
| 137 | 268 | ||
| 269 | + //! \brief Get sensor status | ||
| 138 | int getStatus() const; | 270 | int getStatus() const; |
| 271 | + //! \brief Set sensor status | ||
| 272 | + //! \throws std::system_error when system or socket operations fail | ||
| 273 | + //! \throws HueException when response contained no body | ||
| 274 | + //! \throws HueAPIResponseException when response contains an error | ||
| 275 | + //! \throws nlohmann::json::parse_error when response could not be parsed | ||
| 139 | void setStatus(int status); | 276 | void setStatus(int status); |
| 140 | 277 | ||
| 278 | + //! \brief CLIPGenericStatus sensor type name | ||
| 141 | static constexpr const char* typeStr = "CLIPGenericStatus"; | 279 | static constexpr const char* typeStr = "CLIPGenericStatus"; |
| 142 | }; | 280 | }; |
| 143 | } // namespace sensors | 281 | } // namespace sensors |
include/hueplusplus/ZLLSensors.h
| @@ -243,6 +243,7 @@ public: | @@ -243,6 +243,7 @@ public: | ||
| 243 | bool isReachable() const; | 243 | bool isReachable() const; |
| 244 | 244 | ||
| 245 | //! \brief Get recorded temperature | 245 | //! \brief Get recorded temperature |
| 246 | + //! \returns Temperature in 0.01 degrees Celsius. | ||
| 246 | int getTemperature() const; | 247 | int getTemperature() const; |
| 247 | 248 | ||
| 248 | //! \brief ZLLTemperature sensor type name | 249 | //! \brief ZLLTemperature sensor type name |