mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
Updated HUE API for generic config requests. Updated config parameters
to be more real.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>1.0.8</version>
|
<version>1.0.9</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ public class HueApiResponse {
|
|||||||
private Map<String, String> groups;
|
private Map<String, String> groups;
|
||||||
private HueConfig config;
|
private HueConfig config;
|
||||||
|
|
||||||
public HueApiResponse(String name, String ipaddress, String username, String userid) {
|
public HueApiResponse(String name, String ipaddress, String devicetype, String userid) {
|
||||||
super();
|
super();
|
||||||
this.setConfig(HueConfig.createConfig(name, ipaddress, username, userid));
|
this.setConfig(HueConfig.createConfig(name, ipaddress, devicetype, userid));
|
||||||
this.setGroups(new HashMap<>());
|
this.setGroups(new HashMap<>());
|
||||||
this.setScenes(new HashMap<>());
|
this.setScenes(new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
package com.bwssystems.HABridge.api.hue;
|
package com.bwssystems.HABridge.api.hue;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class HueConfig
|
public class HueConfig
|
||||||
{
|
{
|
||||||
@@ -26,10 +33,13 @@ public class HueConfig
|
|||||||
|
|
||||||
public static HueConfig createConfig(String name, String ipaddress, String devicetype, String userid) {
|
public static HueConfig createConfig(String name, String ipaddress, String devicetype, String userid) {
|
||||||
HueConfig aConfig = new HueConfig();
|
HueConfig aConfig = new HueConfig();
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
aConfig.setMac(HueConfig.getMacAddress(ipaddress));
|
||||||
aConfig.setApiversion("1.4.0");
|
aConfig.setApiversion("1.4.0");
|
||||||
aConfig.setPortalservices(false);
|
aConfig.setPortalservices(false);
|
||||||
aConfig.setGateway("192.168.1.1");
|
aConfig.setGateway(ipaddress);
|
||||||
aConfig.setMac("00:00:88:00:bb:ee");
|
|
||||||
aConfig.setSwversion("01005215");
|
aConfig.setSwversion("01005215");
|
||||||
aConfig.setLinkbutton(false);
|
aConfig.setLinkbutton(false);
|
||||||
aConfig.setIpaddress(ipaddress);
|
aConfig.setIpaddress(ipaddress);
|
||||||
@@ -38,20 +48,46 @@ public class HueConfig
|
|||||||
aConfig.setNetmask("255.255.255.0");
|
aConfig.setNetmask("255.255.255.0");
|
||||||
aConfig.setName(name);
|
aConfig.setName(name);
|
||||||
aConfig.setDhcp(true);
|
aConfig.setDhcp(true);
|
||||||
aConfig.setUtc("2014-07-17T09:27:35");
|
aConfig.setUtc(dateFormatGmt.format(new Date()));
|
||||||
aConfig.setProxyaddress("0.0.0.0");
|
aConfig.setProxyaddress("none");
|
||||||
aConfig.setLocaltime("2014-07-17T11:27:35");
|
aConfig.setLocaltime(dateFormat.format(new Date()));
|
||||||
aConfig.setTimezone("America/Chicago");
|
aConfig.setTimezone(TimeZone.getDefault().getID());
|
||||||
aConfig.setZigbeechannel("6");
|
aConfig.setZigbeechannel("6");
|
||||||
Map<String, WhitelistEntry> awhitelist = new HashMap<>();
|
Map<String, WhitelistEntry> awhitelist = new HashMap<>();
|
||||||
awhitelist.put(userid, WhitelistEntry.createEntry(devicetype));
|
awhitelist.put(userid, WhitelistEntry.createEntry(devicetype));
|
||||||
aConfig.setWhitelist(awhitelist);
|
aConfig.setWhitelist(awhitelist);
|
||||||
|
|
||||||
|
|
||||||
return aConfig;
|
return aConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getMacAddress(String addr)
|
||||||
|
{
|
||||||
|
InetAddress ip;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
try {
|
||||||
|
|
||||||
|
ip = InetAddress.getByName(addr);
|
||||||
|
|
||||||
|
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
|
||||||
|
|
||||||
|
byte[] mac = network.getHardwareAddress();
|
||||||
|
|
||||||
|
for (int i = 0; i < mac.length; i++) {
|
||||||
|
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? ":" : ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
|
||||||
|
sb.append("00:00:88:00:bb:ee");
|
||||||
|
|
||||||
|
} catch (SocketException e){
|
||||||
|
|
||||||
|
sb.append("00:00:88:00:bb:ee");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
public Boolean getPortalservices() {
|
public Boolean getPortalservices() {
|
||||||
return portalservices;
|
return portalservices;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,31 @@ public class HueMulator {
|
|||||||
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
|
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// http://ip_address:port/api/config returns json objects for the config when no user is given
|
||||||
|
get(HUE_CONTEXT + "/config", "application/json", (request, response) -> {
|
||||||
|
String userId = request.params(":userid");
|
||||||
|
log.debug("hue api config requested: " + userId + " from " + request.ip());
|
||||||
|
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||||
|
|
||||||
|
response.type("application/json; charset=utf-8");
|
||||||
|
response.status(HttpStatus.SC_OK);
|
||||||
|
String responseString = null;
|
||||||
|
responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
|
||||||
|
return responseString;
|
||||||
|
});
|
||||||
|
|
||||||
|
// http://ip_address:port/api/{userId}/config returns json objects for the config
|
||||||
|
get(HUE_CONTEXT + "/:userid/config", "application/json", (request, response) -> {
|
||||||
|
String userId = request.params(":userid");
|
||||||
|
log.debug("hue api config requested: " + userId + " from " + request.ip());
|
||||||
|
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||||
|
|
||||||
|
response.type("application/json; charset=utf-8");
|
||||||
|
response.status(HttpStatus.SC_OK);
|
||||||
|
return apiResponse.getConfig();
|
||||||
|
}, new JsonTransformer());
|
||||||
|
|
||||||
|
|
||||||
// http://ip_address:port/api/{userId} returns json objects for the full state
|
// http://ip_address:port/api/{userId} returns json objects for the full state
|
||||||
get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> {
|
get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> {
|
||||||
String userId = request.params(":userid");
|
String userId = request.params(":userid");
|
||||||
|
|||||||
Reference in New Issue
Block a user