mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Started implementation
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>1.4.3</version>
|
||||
<version>1.4.3color</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -71,14 +71,8 @@ public class DeviceResponse {
|
||||
}
|
||||
|
||||
public static DeviceResponse createResponse(DeviceDescriptor device){
|
||||
DeviceState deviceState = new DeviceState();
|
||||
DeviceResponse response = new DeviceResponse();
|
||||
response.setState(deviceState);
|
||||
deviceState.setOn(device.getDeviceState());
|
||||
deviceState.setReachable(true);
|
||||
deviceState.setEffect("none");
|
||||
deviceState.setAlert("none");
|
||||
deviceState.setBri(device.getDeviceSetValue());
|
||||
response.setState(device.getDeviceState());
|
||||
|
||||
response.setName(device.getName());
|
||||
response.setUniqueid(device.getId());
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by arm on 4/14/15.
|
||||
*/
|
||||
public class DeviceState {
|
||||
private boolean on;
|
||||
private int bri = 0;
|
||||
private int bri = 255;
|
||||
private int hue;
|
||||
private int sat;
|
||||
private String effect;
|
||||
private int ct;
|
||||
private String alert;
|
||||
private String colormode;
|
||||
private boolean reachable;
|
||||
private List<Double> xy;
|
||||
|
||||
public boolean isOn() {
|
||||
return on;
|
||||
@@ -27,6 +33,22 @@ public class DeviceState {
|
||||
this.bri = bri;
|
||||
}
|
||||
|
||||
public int getHue() {
|
||||
return hue;
|
||||
}
|
||||
|
||||
public void setHue(int hue) {
|
||||
this.hue = hue;
|
||||
}
|
||||
|
||||
public int getSat() {
|
||||
return sat;
|
||||
}
|
||||
|
||||
public void setSat(int sat) {
|
||||
this.sat = sat;
|
||||
}
|
||||
|
||||
public String getEffect() {
|
||||
return effect;
|
||||
}
|
||||
@@ -35,6 +57,14 @@ public class DeviceState {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
public int getCt() {
|
||||
return ct;
|
||||
}
|
||||
|
||||
public void setCt(int ct) {
|
||||
this.ct = ct;
|
||||
}
|
||||
|
||||
public String getAlert() {
|
||||
return alert;
|
||||
}
|
||||
@@ -43,6 +73,14 @@ public class DeviceState {
|
||||
this.alert = alert;
|
||||
}
|
||||
|
||||
public String getColormode() {
|
||||
return colormode;
|
||||
}
|
||||
|
||||
public void setColormode(String colormode) {
|
||||
this.colormode = colormode;
|
||||
}
|
||||
|
||||
public boolean isReachable() {
|
||||
return reachable;
|
||||
}
|
||||
@@ -51,6 +89,14 @@ public class DeviceState {
|
||||
this.reachable = reachable;
|
||||
}
|
||||
|
||||
public List<Double> getXy() {
|
||||
return xy;
|
||||
}
|
||||
|
||||
public void setXy(List<Double> xy) {
|
||||
this.xy = xy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceState{" +
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bwssystems.HABridge.dao;
|
||||
|
||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
@@ -47,8 +48,7 @@ public class DeviceDescriptor{
|
||||
@Expose
|
||||
private String contentBodyOff;
|
||||
|
||||
private boolean deviceState;
|
||||
private int deviceSetValue;
|
||||
private DeviceState deviceState;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -154,21 +154,12 @@ public class DeviceDescriptor{
|
||||
this.contentBodyOff = contentBodyOff;
|
||||
}
|
||||
|
||||
public boolean getDeviceState() {
|
||||
public DeviceState getDeviceState() {
|
||||
return deviceState;
|
||||
}
|
||||
|
||||
public void setDeviceState(boolean deviceState) {
|
||||
public void setDeviceState(DeviceState deviceState) {
|
||||
this.deviceState = deviceState;
|
||||
}
|
||||
|
||||
public int getDeviceSetValue() {
|
||||
return deviceSetValue;
|
||||
}
|
||||
|
||||
public void setDeviceSetValue(int deviceSetValue) {
|
||||
this.deviceSetValue = deviceSetValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -289,24 +289,9 @@ public class HueMulator {
|
||||
responseString = "[{\"error\":{\"type\": 3, \"address\": \"/lights/" + lightId + "\",\"description\": \"Could not find device\", \"resource\": \"/lights/" + lightId + "\"}}]";
|
||||
return responseString;
|
||||
}
|
||||
|
||||
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":";
|
||||
if(request.body().contains("bri"))
|
||||
{
|
||||
responseString = responseString + "true}},{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state.isOn()) {
|
||||
responseString = responseString + "true}}]";
|
||||
state.setBri(255);
|
||||
} else if (request.body().contains("false")) {
|
||||
responseString = responseString + "false}}]";
|
||||
state.setBri(0);
|
||||
}
|
||||
}
|
||||
device.setDeviceSetValue(state.getBri());
|
||||
device.setDeviceState(state.isOn());
|
||||
|
||||
responseString = this.formatSuccessHueResponse(state, request.body(), lightId);
|
||||
device.setDeviceState(state);
|
||||
|
||||
return responseString;
|
||||
});
|
||||
@@ -351,28 +336,6 @@ public class HueMulator {
|
||||
return responseString;
|
||||
}
|
||||
|
||||
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":";
|
||||
if(request.body().contains("bri"))
|
||||
{
|
||||
url = device.getDimUrl();
|
||||
|
||||
if(url == null || url.length() == 0)
|
||||
url = device.getOnUrl();
|
||||
|
||||
responseString = responseString + "true}},{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state.isOn()) {
|
||||
responseString = responseString + "true}}]";
|
||||
url = device.getOnUrl();
|
||||
state.setBri(255);
|
||||
} else if (request.body().contains("false")) {
|
||||
responseString = responseString + "false}}]";
|
||||
url = device.getOffUrl();
|
||||
state.setBri(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
log.warn("Could not find url: " + lightId + " for hue state change request: " + userId + " from " + request.ip() + " body: " + request.body());
|
||||
@@ -380,6 +343,8 @@ public class HueMulator {
|
||||
return responseString;
|
||||
}
|
||||
|
||||
responseString = this.formatSuccessHueResponse(state, request.body(), lightId);
|
||||
|
||||
if(device.getDeviceType().toLowerCase().contains("activity") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyActivity")))
|
||||
{
|
||||
log.debug("executing HUE api request to change activity to Harmony: " + url);
|
||||
@@ -518,8 +483,7 @@ public class HueMulator {
|
||||
}
|
||||
|
||||
if(!responseString.contains("[{\"error\":")) {
|
||||
device.setDeviceSetValue(state.getBri());
|
||||
device.setDeviceState(state.isOn());
|
||||
device.setDeviceState(state);
|
||||
}
|
||||
return responseString;
|
||||
});
|
||||
@@ -599,4 +563,73 @@ public class HueMulator {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String formatSuccessHueResponse(DeviceState state, String body, String lightId) {
|
||||
|
||||
String responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":";
|
||||
boolean justState = true;
|
||||
if(body.contains("bri"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(body.contains("ct"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/ct\":" + state.getCt() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(body.contains("xy"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/xy\":" + state.getXy() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(body.contains("hue"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/hue\":" + state.getHue() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(body.contains("sat"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/sat\":" + state.getSat() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(body.contains("colormode"))
|
||||
{
|
||||
if(justState)
|
||||
responseString = responseString + "true}}";
|
||||
responseString = responseString + ",{\"success\":{\"/lights/" + lightId + "/state/colormode\":" + state.getColormode() + "}}";
|
||||
justState = false;
|
||||
}
|
||||
|
||||
if(justState)
|
||||
{
|
||||
if (state.isOn()) {
|
||||
responseString = responseString + "true}}]";
|
||||
state.setBri(255);
|
||||
} else if (body.contains("false")) {
|
||||
responseString = responseString + "false}}";
|
||||
state.setBri(0);
|
||||
}
|
||||
}
|
||||
|
||||
responseString = responseString + "]";
|
||||
|
||||
return responseString;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user