Commit 2f28783458c773dae5870a12c9763e7bc4443ba4

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent 2578f2b7

Add documentation for Scene class.

include/hueplusplus/Hue.h
... ... @@ -324,7 +324,7 @@ public:
324 324 bool scheduleExists(int id) const;
325 325  
326 326 //! \brief Create a new schedule.
327   - //! \param params CreateSchedule parameters for the new group.
  327 + //! \param params CreateSchedule parameters for the new schedule.
328 328 //! \returns The new schedule id or 0 if failed.
329 329 //! \throws std::system_error when system or socket operations fail
330 330 //! \throws HueException when response contains no body
... ... @@ -336,12 +336,37 @@ public:
336 336 ///! \name Scenes
337 337 ///@{
338 338  
  339 + //! \brief Get all scenes on this bridge.
  340 + //! \return A vector of references to every Scene.
  341 + //! \throws std::system_error when system or socket operations fail
  342 + //! \throws HueException when response contains no body
  343 + //! \throws HueAPIResponseException when response contains an error
  344 + //! \throws nlohmann::json::parse_error when response could not be parsed
339 345 std::vector<std::reference_wrapper<Scene>> getAllScenes();
340 346  
  347 + //! \brief Get scene specified by id.
  348 + //! \param id ID of the scene.
  349 + //! \returns Schedule that can be modified.
  350 + //! \throws std::system_error when system or socket operations fail
  351 + //! \throws HueException when id does not exist
  352 + //! \throws HueAPIResponseException when response contains an error
  353 + //! \throws nlohmann::json::parse_error when response could not be parsed
341 354 Scene& getScene(const std::string& id);
342 355  
  356 +
  357 + //! \brief Checks whether a scene exists.
  358 + //! \param id ID of the scene.
  359 + //! \returns true when the scene exists.
  360 + //! \note Does not refresh the cached state.
343 361 bool sceneExists(const std::string& id) const;
344 362  
  363 + //! \brief Create a new scene.
  364 + //! \param params CreateScene parameters for the new scene.
  365 + //! \returns The new scene id or 0 if failed.
  366 + //! \throws std::system_error when system or socket operations fail
  367 + //! \throws HueException when response contains no body
  368 + //! \throws HueAPIResponseException when response contains an error
  369 + //! \throws nlohmann::json::parse_error when response could not be parsed
345 370 std::string createScene(const CreateScene& params);
346 371  
347 372 ///@}
... ...
include/hueplusplus/HueLight.h
... ... @@ -201,6 +201,8 @@ public:
201 201 //! \return ColorType containig the color type of the light
202 202 virtual ColorType getColorType() const;
203 203  
  204 + //! \brief Get gamut space of possible light colors
  205 + //! \returns Used gamut, or \ref gamut::maxGamut when unknown.
204 206 ColorGamut getColorGamut() const;
205 207  
206 208 ///@}
... ...
include/hueplusplus/ModelPictures.h
... ... @@ -30,7 +30,7 @@ namespace hueplusplus
30 30 //!
31 31 //! \note This function will only return the filename without extension,
32 32 //! because Philips provides different file types.
33   - //! \param model_id Model Id of a device to get the picture of
  33 + //! \param modelId Model Id of a device to get the picture of
34 34 //! \returns String that either contains the filename of the picture of the device
35 35 //! or an empty string if it was not found.
36 36 std::string getPictureOfModel(const std::string& modelId);
... ...
include/hueplusplus/ResourceList.h
... ... @@ -73,7 +73,7 @@ public:
73 73 //! \brief Deleted copy constructor
74 74 ResourceList(const ResourceList&) = delete;
75 75 //! \brief Defaulted move constructor
76   - ResourceList(ResourceList&&) noexcept = default;
  76 + ResourceList(ResourceList&&) = default;
