1 //******************************************************************
3 // Copyright 2017 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 /* This file contains the C++ representation definition of a Hue light */
24 #ifndef __HUE_LIGHT_H__
25 #define __HUE_LIGHT_H__
34 #include "mpmErrorCode.h"
35 #include "rapidjson.h"
38 #include "messageHandler.h"
42 * The HueLight class represents one Hue Light instance. The class
43 * provides methods to get/set of the desired configuration of the light.
45 * NOTE: A configuration can be build up by calling the desired set* methods
46 * followed by a call to put().
54 * The representational state of the light is cached in the instance
55 * but can be refreshed by a call to get();
60 typedef std::vector<std::shared_ptr<HueLight> > lights;
62 typedef struct light_state_tag
67 /* CSC array. Will contain the x, y coordinates. Both will be in [0.0, 1.0]. */
73 std::string colorMode;
78 hue = bri = sat = ct = 0;
79 power = reachable = 0;
85 bool operator!=(light_state_tag &state)
87 return !(*this == state);
90 bool operator==(light_state_tag &state)
92 /*we only care about following state changes*/
93 return state.hue == hue && state.bri == bri && state.sat == sat && state.power == power;
97 typedef struct light_config_tag
100 /** Light type (Readonly) */
104 /** Model ID (Readonly) */
105 std::string uniqueId;
106 /** Unique Lamp ID (Readonly) */
107 std::string swversion;
108 /** Software version (Readonly) */
109 std::string uri; /*URI for this resource created using uniqueId*/
114 * Constructor initializes a light instance
116 * @param[in] uri is the URI for the light instance (e.g. <ip>/api/<user>/light/1)
117 * @param[in] json is the initial JSON state for the light. If empty,
118 * the constructor will attempt to get the state directly
120 * @param[in] bridge_ip is the ip address of the hue bridge
121 * @param[in] bridge_mac is the mac address of the hue bridge
122 * @param[in] short_id is the light id
126 HueLight(std::string uri, std::string bridge_ip, std::string bridge_mac, std::string short_id,
132 * Retrieves the current light state of the Hue light.
134 * @param[in] state will hold the light state on success.
135 * @param[in] refresh indicates whether to return cached data or not.
137 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX on error.
139 MPMResult getState(light_state_t &state, bool refresh = false);
142 * Sets the current light state of the Hue light.
144 * @param[in] state is the desired state of the light.
146 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX on error.
148 MPMResult setState(light_state_t &state);
151 * Retrieves the configuration information of the Hue light.
153 * @param[in,out] config will hold the configuraion data on success.
155 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX on error.
157 MPMResult getConfig(light_config_t &config);
160 void setConfig(light_config_t &config);
163 std::string getBridgeMac()
168 std::string getShortId()
180 * Retrieves the current state of the light. Values read from
181 * are cached until a new get() is issued.
183 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX code on error.
188 * Sets the configured state of the light. Can be called for each setXXX() call
191 * @param[in] doc is a reference to the JSON object that holds the configuration to
194 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX code on error.
196 MPMResult put(rapidjson::Document &doc);
199 * Retrieves the light state from the JSON representation
201 * @param[in,out] doc is a reference to the DOM that contains the JSON rep.
203 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX on error.
205 MPMResult getInternalState(rapidjson::Document &doc);
208 * Retrieves the configuration from the JSON representation
210 * @param[in,out] doc is a reference to the DOM that contains the JSON rep.
212 * @return MPM_RESULT_OK on success, or another MPM_RESULT_XXX on error.
214 MPMResult getInternalConfig(rapidjson::Document &doc);
217 MPMResult parseJsonResponse(std::string json);
221 * Generates unique URI for this resource
223 std::string generateURI();
226 std::string m_lastCurlResponse;
228 std::string m_bridge_ip;
229 std::string m_short_id;
230 std::string m_bridge_mac;
232 light_state_t m_state;
233 light_config_t m_config;
237 typedef std::shared_ptr<HueLight> HueLightSharedPtr;
240 #endif /* __HUE_LIGHT_H__ */