mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
updated upnp discovery calls to be more like the hue.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>0.3.3</version>
|
||||
<version>0.3.5</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||
@@ -9,6 +10,16 @@ import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||
*/
|
||||
public class HueApiResponse {
|
||||
private Map<String, DeviceResponse> lights;
|
||||
private Map<String, String> scenes;
|
||||
private Map<String, String> groups;
|
||||
private HueConfig config;
|
||||
|
||||
public HueApiResponse(String name, String ipaddress, String username, String userid) {
|
||||
super();
|
||||
this.setConfig(HueConfig.createConfig(name, ipaddress, username, userid));
|
||||
this.setGroups(new HashMap<>());
|
||||
this.setScenes(new HashMap<>());
|
||||
}
|
||||
|
||||
public Map<String, DeviceResponse> getLights() {
|
||||
return lights;
|
||||
@@ -17,4 +28,28 @@ public class HueApiResponse {
|
||||
public void setLights(Map<String, DeviceResponse> lights) {
|
||||
this.lights = lights;
|
||||
}
|
||||
|
||||
public Map<String, String> getScenes() {
|
||||
return scenes;
|
||||
}
|
||||
|
||||
public void setScenes(Map<String, String> scenes) {
|
||||
this.scenes = scenes;
|
||||
}
|
||||
|
||||
public Map<String, String> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void setGroups(Map<String, String> groups) {
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
public HueConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(HueConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
|
||||
198
src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java
Normal file
198
src/main/java/com/bwssystems/HABridge/api/hue/HueConfig.java
Normal file
@@ -0,0 +1,198 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HueConfig
|
||||
{
|
||||
private Boolean portalservices;
|
||||
private String gateway;
|
||||
private String mac;
|
||||
private String swversion;
|
||||
private String apiversion;
|
||||
private Boolean linkbutton;
|
||||
private String ipaddress;
|
||||
private Integer proxyport;
|
||||
private Swupdate swupdate;
|
||||
private String netmask;
|
||||
private String name;
|
||||
private Boolean dhcp;
|
||||
private String UTC;
|
||||
private String proxyaddress;
|
||||
private String localtime;
|
||||
private String timezone;
|
||||
private String zigbeechannel;
|
||||
private Map<String, WhitelistEntry> whitelist;
|
||||
|
||||
public static HueConfig createConfig(String name, String ipaddress, String devicetype, String userid) {
|
||||
HueConfig aConfig = new HueConfig();
|
||||
aConfig.setApiversion("1.4.0");
|
||||
aConfig.setPortalservices(false);
|
||||
aConfig.setGateway("192.168.1.1");
|
||||
aConfig.setMac("00:00:88:00:bb:ee");
|
||||
aConfig.setSwversion("01005215");
|
||||
aConfig.setLinkbutton(false);
|
||||
aConfig.setIpaddress(ipaddress);
|
||||
aConfig.setProxyport(0);
|
||||
aConfig.setSwupdate(Swupdate.createSwupdate());
|
||||
aConfig.setNetmask("255.255.255.0");
|
||||
aConfig.setName(name);
|
||||
aConfig.setDhcp(true);
|
||||
aConfig.setUtc("2014-07-17T09:27:35");
|
||||
aConfig.setProxyaddress("0.0.0.0");
|
||||
aConfig.setLocaltime("2014-07-17T11:27:35");
|
||||
aConfig.setTimezone("America/Chicago");
|
||||
aConfig.setZigbeechannel("6");
|
||||
Map<String, WhitelistEntry> awhitelist = new HashMap<>();
|
||||
awhitelist.put(userid, WhitelistEntry.createEntry(devicetype));
|
||||
aConfig.setWhitelist(awhitelist);
|
||||
|
||||
|
||||
return aConfig;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getPortalservices() {
|
||||
return portalservices;
|
||||
}
|
||||
|
||||
public void setPortalservices(Boolean portalservices) {
|
||||
this.portalservices = portalservices;
|
||||
}
|
||||
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
public void setGateway(String gateway) {
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public void setMac(String mac) {
|
||||
this.mac = mac;
|
||||
}
|
||||
|
||||
public String getSwversion() {
|
||||
return swversion;
|
||||
}
|
||||
|
||||
public void setSwversion(String swversion) {
|
||||
this.swversion = swversion;
|
||||
}
|
||||
|
||||
public Boolean getLinkbutton() {
|
||||
return linkbutton;
|
||||
}
|
||||
|
||||
public void setLinkbutton(Boolean linkbutton) {
|
||||
this.linkbutton = linkbutton;
|
||||
}
|
||||
|
||||
public String getIpaddress() {
|
||||
return ipaddress;
|
||||
}
|
||||
|
||||
public void setIpaddress(String ipaddress) {
|
||||
this.ipaddress = ipaddress;
|
||||
}
|
||||
|
||||
public Integer getProxyport() {
|
||||
return proxyport;
|
||||
}
|
||||
|
||||
public void setProxyport(Integer proxyport) {
|
||||
this.proxyport = proxyport;
|
||||
}
|
||||
|
||||
public Swupdate getSwupdate() {
|
||||
return swupdate;
|
||||
}
|
||||
|
||||
public void setSwupdate(Swupdate swupdate) {
|
||||
this.swupdate = swupdate;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
public void setNetmask(String netmask) {
|
||||
this.netmask = netmask;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Boolean getDhcp() {
|
||||
return dhcp;
|
||||
}
|
||||
|
||||
public void setDhcp(Boolean dhcp) {
|
||||
this.dhcp = dhcp;
|
||||
}
|
||||
|
||||
public String getUtc() {
|
||||
return UTC;
|
||||
}
|
||||
|
||||
public void setUtc(String utc) {
|
||||
this.UTC = utc;
|
||||
}
|
||||
|
||||
public String getProxyaddress() {
|
||||
return proxyaddress;
|
||||
}
|
||||
|
||||
public void setProxyaddress(String proxyaddress) {
|
||||
this.proxyaddress = proxyaddress;
|
||||
}
|
||||
|
||||
public Map<String, WhitelistEntry> getWhitelist() {
|
||||
return whitelist;
|
||||
}
|
||||
|
||||
public void setWhitelist(Map<String, WhitelistEntry> whitelist) {
|
||||
this.whitelist = whitelist;
|
||||
}
|
||||
|
||||
public String getApiversion() {
|
||||
return apiversion;
|
||||
}
|
||||
|
||||
public void setApiversion(String apiversion) {
|
||||
this.apiversion = apiversion;
|
||||
}
|
||||
|
||||
public String getLocaltime() {
|
||||
return localtime;
|
||||
}
|
||||
|
||||
public void setLocaltime(String localtime) {
|
||||
this.localtime = localtime;
|
||||
}
|
||||
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
public void setTimezone(String timezone) {
|
||||
this.timezone = timezone;
|
||||
}
|
||||
|
||||
public String getZigbeechannel() {
|
||||
return zigbeechannel;
|
||||
}
|
||||
|
||||
public void setZigbeechannel(String zigbeechannel) {
|
||||
this.zigbeechannel = zigbeechannel;
|
||||
}
|
||||
}
|
||||
52
src/main/java/com/bwssystems/HABridge/api/hue/Swupdate.java
Normal file
52
src/main/java/com/bwssystems/HABridge/api/hue/Swupdate.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
|
||||
public class Swupdate
|
||||
{
|
||||
private String text;
|
||||
private Boolean notify;
|
||||
private Integer updatestate;
|
||||
private String url;
|
||||
|
||||
public static Swupdate createSwupdate() {
|
||||
Swupdate aSwupdate = new Swupdate();
|
||||
aSwupdate.setNotify(false);
|
||||
aSwupdate.setText("");
|
||||
aSwupdate.setUpdatestate(0);
|
||||
aSwupdate.setUrl("");
|
||||
return aSwupdate;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Boolean getNotify() {
|
||||
return notify;
|
||||
}
|
||||
|
||||
public void setNotify(Boolean notify) {
|
||||
this.notify = notify;
|
||||
}
|
||||
|
||||
public Integer getUpdatestate() {
|
||||
return updatestate;
|
||||
}
|
||||
|
||||
public void setUpdatestate(Integer updatestate) {
|
||||
this.updatestate = updatestate;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class WhitelistEntry
|
||||
{
|
||||
private String lastUseDate;
|
||||
private String createDate;
|
||||
private String name;
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
|
||||
public static WhitelistEntry createEntry(String devicetype) {
|
||||
WhitelistEntry anEntry = new WhitelistEntry();
|
||||
anEntry.setName(devicetype);
|
||||
anEntry.setCreateDate(getCurrentDate());
|
||||
anEntry.setLastUseDate(getCurrentDate());
|
||||
return anEntry;
|
||||
}
|
||||
|
||||
public static String getCurrentDate() {
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
|
||||
public String getLastUseDate() {
|
||||
return lastUseDate;
|
||||
}
|
||||
|
||||
public void setLastUseDate(String lastUseDate) {
|
||||
this.lastUseDate = lastUseDate;
|
||||
}
|
||||
|
||||
public String getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(String createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,6 +64,7 @@ public class HueMulator {
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
||||
deviceResponseMap.put(device.getId(), deviceResponse);
|
||||
}
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(200);
|
||||
return deviceResponseMap;
|
||||
} , new JsonTransformer());
|
||||
@@ -77,6 +78,7 @@ public class HueMulator {
|
||||
newUser = "lightssystem";
|
||||
log.debug("hue api user create requested for device type: " + aNewUser.getDevicetype() + " and username: " + newUser);
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(200);
|
||||
return "[{\"success\":{\"username\":\"" + newUser + "\"}}]";
|
||||
} );
|
||||
@@ -97,9 +99,10 @@ public class HueMulator {
|
||||
deviceList.put(descriptor.getId(), deviceResponse);
|
||||
}
|
||||
);
|
||||
HueApiResponse apiResponse = new HueApiResponse();
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||
apiResponse.setLights(deviceList);
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(200);
|
||||
return apiResponse;
|
||||
}, new JsonTransformer());
|
||||
@@ -118,6 +121,7 @@ public class HueMulator {
|
||||
}
|
||||
DeviceResponse lightResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(200);
|
||||
return lightResponse;
|
||||
}, new JsonTransformer());
|
||||
@@ -183,6 +187,7 @@ public class HueMulator {
|
||||
return null;
|
||||
}
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(200);
|
||||
return responseString;
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UpnpSettingsResource {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(UpnpSettingsResource.class);
|
||||
|
||||
private String hueTemplate = "<?xml version=\"1.0\"?>\n" + "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
|
||||
private String hueTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n"
|
||||
+ "<specVersion>\n" + "<major>1</major>\n" + "<minor>0</minor>\n" + "</specVersion>\n"
|
||||
+ "<URLBase>http://%s:%s/</URLBase>\n" + // hostname string
|
||||
"<device>\n" + "<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>\n"
|
||||
@@ -26,7 +26,7 @@ public class UpnpSettingsResource {
|
||||
+ "<modelDescription>Hue Emulator for HA bridge</modelDescription>\n"
|
||||
+ "<modelName>Philips hue bridge 2012</modelName>\n" + "<modelNumber>929000226503</modelNumber>\n"
|
||||
+ "<modelURL>http://www.bwssystems.com/apps.html</modelURL>\n"
|
||||
+ "<serialNumber>01189998819991197253</serialNumber>\n"
|
||||
+ "<serialNumber>0017880ae670</serialNumber>\n"
|
||||
+ "<UDN>uuid:88f6698f-2c83-4393-bd03-cd54a9f8595</UDN>\n" + "<serviceList>\n" + "<service>\n"
|
||||
+ "<serviceType>(null)</serviceType>\n" + "<serviceId>(null)</serviceId>\n"
|
||||
+ "<controlURL>(null)</controlURL>\n" + "<eventSubURL>(null)</eventSubURL>\n"
|
||||
@@ -46,12 +46,23 @@ public class UpnpSettingsResource {
|
||||
private void setupListener (BridgeSettings theSettings) {
|
||||
log.info("Hue description service started....");
|
||||
// http://ip_adress:port/description.xml which returns the xml configuration for the hue emulator
|
||||
get("/description.xml", "application/xml", (request, response) -> {
|
||||
get("/description.xml", "application/xml; charset=utf-8", (request, response) -> {
|
||||
log.debug("upnp device settings requested: " + request.params(":id") + " from " + request.ip());
|
||||
String portNumber = Integer.toString(request.port());
|
||||
String filledTemplate = String.format(hueTemplate, theSettings.getUpnpConfigAddress(), portNumber, theSettings.getUpnpConfigAddress());
|
||||
log.debug("upnp device settings response: " + filledTemplate);
|
||||
response.status(201);
|
||||
// response.header("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
|
||||
// response.header("Pragma", "no-cache");
|
||||
// response.header("Expires", "Mon, 1 Aug 2011 09:00:00 GMT");
|
||||
// response.header("Connection", "close"); // Not sure if the server will actually close the connections by just setting the header
|
||||
// response.header("Access-Control-Max-Age", "0");
|
||||
// response.header("Access-Control-Allow-Origin", "*");
|
||||
// response.header("Access-Control-Allow-Credentials", "true");
|
||||
// response.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE");
|
||||
// response.header("Access-Control-Allow-Headers", "Content-Type");
|
||||
// response.header("Content-Type", "application/xml; charset=utf-8");
|
||||
response.type("application/xml; charset=utf-8");
|
||||
response.status(200);
|
||||
|
||||
return filledTemplate;
|
||||
} );
|
||||
@@ -60,7 +71,7 @@ public class UpnpSettingsResource {
|
||||
get(UPNP_CONTEXT + "/settings", "application/json", (request, response) -> {
|
||||
log.debug("bridge settings requested from " + request.ip());
|
||||
|
||||
response.status(201);
|
||||
response.status(200);
|
||||
|
||||
return theSettings;
|
||||
}, new JsonTransformer());
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||
<li><a href="http://www.bwssystems.com" target="_blank">Developed by BWS Systems</a></li>
|
||||
<li><a href="http://www.amazon.com/echo" target="_blank">Amazon Echo</a></li>
|
||||
<li><a href="#">HA Bridge Version 0.3.2</a></li>
|
||||
<li><a href="#">HA Bridge Version 0.3.5</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user