mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-21 01:05:43 +00:00
Updated configuration items for hue responses. ADded call thru for hue
devices configured for state info. added dim content body.
This commit is contained in:
@@ -40,10 +40,10 @@ public class HueConfig
|
||||
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
aConfig.setMac(HueConfig.getMacAddress(ipaddress));
|
||||
aConfig.setApiversion("1.10.0");
|
||||
aConfig.setApiversion("1.14.0");
|
||||
aConfig.setPortalservices(false);
|
||||
aConfig.setGateway(ipaddress);
|
||||
aConfig.setSwversion("01028090");
|
||||
aConfig.setSwversion("01033989");
|
||||
aConfig.setLinkbutton(false);
|
||||
aConfig.setIpaddress(ipaddress);
|
||||
aConfig.setProxyport(0);
|
||||
|
||||
@@ -23,8 +23,8 @@ public class HuePublicConfig
|
||||
public static HuePublicConfig createConfig(String name, String ipaddress) {
|
||||
HuePublicConfig aConfig = new HuePublicConfig();
|
||||
aConfig.setMac(HuePublicConfig.getMacAddress(ipaddress));
|
||||
aConfig.setApiversion("1.10.0");
|
||||
aConfig.setSwversion("01028090");
|
||||
aConfig.setApiversion("1.14.0");
|
||||
aConfig.setSwversion("01033989");
|
||||
aConfig.setName(name);
|
||||
aConfig.setBridgeid(HuePublicConfig.getBridgeIdFromMac(aConfig.getMac(), ipaddress));
|
||||
aConfig.setModelid("BSB002");
|
||||
|
||||
@@ -50,6 +50,9 @@ public class DeviceDescriptor{
|
||||
@SerializedName("contentBodyOff")
|
||||
@Expose
|
||||
private String contentBodyOff;
|
||||
@SerializedName("contentBodyDim")
|
||||
@Expose
|
||||
private String contentBodyDim;
|
||||
|
||||
private DeviceState deviceState;
|
||||
|
||||
@@ -165,6 +168,14 @@ public class DeviceDescriptor{
|
||||
this.contentBodyOff = contentBodyOff;
|
||||
}
|
||||
|
||||
public String getContentBodyDim() {
|
||||
return contentBodyDim;
|
||||
}
|
||||
|
||||
public void setContentBodyDim(String contentBodyDim) {
|
||||
this.contentBodyDim = contentBodyDim;
|
||||
}
|
||||
|
||||
public DeviceState getDeviceState() {
|
||||
if(deviceState == null)
|
||||
deviceState = DeviceState.createDeviceState();
|
||||
|
||||
@@ -280,7 +280,41 @@ public class HueMulator implements HueErrorStringSet {
|
||||
List<DeviceDescriptor> deviceList = repository.findAll();
|
||||
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
|
||||
for (DeviceDescriptor device : deviceList) {
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(device);
|
||||
DeviceResponse deviceResponse = null;
|
||||
String responseString;
|
||||
if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice"))) {
|
||||
HueDeviceIdentifier deviceId = new Gson().fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
if(myHueHome.getTheHUERegisteredUser() == null) {
|
||||
hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this);
|
||||
if(hueUser == null) {
|
||||
return errorString;
|
||||
}
|
||||
myHueHome.setTheHUERegisteredUser(hueUser);
|
||||
}
|
||||
// make call
|
||||
responseString = doHttpRequest("http://"+deviceId.getIpAddress()+"/api/"+myHueHome.getTheHUERegisteredUser()+"/lights/"+deviceId.getDeviceId(), HttpGet.METHOD_NAME, device.getContentType(), null, null);
|
||||
if (responseString == null) {
|
||||
log.warn("Error on calling hue device to get state: " + device.getName());
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
else if(responseString.contains("[{\"error\":") && responseString.contains("unauthorized user")) {
|
||||
myHueHome.setTheHUERegisteredUser(null);
|
||||
hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this);
|
||||
if(hueUser == null) {
|
||||
return errorString;
|
||||
}
|
||||
myHueHome.setTheHUERegisteredUser(hueUser);
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
else {
|
||||
deviceResponse = new Gson().fromJson(responseString, DeviceResponse.class);
|
||||
if(deviceResponse == null)
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
deviceResponseMap.put(device.getId(), deviceResponse);
|
||||
}
|
||||
return deviceResponseMap;
|
||||
@@ -448,7 +482,41 @@ public class HueMulator implements HueErrorStringSet {
|
||||
} else {
|
||||
log.debug("found device named: " + device.getName());
|
||||
}
|
||||
DeviceResponse lightResponse = DeviceResponse.createResponse(device);
|
||||
DeviceResponse lightResponse = null;
|
||||
String responseString;
|
||||
if((device.getMapType() != null && device.getMapType().equalsIgnoreCase("hueDevice"))) {
|
||||
HueDeviceIdentifier deviceId = new Gson().fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
if(myHueHome.getTheHUERegisteredUser() == null) {
|
||||
hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this);
|
||||
if(hueUser == null) {
|
||||
return errorString;
|
||||
}
|
||||
myHueHome.setTheHUERegisteredUser(hueUser);
|
||||
}
|
||||
// make call
|
||||
responseString = doHttpRequest("http://"+deviceId.getIpAddress()+"/api/"+myHueHome.getTheHUERegisteredUser()+"/lights/"+deviceId.getDeviceId(), HttpGet.METHOD_NAME, device.getContentType(), null, null);
|
||||
if (responseString == null) {
|
||||
log.warn("Error on calling hue device to get state: " + device.getName());
|
||||
lightResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
else if(responseString.contains("[{\"error\":") && responseString.contains("unauthorized user")) {
|
||||
myHueHome.setTheHUERegisteredUser(null);
|
||||
hueUser = HueUtil.registerWithHue(httpClient, deviceId.getIpAddress(), device.getName(), myHueHome.getTheHUERegisteredUser(), this);
|
||||
if(hueUser == null) {
|
||||
return errorString;
|
||||
}
|
||||
myHueHome.setTheHUERegisteredUser(hueUser);
|
||||
lightResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
else {
|
||||
lightResponse = new Gson().fromJson(responseString, DeviceResponse.class);
|
||||
if(lightResponse == null)
|
||||
lightResponse = DeviceResponse.createResponse(device);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
lightResponse = DeviceResponse.createResponse(device);
|
||||
|
||||
return lightResponse;
|
||||
}, new JsonTransformer());
|
||||
|
||||
Reference in New Issue
Block a user