1 //******************************************************************
3 // Copyright 2015 Samsung Electronics 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 using namespace OIC::Service;
30 m_connector = nullptr;
33 HueLight::HueLight(HueConnector *connector, std::string address)
36 m_connector = connector;
42 m_connector = nullptr;
45 void HueLight::initAttributes()
48 BundleResource::setAttribute("on-off", false);
49 BundleResource::setAttribute("dim", 0);
50 BundleResource::setAttribute("color", 0);
53 RCSResourceAttributes &HueLight::getAttributes()
55 return BundleResource::getAttributes();
58 RCSResourceAttributes::Value HueLight::getAttribute(const std::string &key)
60 cout << "HueLight::getAttribute called for " << key << " called" << endl;
61 return BundleResource::getAttribute(key);
64 void HueLight::setAttribute(std::string attributeName, RCSResourceAttributes::Value &&value)
66 cout << "HueLight::setAttribute setting " << attributeName << " to " << value.toString() <<
69 if (attributeName == "on-off")
71 m_connector->transmit(this->m_address + "/state", "{\"on\":" + value.toString() + "}");
74 if (attributeName == "dim")
76 // needs conversion * 2.5
77 m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value.toString() + "}");
80 if (attributeName == "color")
82 // needs conversion *650
83 m_connector->transmit(this->m_address + "/state", "{\"hue\":" + value.toString() + "}");
86 BundleResource::setAttribute(attributeName, std::move(value));