mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
Fixing items 4beta2.2
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>4beta2</version>
|
<version>4beta2.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ import javax.xml.bind.DatatypeConverter;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
|
|
||||||
import net.java.dev.eval.Expression;
|
import net.java.dev.eval.Expression;
|
||||||
|
|
||||||
public class BrightnessDecode {
|
public class BrightnessDecode {
|
||||||
@@ -23,17 +20,16 @@ public class BrightnessDecode {
|
|||||||
private static final String INTENSITY_MATH_VALUE = "X";
|
private static final String INTENSITY_MATH_VALUE = "X";
|
||||||
private static final String INTENSITY_MATH_CLOSE = ")}";
|
private static final String INTENSITY_MATH_CLOSE = ")}";
|
||||||
|
|
||||||
public static int calculateIntensity(DeviceState state, StateChangeBody theChanges, boolean hasBri, boolean hasBriInc) {
|
public static int calculateIntensity(int setIntensity, Integer targetBri, Integer targetBriInc) {
|
||||||
int setIntensity = state.getBri();
|
if (targetBri != null) {
|
||||||
if (hasBri) {
|
setIntensity = targetBri;
|
||||||
setIntensity = theChanges.getBri();
|
} else if (targetBriInc != null) {
|
||||||
} else if (hasBriInc) {
|
if ((setIntensity + targetBriInc) <= 0)
|
||||||
if ((setIntensity + theChanges.getBri_inc()) <= 0)
|
setIntensity = targetBriInc;
|
||||||
setIntensity = theChanges.getBri_inc();
|
else if ((setIntensity + targetBriInc) > 255)
|
||||||
else if ((setIntensity + theChanges.getBri_inc()) > 255)
|
setIntensity = targetBriInc;
|
||||||
setIntensity = theChanges.getBri_inc();
|
|
||||||
else
|
else
|
||||||
setIntensity = setIntensity + theChanges.getBri_inc();
|
setIntensity = setIntensity + targetBriInc;
|
||||||
}
|
}
|
||||||
return setIntensity;
|
return setIntensity;
|
||||||
}
|
}
|
||||||
@@ -101,7 +97,7 @@ public class BrightnessDecode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper Method
|
// Helper Method
|
||||||
public static String calculateReplaceIntensityValue(String request, DeviceState state, StateChangeBody theChanges, boolean hasBri, boolean hasBriInc, boolean isHex) {
|
public static String calculateReplaceIntensityValue(String request, int theIntensity, Integer targetBri, Integer targetBriInc, boolean isHex) {
|
||||||
return replaceIntensityValue(request, calculateIntensity(state, theChanges, hasBri, hasBriInc), isHex);
|
return replaceIntensityValue(request, calculateIntensity(theIntensity, targetBri, targetBriInc), isHex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -624,8 +624,8 @@ public class HueMulator {
|
|||||||
String responseString = null;
|
String responseString = null;
|
||||||
StateChangeBody theStateChanges = null;
|
StateChangeBody theStateChanges = null;
|
||||||
DeviceState state = null;
|
DeviceState state = null;
|
||||||
boolean stateHasBri = false;
|
Integer targetBri = null;
|
||||||
boolean stateHasBriInc = false;
|
Integer targetBriInc = null;
|
||||||
log.debug("Update state requested: " + userId + " from " + ipAddress + " body: " + body);
|
log.debug("Update state requested: " + userId + " from " + ipAddress + " body: " + body);
|
||||||
HueError[] theErrors = validateWhitelistUser(userId, false);
|
HueError[] theErrors = validateWhitelistUser(userId, false);
|
||||||
if (theErrors != null)
|
if (theErrors != null)
|
||||||
@@ -637,15 +637,6 @@ public class HueMulator {
|
|||||||
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.contains("\"bri\"")) {
|
|
||||||
if (theStateChanges.isOn() && theStateChanges.getBri() == 0)
|
|
||||||
stateHasBri = false;
|
|
||||||
else
|
|
||||||
stateHasBri = true;
|
|
||||||
}
|
|
||||||
if (body.contains("\"bri_inc\""))
|
|
||||||
stateHasBriInc = true;
|
|
||||||
|
|
||||||
DeviceDescriptor device = repository.findOne(lightId);
|
DeviceDescriptor device = repository.findOne(lightId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.warn("Could not find device: " + lightId + " for hue state change request: " + userId + " from "
|
log.warn("Could not find device: " + lightId + " for hue state change request: " + userId + " from "
|
||||||
@@ -653,17 +644,27 @@ public class HueMulator {
|
|||||||
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/lights/" + lightId,
|
return aGsonHandler.toJson(HueErrorResponse.createResponse("3", "/lights/" + lightId,
|
||||||
"Could not find device.", "/lights/" + lightId, null, null).getTheErrors(), HueError[].class);
|
"Could not find device.", "/lights/" + lightId, null, null).getTheErrors(), HueError[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (body.contains("\"bri_inc\""))
|
||||||
|
targetBriInc = new Integer(theStateChanges.getBri_inc());
|
||||||
|
else if (body.contains("\"bri\"")) {
|
||||||
|
if (theStateChanges.isOn() && theStateChanges.getBri() == 0)
|
||||||
|
targetBri = null;
|
||||||
|
else
|
||||||
|
targetBri = new Integer(theStateChanges.getBri());
|
||||||
|
}
|
||||||
|
|
||||||
state = device.getDeviceState();
|
state = device.getDeviceState();
|
||||||
if (state == null)
|
if (state == null)
|
||||||
state = DeviceState.createDeviceState();
|
state = DeviceState.createDeviceState();
|
||||||
state.fillIn();
|
state.fillIn();
|
||||||
if (stateHasBri) {
|
if (targetBri != null) {
|
||||||
if (theStateChanges.getBri() > 0 && !state.isOn())
|
if (targetBri > 0 && !state.isOn())
|
||||||
state.setOn(true);
|
state.setOn(true);
|
||||||
} else if (stateHasBriInc) {
|
} else if (targetBriInc != null) {
|
||||||
if ((state.getBri() + theStateChanges.getBri_inc()) > 0 && !state.isOn())
|
if ((state.getBri() + targetBriInc) > 0 && !state.isOn())
|
||||||
state.setOn(true);
|
state.setOn(true);
|
||||||
else if ((state.getBri() + theStateChanges.getBri_inc()) <= 0 && state.isOn())
|
else if ((state.getBri() + targetBriInc) <= 0 && state.isOn())
|
||||||
state.setOn(false);
|
state.setOn(false);
|
||||||
} else {
|
} else {
|
||||||
if (theStateChanges.isOn()) {
|
if (theStateChanges.isOn()) {
|
||||||
@@ -676,10 +677,9 @@ public class HueMulator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, device.getDeviceState());
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, device.getDeviceState());
|
||||||
device.getDeviceState().setBri(BrightnessDecode.calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc));
|
device.getDeviceState().setBri(BrightnessDecode.calculateIntensity(state.getBri(), targetBri, targetBriInc));
|
||||||
|
|
||||||
return responseString;
|
return responseString;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String changeState(String userId, String lightId, String body, String ipAddress) {
|
private String changeState(String userId, String lightId, String body, String ipAddress) {
|
||||||
@@ -687,9 +687,9 @@ public class HueMulator {
|
|||||||
String url = null;
|
String url = null;
|
||||||
StateChangeBody theStateChanges = null;
|
StateChangeBody theStateChanges = null;
|
||||||
DeviceState state = null;
|
DeviceState state = null;
|
||||||
|
Integer targetBri = null;
|
||||||
|
Integer targetBriInc = null;
|
||||||
MultiCommandUtil aMultiUtil = new MultiCommandUtil();
|
MultiCommandUtil aMultiUtil = new MultiCommandUtil();
|
||||||
boolean stateHasBri = false;
|
|
||||||
boolean stateHasBriInc = false;
|
|
||||||
aMultiUtil.setTheDelay(bridgeSettings.getButtonsleep());
|
aMultiUtil.setTheDelay(bridgeSettings.getButtonsleep());
|
||||||
aMultiUtil.setDelayDefault(bridgeSettings.getButtonsleep());
|
aMultiUtil.setDelayDefault(bridgeSettings.getButtonsleep());
|
||||||
aMultiUtil.setSetCount(1);
|
aMultiUtil.setSetCount(1);
|
||||||
@@ -705,12 +705,6 @@ public class HueMulator {
|
|||||||
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
"Could not parse state change body.", null, null, null).getTheErrors(), HueError[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.contains("\"bri\"")) {
|
|
||||||
stateHasBri = true;
|
|
||||||
}
|
|
||||||
if (body.contains("\"bri_inc\""))
|
|
||||||
stateHasBriInc = true;
|
|
||||||
|
|
||||||
DeviceDescriptor device = repository.findOne(lightId);
|
DeviceDescriptor device = repository.findOne(lightId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.warn("Could not find device: " + lightId + " for hue state change request: " + userId + " from "
|
log.warn("Could not find device: " + lightId + " for hue state change request: " + userId + " from "
|
||||||
@@ -719,26 +713,23 @@ public class HueMulator {
|
|||||||
"Could not find device.", "/lights/" + lightId, null, null).getTheErrors(), HueError[].class);
|
"Could not find device.", "/lights/" + lightId, null, null).getTheErrors(), HueError[].class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (body.contains("\"bri_inc\"")) {
|
||||||
|
targetBriInc = new Integer(theStateChanges.getBri_inc());
|
||||||
|
}
|
||||||
|
else if (body.contains("\"bri\"")) {
|
||||||
|
targetBri = new Integer(theStateChanges.getBri());
|
||||||
|
}
|
||||||
|
|
||||||
state = device.getDeviceState();
|
state = device.getDeviceState();
|
||||||
if (state == null)
|
if (state == null)
|
||||||
state = DeviceState.createDeviceState();
|
state = DeviceState.createDeviceState();
|
||||||
|
|
||||||
if (stateHasBri) {
|
if (targetBri != null || targetBriInc != null) {
|
||||||
if(!state.isOn())
|
if(!state.isOn())
|
||||||
state.setOn(true);
|
state.setOn(true);
|
||||||
|
|
||||||
url = device.getDimUrl();
|
url = device.getDimUrl();
|
||||||
|
|
||||||
if (url == null || url.length() == 0)
|
|
||||||
url = device.getOnUrl();
|
|
||||||
} else if (stateHasBriInc) {
|
|
||||||
if(!state.isOn())
|
|
||||||
state.setOn(true);
|
|
||||||
if ((state.getBri() + theStateChanges.getBri_inc()) <= 0)
|
|
||||||
state.setBri(theStateChanges.getBri_inc());
|
|
||||||
|
|
||||||
url = device.getDimUrl();
|
|
||||||
|
|
||||||
if (url == null || url.length() == 0)
|
if (url == null || url.length() == 0)
|
||||||
url = device.getOnUrl();
|
url = device.getOnUrl();
|
||||||
} else {
|
} else {
|
||||||
@@ -792,7 +783,20 @@ public class HueMulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (callItems[i].getType() != null) {
|
if (callItems[i].getType() != null) {
|
||||||
responseString = homeManager.findHome(callItems[i].getType().trim()).deviceHandler(callItems[i], aMultiUtil, lightId, i, state, theStateChanges, stateHasBri, stateHasBriInc, device, body);
|
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
||||||
|
if (x > 0 || i > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(aMultiUtil.getTheDelay());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (callItems[i].getDelay() != null && callItems[i].getDelay() > 0)
|
||||||
|
aMultiUtil.setTheDelay(callItems[i].getDelay());
|
||||||
|
else
|
||||||
|
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
||||||
|
responseString = homeManager.findHome(callItems[i].getType().trim()).deviceHandler(callItems[i], aMultiUtil, lightId, state.getBri(), targetBri, targetBriInc, device, body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -804,7 +808,7 @@ public class HueMulator {
|
|||||||
|
|
||||||
if (responseString == null || !responseString.contains("[{\"error\":")) {
|
if (responseString == null || !responseString.contains("[{\"error\":")) {
|
||||||
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state);
|
responseString = this.formatSuccessHueResponse(theStateChanges, body, lightId, state);
|
||||||
state.setBri(BrightnessDecode.calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc));
|
state.setBri(BrightnessDecode.calculateIntensity(state.getBri(), targetBri, targetBriInc));
|
||||||
device.setDeviceState(state);
|
device.setDeviceState(state);
|
||||||
}
|
}
|
||||||
return responseString;
|
return responseString;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package com.bwssystems.HABridge.hue;
|
package com.bwssystems.HABridge.hue;
|
||||||
|
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
|
|
||||||
public interface HueMulatorHandler {
|
public interface HueMulatorHandler {
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount, DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body);
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri, Integer targetBriInc, DeviceDescriptor device, String body);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
import com.bwssystems.HABridge.DeviceMapTypes;
|
import com.bwssystems.HABridge.DeviceMapTypes;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -103,8 +101,8 @@ public class NestHome implements com.bwssystems.HABridge.Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
log.debug("executing HUE api request to set away for nest " + anItem.getType() + ": " + anItem.getItem().toString());
|
log.debug("executing HUE api request to set away for nest " + anItem.getType() + ": " + anItem.getItem().toString());
|
||||||
if(!validNest) {
|
if(!validNest) {
|
||||||
@@ -118,18 +116,18 @@ public class NestHome implements com.bwssystems.HABridge.Home {
|
|||||||
} else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) {
|
} else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) {
|
||||||
NestInstruction thermoSetting = aGsonHandler.fromJson(anItem.getItem().toString(), NestInstruction.class);
|
NestInstruction thermoSetting = aGsonHandler.fromJson(anItem.getItem().toString(), NestInstruction.class);
|
||||||
if (thermoSetting.getControl().equalsIgnoreCase("temp")) {
|
if (thermoSetting.getControl().equalsIgnoreCase("temp")) {
|
||||||
if (stateHasBri) {
|
if (targetBri != null) {
|
||||||
if (isFarenheit)
|
if (isFarenheit)
|
||||||
thermoSetting
|
thermoSetting
|
||||||
.setTemp(
|
.setTemp(
|
||||||
String.valueOf((Double
|
String.valueOf((Double
|
||||||
.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
|
.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc, false)) - 32.0) / 1.8));
|
intensity, targetBri, targetBriInc, false)) - 32.0) / 1.8));
|
||||||
else
|
else
|
||||||
thermoSetting
|
thermoSetting
|
||||||
.setTemp(
|
.setTemp(
|
||||||
String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
|
String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc, false))));
|
intensity, targetBri, targetBriInc, false))));
|
||||||
log.debug("Setting thermostat: " + thermoSetting.getName() + " to "
|
log.debug("Setting thermostat: " + thermoSetting.getName() + " to "
|
||||||
+ thermoSetting.getTemp() + "C");
|
+ thermoSetting.getTemp() + "C");
|
||||||
theNest.getThermostat(thermoSetting.getName())
|
theNest.getThermostat(thermoSetting.getName())
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -23,33 +21,18 @@ public class CommandHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int itensity, Integer targetBri, Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
log.debug("Exec Request called with url: " + anItem.getItem().getAsString());
|
||||||
log.debug("Exec Request called with url: " + anItem.getItem().toString());
|
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
String intermediate;
|
String intermediate;
|
||||||
if (anItem.getItem().toString().contains("exec://"))
|
if (anItem.getItem().toString().contains("exec://"))
|
||||||
intermediate = anItem.getItem().toString().substring(anItem.getItem().toString().indexOf("://") + 3);
|
intermediate = anItem.getItem().getAsString().substring(anItem.getItem().toString().indexOf("://") + 3);
|
||||||
else
|
else
|
||||||
intermediate = anItem.getItem().toString();
|
intermediate = anItem.getItem().getAsString();
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
String anError = doExecRequest(intermediate,
|
String anError = doExecRequest(intermediate,
|
||||||
BrightnessDecode.calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc), lightId);
|
BrightnessDecode.calculateIntensity(itensity, targetBri, targetBriInc), lightId);
|
||||||
if (anError != null) {
|
if (anError != null) {
|
||||||
responseString = anError;
|
responseString = anError;
|
||||||
x = aMultiUtil.getSetCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,15 +13,20 @@ import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
import com.bwssystems.HABridge.api.NameValue;
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
import com.bwssystems.HABridge.api.hue.HueError;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
|
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
public class HalHome implements Home {
|
public class HalHome implements Home {
|
||||||
private static final Logger log = LoggerFactory.getLogger(HalHome.class);
|
private static final Logger log = LoggerFactory.getLogger(HalHome.class);
|
||||||
private Map<String, HalInfo> hals;
|
private Map<String, HalInfo> hals;
|
||||||
private Boolean validHal;
|
private Boolean validHal;
|
||||||
|
private HTTPHandler anHttpHandler;
|
||||||
|
|
||||||
public HalHome(BridgeSettingsDescriptor bridgeSettings) {
|
public HalHome(BridgeSettingsDescriptor bridgeSettings) {
|
||||||
super();
|
super();
|
||||||
@@ -108,14 +113,30 @@ public class HalHome implements Home {
|
|||||||
aNewHalDevice.setHalname(theKey);
|
aNewHalDevice.setHalname(theKey);
|
||||||
theDeviceList.add(aNewHalDevice);
|
theDeviceList.add(aNewHalDevice);
|
||||||
}
|
}
|
||||||
|
anHttpHandler = new HTTPHandler();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
log.info("device handler not implemented");
|
log.debug("executing HUE api request to HAL Http " + anItem.getItem().getAsString());
|
||||||
return null;
|
String responseString = null;
|
||||||
|
|
||||||
|
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||||
|
intensity, targetBri, targetBriInc, false);
|
||||||
|
String aBody;
|
||||||
|
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||||
|
intensity, targetBri, targetBriInc, false);
|
||||||
|
// make call
|
||||||
|
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
|
||||||
|
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {
|
||||||
|
log.warn("Error on calling url to change device state: " + anUrl);
|
||||||
|
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
|
||||||
|
"Error on calling url to change device state", "/lights/"
|
||||||
|
+ lightId + "state", null, null).getTheErrors(), HueError[].class);
|
||||||
|
}
|
||||||
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import com.bwssystems.HABridge.Home;
|
|||||||
import com.bwssystems.HABridge.IpList;
|
import com.bwssystems.HABridge.IpList;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -125,8 +123,8 @@ public class HarmonyHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
log.debug("executing HUE api request to change " + anItem.getType() + " to Harmony: " + device.getName());
|
log.debug("executing HUE api request to change " + anItem.getType() + " to Harmony: " + device.getName());
|
||||||
if(!validHarmony) {
|
if(!validHarmony) {
|
||||||
@@ -147,21 +145,8 @@ public class HarmonyHome implements Home {
|
|||||||
+ "\",\"description\": \"Should not get here, no harmony hub available\", \"parameter\": \"/lights/"
|
+ "\",\"description\": \"Should not get here, no harmony hub available\", \"parameter\": \"/lights/"
|
||||||
+ lightId + "state\"}}]";
|
+ lightId + "state\"}}]";
|
||||||
} else {
|
} else {
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
myHarmony.startActivity(anActivity);
|
myHarmony.startActivity(anActivity);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
|
} else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
|
||||||
String url = anItem.getItem().toString();
|
String url = anItem.getItem().toString();
|
||||||
if (url.substring(0, 1).equalsIgnoreCase("{")) {
|
if (url.substring(0, 1).equalsIgnoreCase("{")) {
|
||||||
@@ -172,8 +157,6 @@ public class HarmonyHome implements Home {
|
|||||||
for(int z = 0; z < deviceButtons.length; z++) {
|
for(int z = 0; z < deviceButtons.length; z++) {
|
||||||
if(deviceButtons[z].getCount() != null && deviceButtons[z].getCount() > 0)
|
if(deviceButtons[z].getCount() != null && deviceButtons[z].getCount() > 0)
|
||||||
theCount = deviceButtons[z].getCount();
|
theCount = deviceButtons[z].getCount();
|
||||||
else
|
|
||||||
theCount = aMultiUtil.getSetCount();
|
|
||||||
for(int y = 0; y < theCount; y++) {
|
for(int y = 0; y < theCount; y++) {
|
||||||
if( y > 0 || z > 0) {
|
if( y > 0 || z > 0) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -111,8 +109,8 @@ public class HassHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount, DeviceState state,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
String theReturn = null;
|
String theReturn = null;
|
||||||
log.debug("executing HUE api request to send message to HomeAssistant: " + anItem.getItem().toString());
|
log.debug("executing HUE api request to send message to HomeAssistant: " + anItem.getItem().toString());
|
||||||
if(!validHass) {
|
if(!validHass) {
|
||||||
@@ -124,7 +122,7 @@ public class HassHome implements Home {
|
|||||||
} else {
|
} else {
|
||||||
HassCommand hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class);
|
HassCommand hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class);
|
||||||
hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(),
|
hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(),
|
||||||
BrightnessDecode.calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc), false));
|
BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false));
|
||||||
HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName());
|
HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName());
|
||||||
if (homeAssistant == null) {
|
if (homeAssistant == null) {
|
||||||
log.warn("Should not get here, no HomeAssistants available");
|
log.warn("Should not get here, no HomeAssistants available");
|
||||||
@@ -132,25 +130,11 @@ public class HassHome implements Home {
|
|||||||
+ "\",\"description\": \"Should not get here, no HiomeAssistant clients available\", \"parameter\": \"/lights/"
|
+ "\",\"description\": \"Should not get here, no HiomeAssistant clients available\", \"parameter\": \"/lights/"
|
||||||
+ lightId + "state\"}}]";
|
+ lightId + "state\"}}]";
|
||||||
} else {
|
} else {
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
log.debug("calling HomeAssistant: " + hassCommand.getHassName() + " - "
|
log.debug("calling HomeAssistant: " + hassCommand.getHassName() + " - "
|
||||||
+ hassCommand.getEntityId() + " - " + hassCommand.getState() + " - " + hassCommand.getBri()
|
+ hassCommand.getEntityId() + " - " + hassCommand.getState() + " - " + hassCommand.getBri());
|
||||||
+ " - iteration: " + String.valueOf(iterationCount) + " - count: " + String.valueOf(x));
|
|
||||||
homeAssistant.callCommand(hassCommand);
|
homeAssistant.callCommand(hassCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return theReturn;
|
return theReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.NameValue;
|
import com.bwssystems.HABridge.api.NameValue;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.HueError;
|
import com.bwssystems.HABridge.api.hue.HueError;
|
||||||
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
|
import com.bwssystems.HABridge.api.hue.HueErrorResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -26,8 +24,8 @@ public class HTTPHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
|
|
||||||
//Backwards Compatibility Items
|
//Backwards Compatibility Items
|
||||||
@@ -46,24 +44,11 @@ public class HTTPHome implements Home {
|
|||||||
+ (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": "
|
+ (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": "
|
||||||
+ anItem.getItem().getAsString());
|
+ anItem.getItem().getAsString());
|
||||||
|
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc, false);
|
intensity, targetBri, targetBriInc, false);
|
||||||
String aBody;
|
String aBody;
|
||||||
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc,
|
intensity, targetBri, targetBriInc, false);
|
||||||
false);
|
|
||||||
// make call
|
// make call
|
||||||
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
|
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
|
||||||
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {
|
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {
|
||||||
@@ -71,8 +56,6 @@ public class HTTPHome implements Home {
|
|||||||
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
|
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
|
||||||
"Error on calling url to change device state", "/lights/"
|
"Error on calling url to change device state", "/lights/"
|
||||||
+ lightId + "state", null, null).getTheErrors(), HueError[].class);
|
+ lightId + "state", null, null).getTheErrors(), HueError[].class);
|
||||||
x = aMultiUtil.getSetCount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ import com.bwssystems.HABridge.Home;
|
|||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.HueApiResponse;
|
import com.bwssystems.HABridge.api.hue.HueApiResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
@@ -77,8 +75,8 @@ public class HueHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
if(!validHue)
|
if(!validHue)
|
||||||
return null;
|
return null;
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
@@ -89,23 +87,8 @@ public class HueHome implements Home {
|
|||||||
HueInfo theHue = hues.get(deviceId.getHueName());
|
HueInfo theHue = hues.get(deviceId.getHueName());
|
||||||
|
|
||||||
// make call
|
// make call
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
|
|
||||||
responseString = theHue.changeState(deviceId, lightId, body);
|
responseString = theHue.changeState(deviceId, lightId, body);
|
||||||
if (responseString.contains("[{\"error\":"))
|
|
||||||
x = aMultiUtil.getSetCount();
|
|
||||||
}
|
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -76,24 +74,25 @@ public class MQTTHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString());
|
log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString());
|
||||||
if (validMqtt) {
|
if (validMqtt) {
|
||||||
MQTTMessage[] mqttMessages = aGsonHandler.fromJson(BrightnessDecode.replaceIntensityValue(anItem.getItem().toString(),
|
String mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(),
|
||||||
BrightnessDecode.calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc), false), MQTTMessage[].class);
|
intensity, targetBri, targetBriInc, false);
|
||||||
|
if (mqttObject.substring(0, 1).equalsIgnoreCase("{"))
|
||||||
|
mqttObject = "[" + mqttObject + "]";
|
||||||
|
MQTTMessage[] mqttMessages = aGsonHandler.fromJson(mqttObject, MQTTMessage[].class);
|
||||||
Integer theCount = 1;
|
Integer theCount = 1;
|
||||||
for(int z = 0; z < mqttMessages.length; z++) {
|
for(int z = 0; z < mqttMessages.length; z++) {
|
||||||
if(mqttMessages[z].getCount() != null && mqttMessages[z].getCount() > 0)
|
if(mqttMessages[z].getCount() != null && mqttMessages[z].getCount() > 0)
|
||||||
theCount = mqttMessages[z].getCount();
|
theCount = mqttMessages[z].getCount();
|
||||||
else
|
|
||||||
theCount = aMultiUtil.getSetCount();
|
|
||||||
for(int y = 0; y < theCount; y++) {
|
for(int y = 0; y < theCount; y++) {
|
||||||
if( y > 0 || z > 0) {
|
if( y > 0 || z > 0) {
|
||||||
log.debug("publishing message: " + mqttMessages[y].getClientId() + " - "
|
log.debug("publishing message: " + mqttMessages[y].getClientId() + " - "
|
||||||
+ mqttMessages[y].getTopic() + " - " + mqttMessages[y].getMessage()
|
+ mqttMessages[y].getTopic() + " - " + mqttMessages[y].getMessage()
|
||||||
+ " - iteration: " + String.valueOf(iterationCount) + " - count: " + String.valueOf(z));
|
+ " - count: " + String.valueOf(z));
|
||||||
|
|
||||||
MQTTHandler mqttHandler = getMQTTHandler(mqttMessages[y].getClientId());
|
MQTTHandler mqttHandler = getMQTTHandler(mqttMessages[y].getClientId());
|
||||||
if (mqttHandler == null) {
|
if (mqttHandler == null) {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -30,23 +28,10 @@ public class TCPHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc,
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
DeviceDescriptor device, String body) {
|
log.debug("executing HUE api request to TCP: " + anItem.getItem().getAsString());
|
||||||
log.debug("executing HUE api request to TCP: " + anItem.getItem().toString());
|
String intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3);
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
String intermediate = anItem.getItem().toString().substring(anItem.getItem().toString().indexOf("://") + 3);
|
|
||||||
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
||||||
String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1);
|
String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1);
|
||||||
String hostAddr = null;
|
String hostAddr = null;
|
||||||
@@ -64,12 +49,10 @@ public class TCPHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (theUrlBody.startsWith("0x")) {
|
if (theUrlBody.startsWith("0x")) {
|
||||||
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, state, theStateChanges,
|
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, true);
|
||||||
stateHasBri, stateHasBriInc, true);
|
|
||||||
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
||||||
} else {
|
} else {
|
||||||
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, state, theStateChanges,
|
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody, intensity, targetBri, targetBriInc, false);
|
||||||
stateHasBri, stateHasBriInc, false);
|
|
||||||
sendData = theUrlBody.getBytes();
|
sendData = theUrlBody.getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +65,6 @@ public class TCPHome implements Home {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
import com.bwssystems.HABridge.hue.BrightnessDecode;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
@@ -31,21 +29,9 @@ public class UDPHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
log.debug("executing HUE api request to UDP: " + anItem.getItem().toString());
|
log.debug("executing HUE api request to UDP: " + anItem.getItem().getAsString());
|
||||||
for (int x = 0; x < aMultiUtil.getSetCount(); x++) {
|
|
||||||
if (x > 0 || iterationCount > 0) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(aMultiUtil.getTheDelay());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (anItem.getDelay() != null && anItem.getDelay() > 0)
|
|
||||||
aMultiUtil.setTheDelay(anItem.getDelay());
|
|
||||||
else
|
|
||||||
aMultiUtil.setTheDelay(aMultiUtil.getDelayDefault());
|
|
||||||
String intermediate = anItem.getItem().getAsString()
|
String intermediate = anItem.getItem().getAsString()
|
||||||
.substring(anItem.getItem().getAsString().indexOf("://") + 3);
|
.substring(anItem.getItem().getAsString().indexOf("://") + 3);
|
||||||
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
|
||||||
@@ -66,11 +52,11 @@ public class UDPHome implements Home {
|
|||||||
|
|
||||||
if (theUrlBody.startsWith("0x")) {
|
if (theUrlBody.startsWith("0x")) {
|
||||||
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody,
|
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody,
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc, true);
|
intensity, targetBri, targetBriInc, true);
|
||||||
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
sendData = DatatypeConverter.parseHexBinary(theUrlBody.substring(2));
|
||||||
} else {
|
} else {
|
||||||
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody,
|
theUrlBody = BrightnessDecode.calculateReplaceIntensityValue(theUrlBody,
|
||||||
state, theStateChanges, stateHasBri, stateHasBriInc, false);
|
intensity, targetBri, targetBriInc, false);
|
||||||
sendData = theUrlBody.getBytes();
|
sendData = theUrlBody.getBytes();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -81,7 +67,6 @@ public class UDPHome implements Home {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import com.bwssystems.HABridge.DeviceMapTypes;
|
|||||||
import com.bwssystems.HABridge.Home;
|
import com.bwssystems.HABridge.Home;
|
||||||
import com.bwssystems.HABridge.NamedIP;
|
import com.bwssystems.HABridge.NamedIP;
|
||||||
import com.bwssystems.HABridge.api.CallItem;
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
|
||||||
import com.bwssystems.HABridge.api.hue.StateChangeBody;
|
|
||||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||||
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
import com.bwssystems.HABridge.hue.MultiCommandUtil;
|
||||||
import com.bwssystems.HABridge.plugins.vera.luupRequests.Device;
|
import com.bwssystems.HABridge.plugins.vera.luupRequests.Device;
|
||||||
@@ -74,8 +72,8 @@ public class VeraHome implements Home {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int iterationCount,
|
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
|
||||||
DeviceState state, StateChangeBody theStateChanges, boolean stateHasBri, boolean stateHasBriInc, DeviceDescriptor device, String body) {
|
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
|
||||||
// Not a device handler
|
// Not a device handler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -843,15 +843,16 @@ app.controller('SystemController', function ($scope, $location, $http, $window,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$scope.addHasstoSettings = function (newhassname, newhassip, newhassport) {
|
$scope.addHasstoSettings = function (newhassname, newhassip, newhassport, newhasspassword) {
|
||||||
if($scope.bridge.settings.hassaddress == null) {
|
if($scope.bridge.settings.hassaddress == null) {
|
||||||
$scope.bridge.settings.hassaddress = { devices: [] };
|
$scope.bridge.settings.hassaddress = { devices: [] };
|
||||||
}
|
}
|
||||||
var newhass = {name: newhassname, ip: newhassip, port: newhassport }
|
var newhass = {name: newhassname, ip: newhassip, port: newhassport, password: newhasspassword }
|
||||||
$scope.bridge.settings.hassaddress.devices.push(newhass);
|
$scope.bridge.settings.hassaddress.devices.push(newhass);
|
||||||
$scope.newhassname = null;
|
$scope.newhassname = null;
|
||||||
$scope.newhassip = null;
|
$scope.newhassip = null;
|
||||||
$scope.newhassport = null;
|
$scope.newhassport = null;
|
||||||
|
$scope.newhasspassword = null;
|
||||||
};
|
};
|
||||||
$scope.removeHasstoSettings = function (hassname, hassip) {
|
$scope.removeHasstoSettings = function (hassname, hassip) {
|
||||||
for(var i = $scope.bridge.settings.hassaddress.devices.length - 1; i >= 0; i--) {
|
for(var i = $scope.bridge.settings.hassaddress.devices.length - 1; i >= 0; i--) {
|
||||||
|
|||||||
Reference in New Issue
Block a user