Correcting the INPUT in Doxygen file.
[platform/upstream/iotivity.git] / service / resource-container / examples / HueJavaSampleBundle / hue / src / main / java / org / iotivity / bundle / hue / HueLightResource.java
1 package org.iotivity.bundle.hue;
2
3 import java.util.HashMap;
4
5 import org.iotivity.resourcecontainer.bundle.api.BundleResource;
6
7 /**
8  * This class maps a Philips Hue light to OIC light resource
9  * 
10  * @author iotivity
11  */
12 public class HueLightResource extends BundleResource {
13         private HueConnector m_hueConnector;
14
15         public HueLightResource() {
16                 initAttributes();
17                 m_resourceType = "oic.r.light.control";
18
19         }
20
21         public HueLightResource(HueConnector hueConnector, String name, String uri,
22                         String resourceType, String address) {
23                 this();
24                 this.m_hueConnector = hueConnector;
25                 m_name = name;
26                 m_uri = uri;
27                 m_resourceType = resourceType;
28                 m_address = address;
29         }
30
31         protected void initAttributes() {
32                 m_attributes.put("on-off", "true");
33                 m_attributes.put("color", "0");
34                 m_attributes.put("dim", "0");
35         }
36
37         public void handleSetAttributeRequest(String key, String value) {
38                 System.out.println("Set attribute called - key: " + key + ", value: "
39                                 + value + " transmitting now.");
40
41                 if ("on-off".equals(value)) {
42                         m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
43                                         + "}");
44                 }
45
46                 if ("dim".equals(value)) {
47                         m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
48                                         + "}");
49                 }
50
51                 if ("color".equals(value)) {
52                         m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
53                                         + "}");
54                 }
55                 this.setAttribute(key, value);
56         }
57
58         public String handleGetAttributeRequest(String key) {
59                 // map key to hue address
60                 // read from Hue gateway, parse resource representation and return
61                 // attribute
62                 // m_hueConnector.read(m_address);
63                 return this.getAttribute(key);
64         }
65
66         @Override
67         public String toString() {
68                 return "HueLightResource [m_hueConnector=" + m_hueConnector
69                                 + ", m_name=" + m_name + ", m_uri=" + m_uri
70                                 + ", m_resourceType=" + m_resourceType + ", m_address="
71                                 + m_address + ", m_attributes=" + m_attributes + "]";
72         }
73
74 }