Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fibaro into branch for 5.0 #785

Merged
merged 5 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/com/bwssystems/HABridge/BridgeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static String getCurrentDate() {
public void buildSettings() {
String addressString = null;
String theVeraAddress = null;
String theFibaroAddress = null;
String theSomfyAddress = null;
String theHarmonyAddress = null;
String configFileProperty = System.getProperty("config.file");
Expand Down Expand Up @@ -107,6 +108,22 @@ public void buildSettings() {
}
}
theBridgeSettings.setVeraAddress(theVeraList);

theFibaroAddress = System.getProperty("fibaro.address");
IpList theFibaroList = null;
if(theFibaroAddress != null) {
try {
theFibaroList = new Gson().fromJson(theFibaroAddress, IpList.class);
} catch (Exception e) {
try {
theFibaroList = new Gson().fromJson("{devices:[{name:default,ip:" + theFibaroAddress + "}]}", IpList.class);
} catch (Exception et) {
log.error("Cannot parse fibaro.address, not set with message: " + e.getMessage(), e);
theFibaroList = null;
}
}
}
theBridgeSettings.setFibaroAddress(theFibaroList);

theHarmonyAddress = System.getProperty("harmony.address");
IpList theHarmonyList = null;
Expand Down Expand Up @@ -178,6 +195,7 @@ public void buildSettings() {
theBridgeSettings.setButtonsleep(Integer.parseInt(Configuration.DEFAULT_BUTTON_SLEEP));

theBridgeSettings.setVeraconfigured(theBridgeSettings.isValidVera());
theBridgeSettings.setFibaroconfigured(theBridgeSettings.isValidFibaro());
theBridgeSettings.setHarmonyconfigured(theBridgeSettings.isValidHarmony());
theBridgeSettings.setNestConfigured(theBridgeSettings.isValidNest());
theBridgeSettings.setHueconfigured(theBridgeSettings.isValidHue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class BridgeSettingsDescriptor {
@SerializedName("veraaddress")
@Expose
private IpList veraaddress;
@SerializedName("fibaroaddress")
@Expose
private IpList fibaroaddress;
@SerializedName("harmonyaddress")
@Expose
private IpList harmonyaddress;
Expand Down Expand Up @@ -94,6 +97,7 @@ public class BridgeSettingsDescriptor {

private boolean settingsChanged;
private boolean veraconfigured;
private boolean fibaroconfigured;
private boolean harmonyconfigured;
private boolean hueconfigured;
private boolean nestconfigured;
Expand All @@ -111,6 +115,7 @@ public BridgeSettingsDescriptor() {
this.traceupnp = false;
this.nestconfigured = false;
this.veraconfigured = false;
this.fibaroconfigured = false;
this.somfyconfigured = false;
this.harmonyconfigured = false;
this.hueconfigured = false;
Expand Down Expand Up @@ -166,12 +171,18 @@ public void setUpnpDeviceDb(String upnpDeviceDb) {
public IpList getVeraAddress() {
return veraaddress;
}
public IpList getFibaroAddress() {
return fibaroaddress;
}
public IpList getSomfyAddress() {
return somfyaddress;
}
public void setVeraAddress(IpList veraAddress) {
this.veraaddress = veraAddress;
}
public void setFibaroAddress(IpList fibaroAddress) {
this.fibaroaddress = fibaroAddress;
}
public void setSomfyAddress(IpList somfyAddress) {
this.somfyaddress = somfyAddress;
}
Expand Down Expand Up @@ -208,12 +219,18 @@ public void setNestpwd(String nestpwd) {
public boolean isVeraconfigured() {
return veraconfigured;
}
public boolean isFibaroconfigured() {
return fibaroconfigured;
}
public boolean isSomfyconfigured() {
return somfyconfigured;
}
public void setVeraconfigured(boolean veraconfigured) {
this.veraconfigured = veraconfigured;
}
public void setFibaroconfigured(boolean fibaroconfigured) {
this.fibaroconfigured = fibaroconfigured;
}
public void setSomfyconfigured(boolean somfyconfigured) {
this.somfyconfigured = somfyconfigured;
}
Expand Down Expand Up @@ -369,6 +386,14 @@ public Boolean isValidVera() {
return false;
return true;
}
public Boolean isValidFibaro() {
if(this.getFibaroAddress() == null || this.getFibaroAddress().getDevices().size() <= 0)
return false;
List<NamedIP> devicesList = this.getFibaroAddress().getDevices();
if(devicesList.get(0).getIp().contains(Configuration.DEFAULT_ADDRESS))
return false;
return true;
}
public Boolean isValidHarmony() {
if(this.getHarmonyAddress() == null || this.getHarmonyAddress().getDevices().size() <= 0)
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/bwssystems/HABridge/DeviceMapTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class DeviceMapTypes {
public final static String[] CUSTOM_DEVICE = { "custom", "Custom"};
public final static String[] VERA_DEVICE = { "veraDevice", "Vera Device"};
public final static String[] VERA_SCENE = { "veraScene", "Vera Scene"};
public final static String[] FIBARO_DEVICE = { "fibaroDevice", "Fibaro Device"};
public final static String[] FIBARO_SCENE = { "fibaroScene", "Fibaro Scene"};
public final static String[] HARMONY_ACTIVITY = { "harmonyActivity", "Harmony Activity"};
public final static String[] HARMONY_BUTTON = { "harmonyButton", "Harmony Button"};
public final static String[] NEST_HOMEAWAY = { "nestHomeAway", "Nest Home Status"};
Expand Down Expand Up @@ -57,6 +59,8 @@ public DeviceMapTypes() {
deviceMapTypes.add(UDP_DEVICE);
deviceMapTypes.add(VERA_DEVICE);
deviceMapTypes.add(VERA_SCENE);
deviceMapTypes.add(FIBARO_DEVICE);
deviceMapTypes.add(FIBARO_SCENE);
deviceMapTypes.add(SOMFY_DEVICE);
}
public static int getTypeIndex() {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/bwssystems/HABridge/HomeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.bwssystems.HABridge.plugins.tcp.TCPHome;
import com.bwssystems.HABridge.plugins.udp.UDPHome;
import com.bwssystems.HABridge.plugins.vera.VeraHome;
import com.bwssystems.HABridge.plugins.fibaro.FibaroHome;
import com.bwssystems.HABridge.util.UDPDatagramSender;

public class HomeManager {
Expand Down Expand Up @@ -73,6 +74,8 @@ public void buildHomes(BridgeSettings bridgeSettings, UDPDatagramSender aUdpData
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.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome);
homeList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome);
//setup the tcp handler Home
aHome = new TCPHome(bridgeSettings);
homeList.put(DeviceMapTypes.TCP_DEVICE[DeviceMapTypes.typeIndex], aHome);
Expand All @@ -85,7 +88,11 @@ public void buildHomes(BridgeSettings bridgeSettings, UDPDatagramSender aUdpData
aHome = new VeraHome(bridgeSettings);
resourceList.put(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex], aHome);
resourceList.put(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex], aHome);
//setup the Domoticz configuration if available
// Setup Fibaro Home if available
aHome = new FibaroHome(bridgeSettings);
resourceList.put(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex], aHome);
resourceList.put(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex], aHome);
//setup the Domoticz configuration if available
aHome = new DomoticzHome(bridgeSettings);
homeList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome);
resourceList.put(DeviceMapTypes.DOMOTICZ_DEVICE[DeviceMapTypes.typeIndex], aHome);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/bwssystems/HABridge/NamedIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class NamedIP {
private String name;
private String ip;
private String webhook;
private String ip;
private String webhook;
private String port;
private String username;
private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ private void setupEndpoints() {
response.status(HttpStatus.SC_OK);
return homeManager.findResource(DeviceMapTypes.VERA_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.VERA_SCENE[DeviceMapTypes.typeIndex]);
}, new JsonTransformer());

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

get (API_CONTEXT + "/fibaro/scenes", "application/json", (request, response) -> {
log.debug("Get fibaro scenes");
response.status(HttpStatus.SC_OK);
return homeManager.findResource(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex]).getItems(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex]);
}, new JsonTransformer());

get (API_CONTEXT + "/harmony/activities", "application/json", (request, response) -> {
log.debug("Get harmony activities");
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/com/bwssystems/HABridge/plugins/fibaro/FibaroHome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.bwssystems.HABridge.plugins.fibaro;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.DeviceMapTypes;
import com.bwssystems.HABridge.Home;
import com.bwssystems.HABridge.NamedIP;
import com.bwssystems.HABridge.api.CallItem;
import com.bwssystems.HABridge.dao.DeviceDescriptor;
import com.bwssystems.HABridge.hue.MultiCommandUtil;
import com.bwssystems.HABridge.plugins.fibaro.json.Device;
import com.bwssystems.HABridge.plugins.fibaro.json.Scene;

public class FibaroHome implements Home
{
private static final Logger log = LoggerFactory.getLogger(FibaroHome.class);
private Map<String, FibaroInfo> fibaros;
private Boolean validFibaro;

public FibaroHome(BridgeSettings bridgeSettings)
{
super();
createHome(bridgeSettings);
}

public List<Device> getDevices()
{
log.debug("consolidating devices for fibaros");
Iterator<String> keys = fibaros.keySet().iterator();
ArrayList<Device> deviceList = new ArrayList<>();
while(keys.hasNext())
{
String key = keys.next();
for(Device device : fibaros.get(key).getDevices())
deviceList.add(device);
}
return deviceList;
}

public List<Scene> getScenes()
{
log.debug("consolidating scenes for fibaros");
Iterator<String> keys = fibaros.keySet().iterator();
ArrayList<Scene> sceneList = new ArrayList<>();
while(keys.hasNext())
{
String key = keys.next();
for(Scene scene : fibaros.get(key).getScenes())
sceneList.add(scene);
}
return sceneList;
}

@Override
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity, Integer targetBri, Integer targetBriInc, DeviceDescriptor device, String body)
{
// Not a device handler
return null;
}

@Override
public Object getItems(String type)
{
if(validFibaro)
{
if(type.equalsIgnoreCase(DeviceMapTypes.FIBARO_DEVICE[DeviceMapTypes.typeIndex]))
return getDevices();
if(type.equalsIgnoreCase(DeviceMapTypes.FIBARO_SCENE[DeviceMapTypes.typeIndex]))
return getScenes();
}
return null;
}

@Override
public Home createHome(BridgeSettings bridgeSettings)
{
validFibaro = bridgeSettings.getBridgeSettingsDescriptor().isValidFibaro();
log.info("Fibaro Home created." + (validFibaro ? "" : " No Fibaros configured."));
if(validFibaro)
{
fibaros = new HashMap<String, FibaroInfo>();
Iterator<NamedIP> theList = bridgeSettings.getBridgeSettingsDescriptor().getFibaroAddress().getDevices().iterator();
while(theList.hasNext())
{
NamedIP aFibaro = theList.next();
fibaros.put(aFibaro.getName(), new FibaroInfo(aFibaro));
}
}
return this;
}

@Override
public void closeHome()
{
fibaros = null;
}
}
Loading