77 77 //! \brief Deleted copy assignment
78 78 ResourceList& operator=(const ResourceList&) = delete;
79 79 //! \brief Defaulted move assignment
... ... @@ -276,6 +276,10 @@ public:
276 276 }
277 277 };
278 278  
  279 +//! \brief Handles a group list with the special group 0
  280 +//! \tparam Resource Resource type that is in the list
  281 +//! \tparam CreateType Type that provides parameters for creation.
  282 +//! Must have a const getRequest() function returning the JSON for the POST request.
279 283 template <typename Resource, typename CreateType>
280 284 class GroupResourceList : public CreateableResourceList<Resource, int, CreateType>
281 285 {
... ...
include/hueplusplus/Scene.h
... ... @@ -38,30 +38,53 @@ namespace hueplusplus
38 38 class LightState
39 39 {
40 40 public:
  41 + //! \brief Create LightState from json
  42 + //! \note Use LightStateBuilder for easier creation.
41 43 explicit LightState(const nlohmann::json& state);
42 44  
  45 + //! \brief Get whether the light is on
43 46 bool isOn() const;
44 47  
  48 + //! \brief Get whether a brightness is stored
45 49 bool hasBrightness() const;
  50 + //! \brief Get brightness of the light
  51 + //! \returns Stored brightness, or 0
46 52 int getBrightness() const;
47 53  
  54 + //! \brief Get whether hue and saturation is stored
48 55 bool hasHueSat() const;
  56 + //! \brief Get hue and saturation of the light
  57 + //! \returns Stored hue and saturation, or {0,0} if not stored
49 58 HueSaturation getHueSat() const;
50 59  
  60 + //! \brief Get whether xy color is stored
51 61 bool hasXY() const;
  62 + //! \brief Get xy color of the light
  63 + //! \returns Stored x,y and brightness, or zeros if not stored
52 64 XYBrightness getXY() const;
53 65  
  66 + //! \brief Get whether color temperature is stored
54 67 bool hasCt() const;
  68 + //! \brief Get color temperature of the light
  69 + //! \returns Stored color temperature in mired, or 0 if not stored
55 70 int getCt() const;
56 71  
  72 + //! \brief Get whether effect is stored
57 73 bool hasEffect() const;
  74 + //! \brief Get whether colorloop effect is active
  75 + //! \returns true when colorloop is enabled, false otherwise or if not stored
58 76 bool getColorloop() const;
59 77  
  78 + //! \brief Get transition time to this light state
  79 + //! \returns Stored transition time or 4 by default
60 80 int getTransitionTime() const;
61 81  
  82 + //! \brief Convert to json representation
62 83 nlohmann::json toJson() const;
63 84  
  85 + //! \brief Equality comparison
64 86 bool operator==(const LightState& other) const;
  87 + //! \brief Inequality comparison
65 88 bool operator!=(const LightState& other) const;
66 89  
67 90 private:
... ... @@ -86,51 +109,140 @@ private:
86 109 nlohmann::json state;
87 110 };
88 111  
  112 +//! \brief Scene stored in the bridge
  113 +//!
  114 +//! Scenes bundle the state of multiple lights so it can be recalled later.
89 115 class Scene
90 116 {
91 117 public:
  118 + //! \brief Type of the scen
92 119 enum class Type
93 120 {
94   - lightScene,
95   - groupScene
  121 + lightScene, //!< The scene affects specific lights
  122 + groupScene //!< The scene affects all light of a specific group
96 123 };
97 124  
98 125 public:
  126 + //! \brief Construct existing Scene
  127 + //! \param id Scene id
  128 + //! \param commands HueCommandAPI for requests
  129 + //! \param refreshDuration Time between refreshing the cached state
99 130 Scene(const std::string& id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration);
100 131  
  132 + //! \brief Refreshes internal cached state
  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
101 137 void refresh();
  138 +
  139 + //! \brief Get scene identifier
102 140 std::string getId() const;
  141 + //! \brief Get scene name
  142 + //!
  143 + //! The scene name is always unique for the bridge. It defaults to the id.
103 144 std::string getName() const;
  145 + //! \brief Set scene name
  146 + //! \param name New name for the scene.
  147 + //! Must be unique for all schedules, otherwise a number is added.
  148 + //! \throws std::system_error when system or socket operations fail
  149 + //! \throws HueException when response contained no body
  150 + //! \throws HueAPIResponseException when response contains an error
  151 + //! \throws nlohmann::json::parse_error when response could not be parsed
104 152 void setName(const std::string& name);
105   -
  153 + //! \brief Get scene type
  154 + //!
  155 + //! GroupScenes are deleted when the group is deleted.
106 156 Type getType() const;
107 157  
  158 + //! \brief Get group id for a GroupScene
  159 + //! \returns Group id or 0 if the scene is a LightScene.
108 160 int getGroupId() const;
109 161  
  162 + //! \brief Get light ids
  163 + //!
  164 + //! For a GroupScene, the light ids are the lights in the group.
110 165 std::vector<int> getLightIds() const;
  166 + //! \brief Set light ids for LightScene
  167 + //! \param ids New light ids
  168 + //!
  169 + //! Light ids cannot be changed on GroupScene. Change the lights in the group instead.
  170 + //! \throws std::system_error when system or socket operations fail
  171 + //! \throws HueException when response contained no body
  172 + //! \throws HueAPIResponseException when response contains an error
  173 + //! \throws nlohmann::json::parse_error when response could not be parsed
111 174 void setLightIds(const std::vector<int>& ids);
112 175  
  176 + //! \brief Get user that created or last changed the scene.
113 177 std::string getOwner() const;
  178 + //! \brief Get whether the scene can be automatically deleted
114 179 bool getRecycle() const;
  180 + //! \brief Get whether scene is locked by a rule or schedule
115 181 bool isLocked() const;
116 182  
  183 + //! \brief Get app specific data
117 184 std::string getAppdata() const;
  185 + //! \brief Get version of app specific data
118 186 int getAppdataVersion() const;
  187 + //! \brief Set app specific data
  188 + //! \param data Custom data in any format, max length 16.
  189 + //! \param version Version of the data
  190 + //! \throws std::system_error when system or socket operations fail
  191 + //! \throws HueException when response contained no body
  192 + //! \throws HueAPIResponseException when response contains an error
  193 + //! \throws nlohmann::json::parse_error when response could not be parsed
119 194 void setAppdata(const std::string& data, int version);
120 195  
  196 + //! \brief Get picture, reserved for future use.
  197 + //!
  198 + //! Currently always an empty string.
121 199 std::string getPicture() const;
  200 + //! \brief Get time the scene was created/updated.
122 201 time::AbsoluteTime getLastUpdated() const;
  202 + //! \brief Get version of the scene
  203 + //! \returns 1 for legacy scene without lightstates
  204 + //! \returns 2 for updated scenes with lightstates
123 205 int getVersion() const;
124 206  
  207 + //! \brief Get stored states of the lights
  208 + //! \returns LightStates for each light in the scene, or an empty map for legacy scenes.
125 209 std::map<int, LightState> getLightStates() const;
  210 + //! \brief Set light states
  211 + //! \param states New states for each light in the scene.
  212 + //! Should contain exactly the lights in the scene. Additional states might cause an error.
  213 + //! \throws std::system_error when system or socket operations fail
  214 + //! \throws HueException when response contained no body
  215 + //! \throws HueAPIResponseException when response contains an error
  216 + //! \throws nlohmann::json::parse_error when response could not be parsed
126 217 void setLightStates(const std::map<int, LightState>& states);
127 218  
  219 + //! \brief Store current light state of every light in the scene
  220 + //! \throws std::system_error when system or socket operations fail
  221 + //! \throws HueException when response contained no body
  222 + //! \throws HueAPIResponseException when response contains an error
  223 + //! \throws nlohmann::json::parse_error when response could not be parsed
128 224 void storeCurrentLightState();
  225 + //! \brief Store current light state and update transition time
  226 + //! \param transition The updated transition time to this scene
  227 + //! \throws std::system_error when system or socket operations fail
  228 + //! \throws HueException when response contained no body
  229 + //! \throws HueAPIResponseException when response contains an error
  230 + //! \throws nlohmann::json::parse_error when response could not be parsed
129 231 void storeCurrentLightState(int transition);
130 232  
  233 + //! \brief Recall scene, putting every light in the stored state
  234 + //! \throws std::system_error when system or socket operations fail
  235 + //! \throws HueException when response contained no body
  236 + //! \throws HueAPIResponseException when response contains an error
  237 + //! \throws nlohmann::json::parse_error when response could not be parsed
131 238 void recall();
132 239  
133 240 private:
  241 + //! \brief Send put request to specified sub path
  242 + //! \throws std::system_error when system or socket operations fail
  243 + //! \throws HueException when response contained no body
  244 + //! \throws HueAPIResponseException when response contains an error
  245 + //! \throws nlohmann::json::parse_error when response could not be parsed
134 246 void sendPutRequest(const std::string& path, const nlohmann::json& request, FileInfo fileInfo);
135 247  
136 248 private:
... ... @@ -138,16 +250,40 @@ private:
138 250 APICache state;
139 251 };
140 252  
  253 +//! \brief Parameters for creating a new Scene
  254 +//!
  255 +//! Can be used like a builder object with chained calls.
141 256 class CreateScene
142 257 {
143 258 public:
  259 + //! \brief Set name
  260 + //! \see Scene::setName
144 261 CreateScene& setName(const std::string& name);
  262 + //! \brief Set group id, making the scene a GroupScene
  263 + //! \param id Group id for the scene, not 0
  264 + //!
  265 + //! The group id cannot be changed after the scene was created.
  266 + //! \throws HueException when used after setLightIds
145 267 CreateScene& setGroupId(int id);
  268 + //! \brief Set light ids, making the scene a LightScene
  269 + //! \param ids Ids of lights in the scene
  270 + //! \throws HueException when used after setGroupId
146 271 CreateScene& setLightIds(const std::vector<int>& ids);
  272 + //! \brief Set whether the scene can be automatically deleted
  273 + //!
  274 + //! Cannot be changed after the scene was created.
147 275 CreateScene& setRecycle(bool recycle);
  276 + //! \brief Set app specific data
  277 + //! \see Scene::setAppdata
148 278 CreateScene& setAppdata(const std::string& data, int version);
  279 + //! \brief Set light states of the scene
  280 + //!
  281 + //! When omitted, the current light states are stored.
  282 + //! \see Scene::setLightStates
149 283 CreateScene& setLightStates(const std::map<int, LightState>& states);
150 284  
  285 + //! \brief Get request to create the scene.
  286 + //! \returns JSON request for a POST to create the new scene
151 287 nlohmann::json getRequest() const;
152 288  
153 289 private:
... ...
include/hueplusplus/Schedule.h
... ... @@ -212,6 +212,8 @@ public:
212 212 //! When recycle is true, it is deleted when no resourcelinks refer to it.
213 213 CreateSchedule& setRecycle(bool recycle);
214 214  
  215 + //! \brief Get request to create the schedule.
  216 +//! \returns JSON request for a POST to create the new schedule
215 217 nlohmann::json getRequest() const;
216 218  
217 219 private:
... ...
src/TimePattern.cpp
... ... @@ -90,7 +90,6 @@ std::chrono::system_clock::time_point parseUTCTimestamp(const std::string&amp; times
90 90 // (also not officially thread-safe, but none of the time functions are)
91 91 // Set local timezone to UTC and then set it back
92 92 char* tz = std::getenv("TZ");
93   - std::time_t ctime = std::mktime(&tm);
94 93 if (tz)
95 94 {
96 95 tz = strdup(tz);
... ...