1 package org.iotivity.bundle.hue;
3 import java.util.HashMap;
5 import org.iotivity.resourcecontainer.bundle.api.BundleResource;
8 * This class maps a Philips Hue light to OIC light resource
12 public class HueLightResource extends BundleResource {
13 private HueConnector m_hueConnector;
15 public HueLightResource() {
17 m_resourceType = "oic.r.light.control";
21 public HueLightResource(HueConnector hueConnector, String name, String uri,
22 String resourceType, String address) {
24 this.m_hueConnector = hueConnector;
27 m_resourceType = resourceType;
31 protected void initAttributes() {
32 m_attributes.put("on-off", "true");
33 m_attributes.put("color", "0");
34 m_attributes.put("dim", "0");
37 public void handleSetAttributeRequest(String key, String value) {
38 System.out.println("Set attribute called - key: " + key + ", value: "
39 + value + " transmitting now.");
41 if ("on-off".equals(value)) {
42 m_hueConnector.transmit(m_address + "/state", "{\"on\":" + value
46 if ("dim".equals(value)) {
47 m_hueConnector.transmit(m_address + "/state", "{\"bri\":" + value
51 if ("color".equals(value)) {
52 m_hueConnector.transmit(m_address + "/state", "{\"hue\":" + value
55 this.setAttribute(key, value);
58 public String handleGetAttributeRequest(String key) {
59 // map key to hue address
60 // read from Hue gateway, parse resource representation and return
62 // m_hueConnector.read(m_address);
63 return this.getAttribute(key);
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 + "]";