mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 16:41:53 +00:00
Merge branch 'master' of https://github.com/bwssytems/ha-bridge
This commit is contained in:
@@ -220,19 +220,22 @@ public class DeviceDescriptor{
|
||||
}
|
||||
|
||||
public boolean containsType(String aType) {
|
||||
if(this.mapType.contains(aType))
|
||||
if(aType == null)
|
||||
return false;
|
||||
|
||||
if(this.mapType != null && this.mapType.contains(aType))
|
||||
return true;
|
||||
|
||||
if(this.deviceType.contains(aType))
|
||||
if(this.deviceType != null && this.deviceType.contains(aType))
|
||||
return true;
|
||||
|
||||
if(this.onUrl.contains(aType))
|
||||
if(this.onUrl != null && this.onUrl.contains(aType))
|
||||
return true;
|
||||
|
||||
if(this.dimUrl.contains(aType))
|
||||
if(this.dimUrl != null && this.dimUrl.contains(aType))
|
||||
return true;
|
||||
|
||||
if(this.offUrl.contains(aType))
|
||||
if(this.offUrl != null && this.offUrl.contains(aType))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -673,11 +673,24 @@ public class HueMulator {
|
||||
deviceResponseMap = new HashMap<String, DeviceResponse>();
|
||||
for (DeviceDescriptor device : deviceList) {
|
||||
DeviceResponse deviceResponse = null;
|
||||
// In the multi command context, this is not valid anymore
|
||||
// if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
|
||||
// HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
// deviceResponse = myHueHome.getHueDeviceInfo(deviceId, device);
|
||||
// }
|
||||
if (device.containsType(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
||||
CallItem[] callItems = null;
|
||||
try {
|
||||
if(device.getOnUrl() != null)
|
||||
callItems = aGsonHandler.fromJson(device.getOnUrl(), CallItem[].class);
|
||||
} catch(JsonSyntaxException e) {
|
||||
log.warn("Could not decode Json for url items to get Hue state for device: " + device.getName());
|
||||
callItems = null;
|
||||
}
|
||||
|
||||
for (int i = 0; callItems != null && i < callItems.length; i++) {
|
||||
if((callItems[i].getType() != null && callItems[i].getType().equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) ||
|
||||
(callItems[i].getItem().getAsString().contains("hueName"))) {
|
||||
deviceResponse = myHueHome.getHueDeviceInfo(callItems[i], device);
|
||||
i = callItems.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceResponse == null)
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
@@ -772,10 +785,25 @@ public class HueMulator {
|
||||
log.debug("found device named: " + device.getName());
|
||||
}
|
||||
DeviceResponse lightResponse = null;
|
||||
if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
|
||||
HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
lightResponse = myHueHome.getHueDeviceInfo(deviceId, device);
|
||||
} else
|
||||
if (device.containsType(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
||||
CallItem[] callItems = null;
|
||||
try {
|
||||
if(device.getOnUrl() != null)
|
||||
callItems = aGsonHandler.fromJson(device.getOnUrl(), CallItem[].class);
|
||||
} catch(JsonSyntaxException e) {
|
||||
log.warn("Could not decode Json for url items to get Hue state for device: " + device.getName());
|
||||
callItems = null;
|
||||
}
|
||||
|
||||
for (int i = 0; callItems != null && i < callItems.length; i++) {
|
||||
if((callItems[i].getType() != null && callItems[i].getType().equals(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) || callItems[i].getItem().getAsString().startsWith("{\"ipAddress\":\"")) {
|
||||
lightResponse = myHueHome.getHueDeviceInfo(callItems[i], device);
|
||||
i = callItems.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lightResponse == null)
|
||||
lightResponse = DeviceResponse.createResponse(device);
|
||||
|
||||
return lightResponse;
|
||||
|
||||
@@ -1,209 +1,24 @@
|
||||
|
||||
package com.bwssystems.HABridge.plugins.domoticz;
|
||||
|
||||
import java.util.List;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class DeviceResult {
|
||||
|
||||
@SerializedName("AddjMulti")
|
||||
@Expose
|
||||
private Integer addjMulti;
|
||||
@SerializedName("AddjMulti2")
|
||||
@Expose
|
||||
private Integer addjMulti2;
|
||||
@SerializedName("AddjValue")
|
||||
@Expose
|
||||
private Integer addjValue;
|
||||
@SerializedName("AddjValue2")
|
||||
@Expose
|
||||
private Integer addjValue2;
|
||||
@SerializedName("BatteryLevel")
|
||||
@Expose
|
||||
private Integer batteryLevel;
|
||||
@SerializedName("CustomImage")
|
||||
@Expose
|
||||
private Integer customImage;
|
||||
@SerializedName("Data")
|
||||
@Expose
|
||||
private String data;
|
||||
@SerializedName("Description")
|
||||
@Expose
|
||||
private String description;
|
||||
@SerializedName("Favorite")
|
||||
@Expose
|
||||
private Integer favorite;
|
||||
@SerializedName("HardwareID")
|
||||
@Expose
|
||||
private Integer hardwareID;
|
||||
@SerializedName("HardwareName")
|
||||
@Expose
|
||||
private String hardwareName;
|
||||
@SerializedName("HardwareType")
|
||||
@Expose
|
||||
private String hardwareType;
|
||||
@SerializedName("HardwareTypeVal")
|
||||
@Expose
|
||||
private Integer hardwareTypeVal;
|
||||
@SerializedName("HaveDimmer")
|
||||
@Expose
|
||||
private Boolean haveDimmer;
|
||||
@SerializedName("HaveGroupCmd")
|
||||
@Expose
|
||||
private Boolean haveGroupCmd;
|
||||
@SerializedName("HaveTimeout")
|
||||
@Expose
|
||||
private Boolean haveTimeout;
|
||||
@SerializedName("ID")
|
||||
@Expose
|
||||
private String iD;
|
||||
@SerializedName("Image")
|
||||
@Expose
|
||||
private String image;
|
||||
@SerializedName("IsSubDevice")
|
||||
@Expose
|
||||
private Boolean isSubDevice;
|
||||
@SerializedName("LastUpdate")
|
||||
@Expose
|
||||
private String lastUpdate;
|
||||
@SerializedName("Level")
|
||||
@Expose
|
||||
private Integer level;
|
||||
@SerializedName("LevelInt")
|
||||
@Expose
|
||||
private Integer levelInt;
|
||||
@SerializedName("MaxDimLevel")
|
||||
@Expose
|
||||
private Integer maxDimLevel;
|
||||
@SerializedName("Name")
|
||||
@Expose
|
||||
private String name;
|
||||
@SerializedName("Notifications")
|
||||
@Expose
|
||||
private String notifications;
|
||||
@SerializedName("OffAction")
|
||||
@Expose
|
||||
private String offAction;
|
||||
@SerializedName("OnAction")
|
||||
@Expose
|
||||
private String onAction;
|
||||
@SerializedName("PlanID")
|
||||
@Expose
|
||||
private String planID;
|
||||
@SerializedName("PlanIDs")
|
||||
@Expose
|
||||
private List<Integer> planIDs = null;
|
||||
@SerializedName("Protected")
|
||||
@Expose
|
||||
private Boolean _protected;
|
||||
@SerializedName("ShowNotifications")
|
||||
@Expose
|
||||
private Boolean showNotifications;
|
||||
@SerializedName("SignalLevel")
|
||||
@Expose
|
||||
private String signalLevel;
|
||||
@SerializedName("Status")
|
||||
@Expose
|
||||
private String status;
|
||||
@SerializedName("StrParam1")
|
||||
@Expose
|
||||
private String strParam1;
|
||||
@SerializedName("StrParam2")
|
||||
@Expose
|
||||
private String strParam2;
|
||||
@SerializedName("SubType")
|
||||
@Expose
|
||||
private String subType;
|
||||
@SerializedName("SwitchType")
|
||||
@Expose
|
||||
private String switchType;
|
||||
@SerializedName("SwitchTypeVal")
|
||||
@Expose
|
||||
private Integer switchTypeVal;
|
||||
@SerializedName("Timers")
|
||||
@Expose
|
||||
private String timers;
|
||||
@SerializedName("Type")
|
||||
@Expose
|
||||
private String type;
|
||||
@SerializedName("TypeImg")
|
||||
@Expose
|
||||
private String typeImg;
|
||||
@SerializedName("Unit")
|
||||
@Expose
|
||||
private Integer unit;
|
||||
@SerializedName("Used")
|
||||
@Expose
|
||||
private Integer used;
|
||||
@SerializedName("UsedByCamera")
|
||||
@Expose
|
||||
private Boolean usedByCamera;
|
||||
@SerializedName("XOffset")
|
||||
@Expose
|
||||
private String xOffset;
|
||||
@SerializedName("YOffset")
|
||||
@Expose
|
||||
private String yOffset;
|
||||
@SerializedName("idx")
|
||||
@Expose
|
||||
private String idx;
|
||||
|
||||
public Integer getAddjMulti() {
|
||||
return addjMulti;
|
||||
}
|
||||
|
||||
public void setAddjMulti(Integer addjMulti) {
|
||||
this.addjMulti = addjMulti;
|
||||
}
|
||||
|
||||
public Integer getAddjMulti2() {
|
||||
return addjMulti2;
|
||||
}
|
||||
|
||||
public void setAddjMulti2(Integer addjMulti2) {
|
||||
this.addjMulti2 = addjMulti2;
|
||||
}
|
||||
|
||||
public Integer getAddjValue() {
|
||||
return addjValue;
|
||||
}
|
||||
|
||||
public void setAddjValue(Integer addjValue) {
|
||||
this.addjValue = addjValue;
|
||||
}
|
||||
|
||||
public Integer getAddjValue2() {
|
||||
return addjValue2;
|
||||
}
|
||||
|
||||
public void setAddjValue2(Integer addjValue2) {
|
||||
this.addjValue2 = addjValue2;
|
||||
}
|
||||
|
||||
public Integer getBatteryLevel() {
|
||||
return batteryLevel;
|
||||
}
|
||||
|
||||
public void setBatteryLevel(Integer batteryLevel) {
|
||||
this.batteryLevel = batteryLevel;
|
||||
}
|
||||
|
||||
public Integer getCustomImage() {
|
||||
return customImage;
|
||||
}
|
||||
|
||||
public void setCustomImage(Integer customImage) {
|
||||
this.customImage = customImage;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
@@ -213,126 +28,6 @@ public class DeviceResult {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Integer getFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
public void setFavorite(Integer favorite) {
|
||||
this.favorite = favorite;
|
||||
}
|
||||
|
||||
public Integer getHardwareID() {
|
||||
return hardwareID;
|
||||
}
|
||||
|
||||
public void setHardwareID(Integer hardwareID) {
|
||||
this.hardwareID = hardwareID;
|
||||
}
|
||||
|
||||
public String getHardwareName() {
|
||||
return hardwareName;
|
||||
}
|
||||
|
||||
public void setHardwareName(String hardwareName) {
|
||||
this.hardwareName = hardwareName;
|
||||
}
|
||||
|
||||
public String getHardwareType() {
|
||||
return hardwareType;
|
||||
}
|
||||
|
||||
public void setHardwareType(String hardwareType) {
|
||||
this.hardwareType = hardwareType;
|
||||
}
|
||||
|
||||
public Integer getHardwareTypeVal() {
|
||||
return hardwareTypeVal;
|
||||
}
|
||||
|
||||
public void setHardwareTypeVal(Integer hardwareTypeVal) {
|
||||
this.hardwareTypeVal = hardwareTypeVal;
|
||||
}
|
||||
|
||||
public Boolean getHaveDimmer() {
|
||||
return haveDimmer;
|
||||
}
|
||||
|
||||
public void setHaveDimmer(Boolean haveDimmer) {
|
||||
this.haveDimmer = haveDimmer;
|
||||
}
|
||||
|
||||
public Boolean getHaveGroupCmd() {
|
||||
return haveGroupCmd;
|
||||
}
|
||||
|
||||
public void setHaveGroupCmd(Boolean haveGroupCmd) {
|
||||
this.haveGroupCmd = haveGroupCmd;
|
||||
}
|
||||
|
||||
public Boolean getHaveTimeout() {
|
||||
return haveTimeout;
|
||||
}
|
||||
|
||||
public void setHaveTimeout(Boolean haveTimeout) {
|
||||
this.haveTimeout = haveTimeout;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return iD;
|
||||
}
|
||||
|
||||
public void setID(String iD) {
|
||||
this.iD = iD;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public Boolean getIsSubDevice() {
|
||||
return isSubDevice;
|
||||
}
|
||||
|
||||
public void setIsSubDevice(Boolean isSubDevice) {
|
||||
this.isSubDevice = isSubDevice;
|
||||
}
|
||||
|
||||
public String getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(String lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Integer getLevelInt() {
|
||||
return levelInt;
|
||||
}
|
||||
|
||||
public void setLevelInt(Integer levelInt) {
|
||||
this.levelInt = levelInt;
|
||||
}
|
||||
|
||||
public Integer getMaxDimLevel() {
|
||||
return maxDimLevel;
|
||||
}
|
||||
|
||||
public void setMaxDimLevel(Integer maxDimLevel) {
|
||||
this.maxDimLevel = maxDimLevel;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -341,127 +36,6 @@ public class DeviceResult {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNotifications() {
|
||||
return notifications;
|
||||
}
|
||||
|
||||
public void setNotifications(String notifications) {
|
||||
this.notifications = notifications;
|
||||
}
|
||||
|
||||
|
||||
public String getOffAction() {
|
||||
return offAction;
|
||||
}
|
||||
|
||||
public void setOffAction(String offAction) {
|
||||
this.offAction = offAction;
|
||||
}
|
||||
|
||||
public String getOnAction() {
|
||||
return onAction;
|
||||
}
|
||||
|
||||
public void setOnAction(String onAction) {
|
||||
this.onAction = onAction;
|
||||
}
|
||||
|
||||
public String getPlanID() {
|
||||
return planID;
|
||||
}
|
||||
|
||||
public void setPlanID(String planID) {
|
||||
this.planID = planID;
|
||||
}
|
||||
|
||||
public List<Integer> getPlanIDs() {
|
||||
return planIDs;
|
||||
}
|
||||
|
||||
public void setPlanIDs(List<Integer> planIDs) {
|
||||
this.planIDs = planIDs;
|
||||
}
|
||||
|
||||
public Boolean getProtected() {
|
||||
return _protected;
|
||||
}
|
||||
|
||||
public void setProtected(Boolean _protected) {
|
||||
this._protected = _protected;
|
||||
}
|
||||
|
||||
public Boolean getShowNotifications() {
|
||||
return showNotifications;
|
||||
}
|
||||
|
||||
public void setShowNotifications(Boolean showNotifications) {
|
||||
this.showNotifications = showNotifications;
|
||||
}
|
||||
|
||||
public String getSignalLevel() {
|
||||
return signalLevel;
|
||||
}
|
||||
|
||||
public void setSignalLevel(String signalLevel) {
|
||||
this.signalLevel = signalLevel;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStrParam1() {
|
||||
return strParam1;
|
||||
}
|
||||
|
||||
public void setStrParam1(String strParam1) {
|
||||
this.strParam1 = strParam1;
|
||||
}
|
||||
|
||||
public String getStrParam2() {
|
||||
return strParam2;
|
||||
}
|
||||
|
||||
public void setStrParam2(String strParam2) {
|
||||
this.strParam2 = strParam2;
|
||||
}
|
||||
|
||||
public String getSubType() {
|
||||
return subType;
|
||||
}
|
||||
|
||||
public void setSubType(String subType) {
|
||||
this.subType = subType;
|
||||
}
|
||||
|
||||
public String getSwitchType() {
|
||||
return switchType;
|
||||
}
|
||||
|
||||
public void setSwitchType(String switchType) {
|
||||
this.switchType = switchType;
|
||||
}
|
||||
|
||||
public Integer getSwitchTypeVal() {
|
||||
return switchTypeVal;
|
||||
}
|
||||
|
||||
public void setSwitchTypeVal(Integer switchTypeVal) {
|
||||
this.switchTypeVal = switchTypeVal;
|
||||
}
|
||||
|
||||
public String getTimers() {
|
||||
return timers;
|
||||
}
|
||||
|
||||
public void setTimers(String timers) {
|
||||
this.timers = timers;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -470,54 +44,6 @@ public class DeviceResult {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTypeImg() {
|
||||
return typeImg;
|
||||
}
|
||||
|
||||
public void setTypeImg(String typeImg) {
|
||||
this.typeImg = typeImg;
|
||||
}
|
||||
|
||||
public Integer getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(Integer unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public Integer getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public void setUsed(Integer used) {
|
||||
this.used = used;
|
||||
}
|
||||
|
||||
public Boolean getUsedByCamera() {
|
||||
return usedByCamera;
|
||||
}
|
||||
|
||||
public void setUsedByCamera(Boolean usedByCamera) {
|
||||
this.usedByCamera = usedByCamera;
|
||||
}
|
||||
|
||||
public String getXOffset() {
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
public void setXOffset(String xOffset) {
|
||||
this.xOffset = xOffset;
|
||||
}
|
||||
|
||||
public String getYOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public void setYOffset(String yOffset) {
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public String getIdx() {
|
||||
return idx;
|
||||
}
|
||||
|
||||
@@ -149,8 +149,12 @@ public class HalInfo {
|
||||
theData = httpClient.doHttpRequest(theUrl, null, null, null, null);
|
||||
if (theData != null) {
|
||||
log.debug("GET IrData for IR Device " + theHalDevice.getHaldevicename() + " HalApiResponse - data: " + theData);
|
||||
theHalApiResponse = new Gson().fromJson(theData, DeviceElements.class);
|
||||
if (theHalApiResponse.getDeviceElements() == null) {
|
||||
try {
|
||||
theHalApiResponse = new Gson().fromJson(theData, DeviceElements.class);
|
||||
} catch (Exception e) {
|
||||
theHalApiResponse = null;
|
||||
}
|
||||
if (theHalApiResponse == null || theHalApiResponse.getDeviceElements() == null) {
|
||||
StatusDescription theStatus = new Gson().fromJson(theData, StatusDescription.class);
|
||||
if (theStatus.getStatus() == null) {
|
||||
log.warn("Cannot get buttons for IR Device " + theHalDevice.getHaldevicename() + " for hal "
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HomeAssistant {
|
||||
if(aCommand.getState().equalsIgnoreCase("on")) {
|
||||
aUrl = aUrl + "/turn_on";
|
||||
if(aCommand.getBri() != null)
|
||||
aBody = aBody + ",\"state\":\"on\",\"attributes\":{\"brightness\":" + aCommand.getBri() + "}}";
|
||||
aBody = aBody + ",\"brightness\":" + aCommand.getBri() + "}";
|
||||
else
|
||||
aBody = aBody + "}";
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class HTTPHandler {
|
||||
// This function executes the url from the device repository against the
|
||||
// target as http or https as defined
|
||||
public String doHttpRequest(String url, String httpVerb, String contentType, String body, NameValue[] headers) {
|
||||
log.debug("doHttpRequest with url: " + url + " with http command: " + httpVerb + " with body: " + body);
|
||||
HttpUriRequest request = null;
|
||||
String theContent = null;
|
||||
URI theURI = null;
|
||||
|
||||
@@ -65,9 +65,17 @@ public class HueHome implements Home {
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
public DeviceResponse getHueDeviceInfo(HueDeviceIdentifier deviceId, DeviceDescriptor device) {
|
||||
public DeviceResponse getHueDeviceInfo(CallItem anItem, DeviceDescriptor device) {
|
||||
if(!validHue)
|
||||
return null;
|
||||
HueDeviceIdentifier deviceId = null;
|
||||
if(anItem.getItem().isJsonObject())
|
||||
deviceId = aGsonHandler.fromJson(anItem.getItem(), HueDeviceIdentifier.class);
|
||||
else
|
||||
deviceId = aGsonHandler.fromJson(anItem.getItem().getAsString(), HueDeviceIdentifier.class);
|
||||
if(deviceId.getHueName() == null || deviceId.getHueName().isEmpty())
|
||||
deviceId.setHueName(device.getTargetDevice());
|
||||
|
||||
DeviceResponse deviceResponse = null;
|
||||
HueInfo aHueInfo = hues.get(device.getTargetDevice());
|
||||
deviceResponse = aHueInfo.getHueDeviceInfo(deviceId.getDeviceId(), device);
|
||||
|
||||
Reference in New Issue
Block a user