fibaro HC2 support

This commit is contained in:
diamond
2017-05-04 03:19:03 +03:00
parent ebeb6be7a7
commit d36769e2a0
29 changed files with 1041 additions and 8 deletions

View File

@@ -65,6 +65,7 @@ public class BridgeSettings extends BackupHandler {
public void buildSettings() {
String addressString = null;
String theVeraAddress = null;
String theFibaroAddress = null;
String theSomfyAddress = null;
String theHarmonyAddress = null;
String configFileProperty = System.getProperty("config.file");
@@ -107,6 +108,22 @@ public class BridgeSettings extends BackupHandler {
}
}
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;
@@ -178,6 +195,7 @@ public class BridgeSettings extends BackupHandler {
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());

View File

@@ -24,6 +24,9 @@ public class BridgeSettingsDescriptor {
@SerializedName("veraaddress")
@Expose
private IpList veraaddress;
@SerializedName("fibaroaddress")
@Expose
private IpList fibaroaddress;
@SerializedName("harmonyaddress")
@Expose
private IpList harmonyaddress;
@@ -91,6 +94,7 @@ public class BridgeSettingsDescriptor {
private boolean settingsChanged;
private boolean veraconfigured;
private boolean fibaroconfigured;
private boolean harmonyconfigured;
private boolean hueconfigured;
private boolean nestconfigured;
@@ -107,6 +111,7 @@ public class BridgeSettingsDescriptor {
this.traceupnp = false;
this.nestconfigured = false;
this.veraconfigured = false;
this.fibaroconfigured = false;
this.somfyconfigured = false;
this.harmonyconfigured = false;
this.hueconfigured = false;
@@ -153,12 +158,18 @@ public class BridgeSettingsDescriptor {
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;
}
@@ -195,12 +206,18 @@ public class BridgeSettingsDescriptor {
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;
}
@@ -356,6 +373,14 @@ public class BridgeSettingsDescriptor {
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;

View File

@@ -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"};
@@ -57,6 +59,8 @@ public class 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() {

View File

@@ -19,6 +19,7 @@ import com.bwssystems.HABridge.plugins.somfy.SomfyHome;
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 {
@@ -73,6 +74,8 @@ public class HomeManager {
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);
@@ -85,7 +88,11 @@ public class HomeManager {
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);

View File

@@ -214,6 +214,18 @@ public class DeviceResource {
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");

View File

@@ -0,0 +1,75 @@
package com.bwssystems.HABridge.plugins.fibaro;
public class Device
{
public int id;
public String name;
public int roomID;
public String type;
public String baseType;
public boolean enabled;
public boolean visible;
public boolean isPlugin;
public int parentId;
public int remoteGatewayId;
public boolean viewXml;
public boolean configXml;
public Object interfaces;
public Properties properties;
public Object actions;
public int created;
public int modified;
public int sortOrder;
public class Properties {
public String UIMessageSendTime;
public String autoConfig;
public String date;
public String dead;
public String deviceControlType;
public String deviceIcon;
public String disabled;
public String emailNotificationID;
public String emailNotificationType;
public String endPoint;
public String liliOffCommand;
public String liliOnCommand;
public String log;
public String logTemp;
public String manufacturer;
public String markAsDead;
public String model;
public String nodeID;
public String pollingDeadDevice;
public String pollingTime;
public String pollingTimeNext;
public int pollingTimeSec;
public String productInfo;
public String pushNotificationID;
public String pushNotificationType;
public String remoteGatewayId;
public String requestNodeNeighborStat;
public String requestNodeNeighborStatTimeStemp;
public String requestNodeNeighborState;
public String requestNodeNeighborStateTimeStemp;
public String saveLogs;
public String showChildren;
public String smsNotificationID;
public String smsNotificationType;
public String status;
public String sunriseHour;
public String sunsetHour;
public String userDescription;
public String value;
public String zwaveBuildVersion;
public String zwaveCompany;
public String zwaveInfo;
public String zwaveRegion;
public double zwaveVersion;
}
public String room;
public String category;
public String fibaroaddress;
public String fibaroname;
}

View File

@@ -0,0 +1,103 @@
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;
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;
}
}

View File

@@ -0,0 +1,146 @@
package com.bwssystems.HABridge.plugins.fibaro;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.NamedIP;
import com.bwssystems.HABridge.plugins.http.HTTPHandler;
import com.google.gson.Gson;
public class FibaroInfo
{
private static final Logger log = LoggerFactory.getLogger(FibaroInfo.class);
private HTTPHandler httpClient;
private NamedIP fibaroAddress;
// You can disable it if you want
boolean useSaveLogs = true; // This can be used to exclude some devices from list
boolean useUserDescription = true;
boolean removeDigits = true;
boolean scenesWithLiliCommandOnly = true;
public FibaroInfo(NamedIP addressName)
{
super();
httpClient = new HTTPHandler();
fibaroAddress = addressName;
}
public Device[] getDevices()
{
Room[] rooms = getRooms();
log.debug("Founded: " + rooms.length + ", rooms");
Device[] all_devices = getAllDevices();
int count = 0;
for(Device d : all_devices)
{
if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true)
count++;
}
Device[] devices = new Device[count];
int i = 0;
for(Device d : all_devices)
if(d.roomID > 0 && useSaveLogs ? "true".equals(d.properties.saveLogs) : true)
{
if(useUserDescription && d.properties.userDescription != null && !d.properties.userDescription.isEmpty())
d.name = d.properties.userDescription;
if(removeDigits)
d.name = replaceDigits(d.name);
devices[i++] = d;
for(Room room : rooms)
if(d.roomID == room.id)
{
d.room = room.name.trim();
d.category = String.valueOf(room.sectionID); // TODO load name of section
}
d.fibaroaddress = fibaroAddress.getIp();
d.fibaroname = fibaroAddress.getName();
}
log.debug("Founded: " + devices.length + " devices");
return devices;
}
public Scene[] getScenes()
{
Room[] rooms = getRooms();
int count = 0;
Scene[] scenes = getAllScenes();
for(Scene s : scenes)
if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty())
count++;
Scene[] result = new Scene[count];
int i = 0;
for(Scene s : scenes)
if(!scenesWithLiliCommandOnly || s.liliStartCommand != null && !s.liliStartCommand.isEmpty())
{
result[i++] = s;
for(Room room : rooms)
if(s.roomID == room.id)
{
s.room = room.name.trim();
s.category = String.valueOf(room.sectionID); // TODO load name of section
}
s.fibaroaddress = fibaroAddress.getIp();
s.fibaroname = fibaroAddress.getName();
}
System.out.println("Founded: " + count + " scenes");
return result;
}
private Device[] getAllDevices()
{
String result = request("devices?enabled=true&visible=true");
if(result == null)
return new Device[0];
Device[] devices = new Gson().fromJson(result, Device[].class);
return devices;
}
private Scene[] getAllScenes()
{
String result = request("scenes?enabled=true&visible=true");
if(result == null)
return new Scene[0];
Scene[] scenes = new Gson().fromJson(result, Scene[].class);
return scenes;
}
private Room[] getRooms()
{
String result = request("rooms");
if(result == null)
return new Room[0];
return new Gson().fromJson(result, Room[].class);
}
private String request(String theUrl)
{
theUrl = "http://" + fibaroAddress.getIp() + "/api/" + theUrl;
return httpClient.doHttpRequest(theUrl, null, null, null, null);
}
private String replaceDigits(String name)
{
name = name.replaceAll("1", "");
name = name.replaceAll("2", "");
name = name.replaceAll("3", "");
name = name.replaceAll("4", "");
name = name.replaceAll("5", "");
name = name.replaceAll("6", "");
name = name.replaceAll("7", "");
name = name.replaceAll("8", "");
name = name.replaceAll("9", "");
name = name.replaceAll("0", "");
name = name.trim();
return name;
}
}

View File

@@ -0,0 +1,19 @@
package com.bwssystems.HABridge.plugins.fibaro;
public class Room
{
public int id;
public String name;
public int sectionID;
public String icon;
public Sensor defaultSensors;
public int defaultThermostat;
public int sortOrder;
public class Sensor
{
public int temperature;
public int humidity;
public int light;
}
}

View File

@@ -0,0 +1,39 @@
package com.bwssystems.HABridge.plugins.fibaro;
public class Scene
{
public int id;
public String name;
public String type;
public String properties;
public int roomID;
public int iconID;
public String runConfig;
public boolean autostart;
public boolean protectedByPIN;
public boolean killable;
public int maxRunningInstances;
public int runningInstances;
public boolean visible;
public boolean isLua;
public Triggers triggers;
public String liliStartCommand;
public String liliStopCommand;
public int sortOrder;
public class Triggers {
public Properties[] properties;
public String[] globals;
public String[] events;
}
public class Properties {
public String id;
public String name;
}
public String room;
public String category;
public String fibaroaddress;
public String fibaroname;
}