Skip to content

Commit

Permalink
Merge pull request #413 from bwssytems/targetV4.1.0
Browse files Browse the repository at this point in the history
Target v4.1.0
  • Loading branch information
bwssytems authored Jan 27, 2017
2 parents b08a285 + 0bcc162 commit a091262
Show file tree
Hide file tree
Showing 46 changed files with 1,973 additions and 212 deletions.
216 changes: 154 additions & 62 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>4.0.3</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<name>HA Bridge</name>
Expand Down Expand Up @@ -217,4 +217,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
13 changes: 4 additions & 9 deletions src/main/java/com/bwssystems/HABridge/BridgeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,10 @@ public void buildSettings() {
if(theBridgeSettings.getUpnpDeviceDb() == null)
theBridgeSettings.setUpnpDeviceDb(Configuration.DEVICE_DB_DIRECTORY);

if(theBridgeSettings.getNumberoflogmessages() == null)
if(theBridgeSettings.getNumberoflogmessages() == null || theBridgeSettings.getNumberoflogmessages() <= 0)
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));

if(theBridgeSettings.getNumberoflogmessages() <= 0)
theBridgeSettings.setNumberoflogmessages(new Integer(Configuration.NUMBER_OF_LOG_MESSAGES));

if(theBridgeSettings.getButtonsleep() == null)
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));

if(theBridgeSettings.getButtonsleep() < 0)
if(theBridgeSettings.getButtonsleep() == null || theBridgeSettings.getButtonsleep() < 0)
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));

theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera());
Expand All @@ -153,7 +147,8 @@ public void buildSettings() {
theBridgeSettings.setHalconfigured(theBridgeSettings.isValidHal());
theBridgeSettings.setMqttconfigured(theBridgeSettings.isValidMQTT());
theBridgeSettings.setHassconfigured(theBridgeSettings.isValidHass());
if(serverPortOverride != null)
theBridgeSettings.setDomoticzconfigured(theBridgeSettings.isValidDomoticz());
if(serverPortOverride != null)
theBridgeSettings.setServerPort(serverPortOverride);
if(serverIpOverride != null)
theBridgeSettings.setWebaddress(serverIpOverride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class BridgeSettingsDescriptor {
private IpList hassaddress;
private boolean hassconfigured;
private String hubversion;
private IpList domoticzaddress;
private boolean domoticzconfigured;

public BridgeSettingsDescriptor() {
super();
Expand Down Expand Up @@ -249,6 +251,18 @@ public String getHubversion() {
public void setHubversion(String hubversion) {
this.hubversion = hubversion;
}
public IpList getDomoticzaddress() {
return domoticzaddress;
}
public void setDomoticzaddress(IpList domoticzaddress) {
this.domoticzaddress = domoticzaddress;
}
public boolean isDomoticzconfigured() {
return domoticzconfigured;
}
public void setDomoticzconfigured(boolean domoticzconfigured) {
this.domoticzconfigured = domoticzconfigured;
}
public Boolean isValidVera() {
if(this.getVeraAddress() == null || this.getVeraAddress().getDevices().size() <= 0)
return false;
Expand Down Expand Up @@ -306,4 +320,12 @@ public Boolean isValidHass() {
return false;
return true;
}
public Boolean isValidDomoticz() {
if(this.getDomoticzaddress() == null || this.getDomoticzaddress().getDevices().size() <= 0)
return false;
List<NamedIP> devicesList = this.getDomoticzaddress().getDevices();
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
return false;
return true;
}
}
6 changes: 4 additions & 2 deletions src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class DeviceMapTypes {
public final static String[] UDP_DEVICE = { "udpDevice", "UDP Device"};
public final static String[] UDP_DEVICE_COMPAT = { "UDP", "UDP Device"};
public final static String[] HTTP_DEVICE = { "httpDevice", "HTTP Device"};
public final static String[] DOMOTICZ_DEVICE = { "domoticzDevice", "Domoticz Device"};

public final static int typeIndex = 0;
public final static int displayIndex = 1;
Expand All @@ -35,10 +36,13 @@ public DeviceMapTypes() {
super();
deviceMapTypes = new ArrayList<String[]>();
deviceMapTypes.add(CMD_DEVICE);
deviceMapTypes.add(DOMOTICZ_DEVICE);
deviceMapTypes.add(HAL_DEVICE);
deviceMapTypes.add(HAL_HOME);
deviceMapTypes.add(HAL_THERMO_SET);
deviceMapTypes.add(HAL_BUTTON);
deviceMapTypes.add(HARMONY_ACTIVITY);
deviceMapTypes.add(HARMONY_BUTTON);
deviceMapTypes.add(HASS_DEVICE);
deviceMapTypes.add(HTTP_DEVICE);
deviceMapTypes.add(HUE_DEVICE);
Expand All @@ -49,8 +53,6 @@ public DeviceMapTypes() {
deviceMapTypes.add(UDP_DEVICE);
deviceMapTypes.add(VERA_DEVICE);
deviceMapTypes.add(VERA_SCENE);
deviceMapTypes.add(HARMONY_ACTIVITY);
deviceMapTypes.add(HARMONY_BUTTON);
}
public static int getTypeIndex() {
return typeIndex;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/bwssystems/HABridge/HomeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.bwssystems.HABridge.devicemanagmeent.ResourceHandler;
import com.bwssystems.HABridge.plugins.NestBridge.NestHome;
import com.bwssystems.HABridge.plugins.domoticz.DomoticzHome;
import com.bwssystems.HABridge.plugins.exec.CommandHome;
import com.bwssystems.HABridge.plugins.hal.HalHome;
import com.bwssystems.HABridge.plugins.harmony.HarmonyHome;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void buildHomes(BridgeSettingsDescriptor bridgeSettings, UDPDatagramSende
homeList.put(DeviceMapTypes.CUSTOM_DEVICE[DeviceMapTypes.typeIndex], aHome);
homeList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome);
homeList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome);
homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome);
//setup the tcp handler Home
aHome = new TCPHome(bridgeSettings);
homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome);
Expand All @@ -81,6 +83,9 @@ public void buildHomes(BridgeSettingsDescriptor bridgeSettings, UDPDatagramSende
aHome = new VeraHome(bridgeSettings);
resourceList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome);
resourceList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome);
//setup the HomeAssistant configuration if available
aHome = new DomoticzHome(bridgeSettings);
resourceList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome);
}

public Home findHome(String type) {
Expand Down
40 changes: 39 additions & 1 deletion src/main/java/com/bwssystems/HABridge/api/hue/GroupResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import java.util.List;

import com.bwssystems.HABridge.dao.DeviceDescriptor;
import com.google.gson.annotations.SerializedName;

public class GroupResponse {
@SerializedName("action")
private DeviceState action;
@SerializedName("lights")
private String[] lights;
@SerializedName("name")
private String name;
@SerializedName("type")
private String type;
@SerializedName("class")
String class_name;

public DeviceState getAction() {
return action;
}
Expand All @@ -27,7 +36,19 @@ public void setName(String name) {
this.name = name;
}

public static GroupResponse createGroupResponse(List<DeviceDescriptor> deviceList) {
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
public static GroupResponse createDefaultGroupResponse(List<DeviceDescriptor> deviceList) {
String[] theList = new String[deviceList.size()];
int i = 0;
for (DeviceDescriptor device : deviceList) {
Expand All @@ -38,6 +59,23 @@ public static GroupResponse createGroupResponse(List<DeviceDescriptor> deviceLis
theResponse.setAction(DeviceState.createDeviceState());
theResponse.setName("Lightset 0");
theResponse.setLights(theList);
theResponse.setType("LightGroup");
return theResponse;
}
public static GroupResponse createOtherGroupResponse(List<DeviceDescriptor> deviceList) {
String[] theList = new String[deviceList.size()];
int i = 0;
for (DeviceDescriptor device : deviceList) {
theList[i] = device.getId();
i++;
}
GroupResponse theResponse = new GroupResponse();
theResponse.setAction(DeviceState.createDeviceState());
theResponse.setName("AGroup");
theResponse.setLights(theList);
theResponse.setType("Room");
theResponse.setClass_name("Other");

return theResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class HueApiResponse {
private Map<String, DeviceResponse> lights;
private Map<String, JsonObject> scenes;
private Map<String, JsonObject> groups;
private Map<String, GroupResponse> groups;
private Map<String, JsonObject> schedules;
private Map<String, JsonObject> sensors;
private Map<String, JsonObject> rules;
Expand Down Expand Up @@ -44,11 +44,11 @@ public void setScenes(Map<String, JsonObject> scenes) {
this.scenes = scenes;
}

public Map<String, JsonObject> getGroups() {
public Map<String, GroupResponse> getGroups() {
return groups;
}

public void setGroups(Map<String, JsonObject> groups) {
public void setGroups(Map<String, GroupResponse> groups) {
this.groups = groups;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bwssystems.HABridge.api.hue;

public class HueConstants {
public final static String HUB_VERSION = "01036562";
public final static String HUB_VERSION = "01036659";
public final static String API_VERSION = "1.15.0";
public final static String MODEL_ID = "BSB002";
public final static String UUID_PREFIX = "2f402f80-da50-11e1-9b23-";
Expand Down
42 changes: 41 additions & 1 deletion src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class DeviceDescriptor{
@SerializedName("contentBodyDim")
@Expose
private String contentBodyDim;
@SerializedName("inactive")
@Expose
private boolean inactive;
@SerializedName("noState")
@Expose
private boolean noState;

private DeviceState deviceState;

Expand Down Expand Up @@ -197,4 +203,38 @@ public void setDeviceState(DeviceState deviceState) {
this.deviceState = deviceState;
}

}
public boolean isInactive() {
return inactive;
}

public void setInactive(boolean inactive) {
this.inactive = inactive;
}

public boolean isNoState() {
return noState;
}

public void setNoState(boolean noState) {
this.noState = noState;
}

public boolean containsType(String aType) {
if(this.mapType.contains(aType))
return true;

if(this.deviceType.contains(aType))
return true;

if(this.onUrl.contains(aType))
return true;

if(this.dimUrl.contains(aType))
return true;

if(this.offUrl.contains(aType))
return true;

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public List<DeviceDescriptor> findAll() {
return list;
}

public List<DeviceDescriptor> findActive() {
List<DeviceDescriptor> list = new ArrayList<DeviceDescriptor>();
for(DeviceDescriptor aDevice : new ArrayList<DeviceDescriptor>(devices.values())) {
if(!aDevice.isInactive())
list.add(aDevice);
}
return list;
}

public DeviceDescriptor findOne(String id) {
return devices.get(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ private void setupEndpoints() {
return homeManager.findResource(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.HASS_DEVICE[DeviceMapTypes.typeIndex]);
}, new JsonTransformer());

get (API_CONTEXT + "/domoticz/devices", "application/json", (request, response) -> {
log.debug("Get Domoticz Clients");
response.status(HttpStatus.SC_OK);
return homeManager.findResource(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex]);
}, new JsonTransformer());

get (API_CONTEXT + "/map/types", "application/json", (request, response) -> {
log.debug("Get map types");
return new DeviceMapTypes().getDeviceMapTypes();
Expand Down
Loading

0 comments on commit a091262

Please sign in to comment.