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