mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Finished adding dim versus on, utf-8 and track state and return on api
calls.
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>1.4.1c</version>
|
||||
<version>1.4.1d</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bwssystems.HABridge.api.hue;
|
||||
|
||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||
|
||||
/**
|
||||
* Created by arm on 4/14/15.
|
||||
*/
|
||||
@@ -68,18 +70,18 @@ public class DeviceResponse {
|
||||
this.swversion = swversion;
|
||||
}
|
||||
|
||||
public static DeviceResponse createResponse(String name, String id){
|
||||
public static DeviceResponse createResponse(DeviceDescriptor device){
|
||||
DeviceState deviceState = new DeviceState();
|
||||
DeviceResponse response = new DeviceResponse();
|
||||
response.setState(deviceState);
|
||||
deviceState.setOn(false);
|
||||
deviceState.setOn(device.getDeviceState());
|
||||
deviceState.setReachable(true);
|
||||
deviceState.setEffect("none");
|
||||
deviceState.setAlert("none");
|
||||
deviceState.setBri(254);
|
||||
deviceState.setBri(device.getDeviceSetValue());
|
||||
|
||||
response.setName(name);
|
||||
response.setUniqueid(id);
|
||||
response.setName(device.getName());
|
||||
response.setUniqueid(device.getId());
|
||||
response.setManufacturername("Philips");
|
||||
response.setType("Dimmable light");
|
||||
response.setModelid("LWB004");
|
||||
|
||||
@@ -6,7 +6,7 @@ package com.bwssystems.HABridge.api.hue;
|
||||
*/
|
||||
public class DeviceState {
|
||||
private boolean on;
|
||||
private int bri = 255;
|
||||
private int bri = 0;
|
||||
private String effect;
|
||||
private String alert;
|
||||
private boolean reachable;
|
||||
|
||||
@@ -1,21 +1,55 @@
|
||||
package com.bwssystems.HABridge.dao;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/*
|
||||
* Object to handle the device configuration
|
||||
*/
|
||||
public class DeviceDescriptor{
|
||||
private String id;
|
||||
@SerializedName("id")
|
||||
@Expose
|
||||
private String id;
|
||||
@SerializedName("name")
|
||||
@Expose
|
||||
private String name;
|
||||
@SerializedName("mapId")
|
||||
@Expose
|
||||
private String mapId;
|
||||
@SerializedName("mapType")
|
||||
@Expose
|
||||
private String mapType;
|
||||
@SerializedName("deviceType")
|
||||
@Expose
|
||||
private String deviceType;
|
||||
@SerializedName("targetDevice")
|
||||
@Expose
|
||||
private String targetDevice;
|
||||
@SerializedName("offUrl")
|
||||
@Expose
|
||||
private String offUrl;
|
||||
@SerializedName("dimUrl")
|
||||
@Expose
|
||||
private String dimUrl;
|
||||
@SerializedName("onUrl")
|
||||
@Expose
|
||||
private String onUrl;
|
||||
@SerializedName("httpVerb")
|
||||
@Expose
|
||||
private String httpVerb;
|
||||
@SerializedName("contentType")
|
||||
@Expose
|
||||
private String contentType;
|
||||
@SerializedName("contentBody")
|
||||
@Expose
|
||||
private String contentBody;
|
||||
@SerializedName("contentBodyOff")
|
||||
@Expose
|
||||
private String contentBodyOff;
|
||||
|
||||
private boolean deviceState;
|
||||
private int deviceSetValue;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -64,7 +98,15 @@ public class DeviceDescriptor{
|
||||
this.offUrl = offUrl;
|
||||
}
|
||||
|
||||
public String getOnUrl() {
|
||||
public String getDimUrl() {
|
||||
return dimUrl;
|
||||
}
|
||||
|
||||
public void setDimUrl(String dimUrl) {
|
||||
this.dimUrl = dimUrl;
|
||||
}
|
||||
|
||||
public String getOnUrl() {
|
||||
return onUrl;
|
||||
}
|
||||
|
||||
@@ -111,6 +153,22 @@ public class DeviceDescriptor{
|
||||
public void setContentBodyOff(String contentBodyOff) {
|
||||
this.contentBodyOff = contentBodyOff;
|
||||
}
|
||||
|
||||
public boolean getDeviceState() {
|
||||
return deviceState;
|
||||
}
|
||||
|
||||
public void setDeviceState(boolean deviceState) {
|
||||
this.deviceState = deviceState;
|
||||
}
|
||||
|
||||
public int getDeviceSetValue() {
|
||||
return deviceSetValue;
|
||||
}
|
||||
|
||||
public void setDeviceSetValue(int deviceSetValue) {
|
||||
this.deviceSetValue = deviceSetValue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bwssystems.HABridge.dao;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -18,22 +17,26 @@ import org.slf4j.LoggerFactory;
|
||||
import com.bwssystems.HABridge.dao.DeviceDescriptor;
|
||||
import com.bwssystems.util.BackupHandler;
|
||||
import com.bwssystems.util.JsonTransformer;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
/*
|
||||
* This is an in memory list to manage the configured devices and saves the list as a JSON string to a file for later
|
||||
* loading.
|
||||
*/
|
||||
public class DeviceRepository extends BackupHandler {
|
||||
Map<String, DeviceDescriptor> devices;
|
||||
Path repositoryPath;
|
||||
final Random random = new Random();
|
||||
final Logger log = LoggerFactory.getLogger(DeviceRepository.class);
|
||||
private Map<String, DeviceDescriptor> devices;
|
||||
private Path repositoryPath;
|
||||
private Gson gson;
|
||||
final private Random random = new Random();
|
||||
private Logger log = LoggerFactory.getLogger(DeviceRepository.class);
|
||||
|
||||
public DeviceRepository(String deviceDb) {
|
||||
super();
|
||||
gson =
|
||||
new GsonBuilder()
|
||||
.create();
|
||||
repositoryPath = null;
|
||||
repositoryPath = Paths.get(deviceDb);
|
||||
setupParams(repositoryPath, ".bk", "device.db-");
|
||||
@@ -50,15 +53,11 @@ public class DeviceRepository extends BackupHandler {
|
||||
|
||||
if(jsonContent != null)
|
||||
{
|
||||
List<DeviceDescriptor> list = readJsonStream(jsonContent);
|
||||
ListIterator<DeviceDescriptor> theIterator = list.listIterator();
|
||||
DeviceDescriptor theDevice = null;
|
||||
while (theIterator.hasNext()) {
|
||||
theDevice = theIterator.next();
|
||||
put(theDevice.getId(), theDevice);
|
||||
DeviceDescriptor list[] = gson.fromJson(jsonContent, DeviceDescriptor[].class);
|
||||
for(int i = 0; i < list.length; i++) {
|
||||
put(list[i].getId(), list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public List<DeviceDescriptor> findAll() {
|
||||
@@ -89,8 +88,7 @@ public class DeviceRepository extends BackupHandler {
|
||||
put(descriptors[i].getId(), descriptors[i]);
|
||||
theNames = theNames + " " + descriptors[i].getName() + ", ";
|
||||
}
|
||||
JsonTransformer aRenderer = new JsonTransformer();
|
||||
String jsonValue = aRenderer.render(findAll());
|
||||
String jsonValue = gson.toJson(findAll());
|
||||
repositoryWriter(jsonValue, repositoryPath);
|
||||
log.debug("Save device(s): " + theNames);
|
||||
}
|
||||
@@ -153,82 +151,4 @@ public class DeviceRepository extends BackupHandler {
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
private List<DeviceDescriptor> readJsonStream(String context) {
|
||||
JsonReader reader = new JsonReader(new StringReader(context));
|
||||
List<DeviceDescriptor> theDescriptors = null;
|
||||
try {
|
||||
theDescriptors = readDescriptorArray(reader);
|
||||
} catch (IOException e) {
|
||||
log.error("Error reading json array: " + context + " message: " + e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Error closing json reader: " + context + " message: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return theDescriptors;
|
||||
}
|
||||
|
||||
public List<DeviceDescriptor> readDescriptorArray(JsonReader reader) throws IOException {
|
||||
List<DeviceDescriptor> descriptors = new ArrayList<DeviceDescriptor>();
|
||||
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
descriptors.add(readDescriptor(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
public DeviceDescriptor readDescriptor(JsonReader reader) throws IOException {
|
||||
DeviceDescriptor deviceEntry = new DeviceDescriptor();
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
String name = reader.nextName();
|
||||
if (name.equals("id")) {
|
||||
deviceEntry.setId(reader.nextString());
|
||||
log.debug("Read a Device - device json id: " + deviceEntry.getId());
|
||||
} else if (name.equals("name")) {
|
||||
deviceEntry.setName(reader.nextString());
|
||||
log.debug("Read a Device - device json name: " + deviceEntry.getName());
|
||||
} else if (name.equals("mapType")) {
|
||||
deviceEntry.setMapType(reader.nextString());
|
||||
log.debug("Read a Device - device json name: " + deviceEntry.getMapType());
|
||||
} else if (name.equals("mapId")) {
|
||||
deviceEntry.setMapId(reader.nextString());
|
||||
log.debug("Read a Device - device json name: " + deviceEntry.getMapId());
|
||||
} else if (name.equals("deviceType")) {
|
||||
deviceEntry.setDeviceType(reader.nextString());
|
||||
log.debug("Read a Device - device json type:" + deviceEntry.getDeviceType());
|
||||
} else if (name.equals("targetDevice")) {
|
||||
deviceEntry.setTargetDevice(reader.nextString());
|
||||
log.debug("Read a Device - device json type:" + deviceEntry.getTargetDevice());
|
||||
} else if (name.equals("offUrl")) {
|
||||
deviceEntry.setOffUrl(reader.nextString());
|
||||
log.debug("Read a Device - device json off URL:" + deviceEntry.getOffUrl());
|
||||
} else if (name.equals("onUrl")) {
|
||||
deviceEntry.setOnUrl(reader.nextString());
|
||||
log.debug("Read a Device - device json on URL:" + deviceEntry.getOnUrl());
|
||||
} else if (name.equals("httpVerb")) {
|
||||
deviceEntry.setHttpVerb(reader.nextString());
|
||||
log.debug("Read a Device - device json httpVerb:" + deviceEntry.getHttpVerb());
|
||||
} else if (name.equals("contentType")) {
|
||||
deviceEntry.setContentType(reader.nextString());
|
||||
log.debug("Read a Device - device json contentType:" + deviceEntry.getContentType());
|
||||
} else if (name.equals("contentBody")) {
|
||||
deviceEntry.setContentBody(reader.nextString());
|
||||
log.debug("Read a Device - device json contentBody:" + deviceEntry.getContentBody());
|
||||
} else if (name.equals("contentBodyOff")) {
|
||||
deviceEntry.setContentBodyOff(reader.nextString());
|
||||
log.debug("Read a Device - device json contentBodyOff:" + deviceEntry.getContentBodyOff());
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
return deviceEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,35 +115,24 @@ public class DeviceResource {
|
||||
put (API_CONTEXT + "/:id", "application/json", (request, response) -> {
|
||||
log.debug("Edit a Device - request body: " + request.body());
|
||||
DeviceDescriptor device = new Gson().fromJson(request.body(), DeviceDescriptor.class);
|
||||
DeviceDescriptor deviceEntry = deviceRepository.findOne(request.params(":id"));
|
||||
if(deviceEntry == null){
|
||||
log.debug("Could not save an edited Device Id: " + request.params(":id"));
|
||||
if(deviceRepository.findOne(request.params(":id")) == null){
|
||||
log.debug("Could not save an edited device, Device Id not found: " + request.params(":id"));
|
||||
response.status(HttpStatus.SC_BAD_REQUEST);
|
||||
return new ErrorMessage("Could not save an edited Device Id: " + request.params(":id") + " ");
|
||||
return new ErrorMessage("Could not save an edited device, Device Id not found: " + request.params(":id") + " ");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.debug("Saving an edited Device: " + deviceEntry.getName());
|
||||
log.debug("Saving an edited Device: " + device.getName());
|
||||
|
||||
deviceEntry.setName(device.getName());
|
||||
if (device.getDeviceType() != null)
|
||||
deviceEntry.setDeviceType(device.getDeviceType());
|
||||
deviceEntry.setMapId(device.getMapId());
|
||||
deviceEntry.setMapType(device.getMapType());
|
||||
deviceEntry.setTargetDevice(device.getTargetDevice());
|
||||
deviceEntry.setOnUrl(device.getOnUrl());
|
||||
deviceEntry.setOffUrl(device.getOffUrl());
|
||||
deviceEntry.setHttpVerb(device.getHttpVerb());
|
||||
deviceEntry.setContentType(device.getContentType());
|
||||
deviceEntry.setContentBody(device.getContentBody());
|
||||
deviceEntry.setContentBodyOff(device.getContentBodyOff());
|
||||
device.setDeviceType(device.getDeviceType());
|
||||
|
||||
DeviceDescriptor[] theDevices = new DeviceDescriptor[1];
|
||||
theDevices[0] = deviceEntry;
|
||||
theDevices[0] = device;
|
||||
deviceRepository.save(theDevices);
|
||||
response.status(HttpStatus.SC_OK);
|
||||
}
|
||||
return deviceEntry;
|
||||
return device;
|
||||
}, new JsonTransformer());
|
||||
|
||||
get (API_CONTEXT, "application/json", (request, response) -> {
|
||||
|
||||
@@ -101,7 +101,7 @@ public class HueMulator {
|
||||
List<DeviceDescriptor> deviceList = repository.findAll();
|
||||
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
|
||||
for (DeviceDescriptor device : deviceList) {
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(device);
|
||||
deviceResponseMap.put(device.getId(), deviceResponse);
|
||||
}
|
||||
response.type("application/json; charset=utf-8");
|
||||
@@ -225,7 +225,7 @@ public class HueMulator {
|
||||
Map<String, DeviceResponse> deviceList = new HashMap<>();
|
||||
|
||||
descriptorList.forEach(descriptor -> {
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor.getName(), descriptor.getId());
|
||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
|
||||
deviceList.put(descriptor.getId(), deviceResponse);
|
||||
}
|
||||
);
|
||||
@@ -249,7 +249,7 @@ public class HueMulator {
|
||||
} else {
|
||||
log.debug("found device named: " + device.getName());
|
||||
}
|
||||
DeviceResponse lightResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
||||
DeviceResponse lightResponse = DeviceResponse.createResponse(device);
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(HttpStatus.SC_OK);
|
||||
@@ -296,28 +296,34 @@ public class HueMulator {
|
||||
return responseString;
|
||||
}
|
||||
|
||||
if (state.isOn()) {
|
||||
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":true}}";
|
||||
url = device.getOnUrl();
|
||||
} else if (request.body().contains("false")) {
|
||||
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":false}}";
|
||||
url = device.getOffUrl();
|
||||
}
|
||||
|
||||
responseString = "[{\"success\":{\"/lights/" + lightId + "/state/on\":";
|
||||
if(request.body().contains("bri"))
|
||||
{
|
||||
if(url == null)
|
||||
{
|
||||
url = device.getOnUrl();
|
||||
responseString = "[";
|
||||
}
|
||||
else
|
||||
responseString = responseString + ",";
|
||||
url = device.getDimUrl();
|
||||
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]";
|
||||
if(url == null || url.length() == 0)
|
||||
url = device.getOnUrl();
|
||||
|
||||
responseString = responseString + "true}},{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}]";
|
||||
}
|
||||
else
|
||||
responseString = responseString + "]";
|
||||
{
|
||||
if (state.isOn()) {
|
||||
responseString = responseString + "true}}]";
|
||||
url = device.getOnUrl();
|
||||
state.setBri(255);
|
||||
} else if (request.body().contains("false")) {
|
||||
responseString = responseString + "false}}]";
|
||||
url = device.getOffUrl();
|
||||
state.setBri(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
log.warn("Could not find url: " + lightId + " for hue state change request: " + userId + " from " + request.ip() + " body: " + request.body());
|
||||
responseString = "[{\"error\":{\"type\": 3, \"address\": \"/lights/" + lightId + "\",\"description\": \"Could not find url\", \"resource\": \"/lights/" + lightId + "\"}}]";
|
||||
return responseString;
|
||||
}
|
||||
|
||||
if(device.getDeviceType().toLowerCase().contains("activity") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyActivity")))
|
||||
{
|
||||
@@ -337,7 +343,6 @@ public class HueMulator {
|
||||
else {
|
||||
log.warn("Should not get here, no harmony configured");
|
||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Should not get here, no harmony configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||
|
||||
}
|
||||
}
|
||||
else if(device.getDeviceType().toLowerCase().contains("button") || (device.getMapType() != null && device.getMapType().equalsIgnoreCase("harmonyButton")))
|
||||
@@ -456,7 +461,11 @@ public class HueMulator {
|
||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling url to change device state\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!responseString.contains("[{\"error\":")) {
|
||||
device.setDeviceSetValue(state.getBri());
|
||||
device.setDeviceState(state.isOn());
|
||||
}
|
||||
return responseString;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bwssystems.NestBridge;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class NestItem {
|
||||
private String name;
|
||||
private String id;
|
||||
@@ -9,7 +11,14 @@ public class NestItem {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
byte ptext[];
|
||||
String theLabel = new String(name);
|
||||
try {
|
||||
ptext = theLabel.getBytes("ISO-8859-1");
|
||||
this.name = new String(ptext, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
this.name = theLabel;
|
||||
}
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bwssystems.harmony;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import net.whistlingfish.harmony.config.Activity;
|
||||
|
||||
public class HarmonyActivity {
|
||||
@@ -15,6 +17,14 @@ public class HarmonyActivity {
|
||||
return activity;
|
||||
}
|
||||
public void setActivity(Activity activity) {
|
||||
byte ptext[];
|
||||
String theLabel = activity.getLabel();
|
||||
try {
|
||||
ptext = theLabel.getBytes("ISO-8859-1");
|
||||
activity.setLabel(new String(ptext, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
activity.setLabel(theLabel);
|
||||
}
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.bwssystems.harmony;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import net.whistlingfish.harmony.config.Device;
|
||||
|
||||
public class HarmonyDevice {
|
||||
@@ -9,6 +11,14 @@ public class HarmonyDevice {
|
||||
return device;
|
||||
}
|
||||
public void setDevice(Device device) {
|
||||
byte ptext[];
|
||||
String theLabel = device.getLabel();
|
||||
try {
|
||||
ptext = theLabel.getBytes("ISO-8859-1");
|
||||
device.setLabel(new String(ptext, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
device.setLabel(theLabel);
|
||||
}
|
||||
this.device = device;
|
||||
}
|
||||
public String getHub() {
|
||||
|
||||
@@ -47,27 +47,25 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], type: "", settings: [], myToastMsg: [], logMsgs: [], loggerInfo: [], olddevicename: "", logShowAll: false, isInControl: false, showVera: false, showHarmony: false, showNest: false, habridgeversion: ""};
|
||||
|
||||
this.displayWarn = function(errorTitle, error) {
|
||||
if(error == null || typeof(error) != 'undefined') {
|
||||
error = {status: 200, statusText: "OK", data: []};
|
||||
error.data = {message: "success"};
|
||||
}
|
||||
var toastContent = errorTitle;
|
||||
if(error != null && typeof(error) != 'undefined')
|
||||
toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status;
|
||||
ngToast.create({
|
||||
className: "warning",
|
||||
dismissButton: true,
|
||||
dismissOnTimeout: false,
|
||||
content: errorTitle + error.data.message + " with status: " + error.statusText + " - " + error.status});
|
||||
content: toastContent});
|
||||
};
|
||||
|
||||
this.displayError = function(errorTitle, error) {
|
||||
if(error == null || typeof(error) != 'undefined') {
|
||||
error = {status: 200, statusText: "OK", data: []};
|
||||
error.data = {message: "success"};
|
||||
}
|
||||
var toastContent = errorTitle;
|
||||
if(error != null && typeof(error) != 'undefined')
|
||||
toastContent = toastContent + " " + error.data.message + " with status: " + error.statusText + " - " + error.status;
|
||||
ngToast.create({
|
||||
className: "danger",
|
||||
dismissButton: true,
|
||||
dismissOnTimeout: false,
|
||||
content: errorTitle + error.data.message + " with status: " + error.statusText + " - " + error.status});
|
||||
content: toastContent});
|
||||
};
|
||||
|
||||
this.displayErrorMessage = function(errorTitle, errorMessage) {
|
||||
@@ -101,6 +99,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
self.state.device.mapId = null;
|
||||
self.state.device.name = "";
|
||||
self.state.device.onUrl = "";
|
||||
self.state.device.dimUrl = "";
|
||||
self.state.device.deviceType = "custom";
|
||||
self.state.device.targetDevice = null;
|
||||
self.state.device.offUrl = "";
|
||||
@@ -108,7 +107,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
self.state.device.contentType = null;
|
||||
self.state.device.contentBody = null;
|
||||
self.state.device.contentBodyOff = null;
|
||||
self.state.bridge.olddevicename = "";
|
||||
self.state.olddevicename = "";
|
||||
};
|
||||
|
||||
this.getHABridgeVersion = function () {
|
||||
@@ -303,27 +302,16 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
);
|
||||
};
|
||||
|
||||
this.addDevice = function (device) {
|
||||
this.addDevice = function (aDevice) {
|
||||
var device = {};
|
||||
angular.extend(device, aDevice );
|
||||
if(device.httpVerb != null && device.httpVerb != "")
|
||||
device.deviceType = "custom";
|
||||
if(device.targetDevice == null || device.targetDevice == "")
|
||||
device.targetDevice = "Encapsulated";
|
||||
if (device.id) {
|
||||
var putUrl = this.state.base + "/" + device.id;
|
||||
return $http.put(putUrl, {
|
||||
id: device.id,
|
||||
name: device.name,
|
||||
mapId: device.mapId,
|
||||
mapType: device.mapType,
|
||||
deviceType: device.deviceType,
|
||||
targetDevice: device.targetDevice,
|
||||
onUrl: device.onUrl,
|
||||
offUrl: device.offUrl,
|
||||
httpVerb: device.httpVerb,
|
||||
contentType: device.contentType,
|
||||
contentBody: device.contentBody,
|
||||
contentBodyOff: device.contentBodyOff
|
||||
}).then(
|
||||
return $http.put(putUrl, device).then(
|
||||
function (response) {
|
||||
},
|
||||
function (error) {
|
||||
@@ -333,19 +321,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
} else {
|
||||
if(device.deviceType == null || device.deviceType == "")
|
||||
device.deviceType = "custom";
|
||||
return $http.post(this.state.base, {
|
||||
name: device.name,
|
||||
mapId: device.mapId,
|
||||
mapType: device.mapType,
|
||||
deviceType: device.deviceType,
|
||||
targetDevice: device.targetDevice,
|
||||
onUrl: device.onUrl,
|
||||
offUrl: device.offUrl,
|
||||
httpVerb: device.httpVerb,
|
||||
contentType: device.contentType,
|
||||
contentBody: device.contentBody,
|
||||
contentBodyOff: device.contentBodyOff
|
||||
}).then(
|
||||
return $http.post(this.state.base, device).then(
|
||||
function (response) {
|
||||
},
|
||||
function (error) {
|
||||
@@ -523,11 +499,11 @@ app.service('bridgeService', function ($http, $window, ngToast) {
|
||||
var msgDescription = "unknown";
|
||||
var testUrl = this.state.huebase + "/test/lights/" + device.id + "/state";
|
||||
var testBody = "{\"on\":";
|
||||
if(type == "on") {
|
||||
testBody = testBody + "true";
|
||||
if(type == "off") {
|
||||
testBody = testBody + "false";
|
||||
}
|
||||
else {
|
||||
testBody = testBody + "false";
|
||||
testBody = testBody + "true";
|
||||
}
|
||||
if(value) {
|
||||
testBody = testBody + ",\"bri\":" + value;
|
||||
@@ -683,12 +659,15 @@ app.controller('ViewingController', function ($scope, $location, $http, $window,
|
||||
$scope.imgBkUrl = "glyphicon glyphicon-plus";
|
||||
$scope.testUrl = function (device, type) {
|
||||
var dialogNeeded = false;
|
||||
if((type == "on" && (bridgeService.aContainsB(device.onUrl, "${intensity..byte}") ||
|
||||
if((type == "on" && (bridgeService.aContainsB(device.onUrl, "${intensity.byte}") ||
|
||||
bridgeService.aContainsB(device.onUrl, "${intensity.percent}") ||
|
||||
bridgeService.aContainsB(device.onUrl, "${intensity.math("))) ||
|
||||
(type == "off" && (bridgeService.aContainsB(device.offUrl, "${intensity..byte}") ||
|
||||
(type == "off" && (bridgeService.aContainsB(device.offUrl, "${intensity.byte}") ||
|
||||
bridgeService.aContainsB(device.offUrl, "${intensity.percent}") ||
|
||||
bridgeService.aContainsB(device.offUrl, "${intensity.math(")))) {
|
||||
bridgeService.aContainsB(device.offUrl, "${intensity.math("))) ||
|
||||
(type == "dim" && (bridgeService.aContainsB(device.dimUrl, "${intensity.byte}") ||
|
||||
bridgeService.aContainsB(device.dimUrl, "${intensity.percent}") ||
|
||||
bridgeService.aContainsB(device.dimUrl, "${intensity.math(")))) {
|
||||
$scope.bridge.device = device;
|
||||
$scope.bridge.type = type;
|
||||
ngDialog.open({
|
||||
@@ -792,15 +771,18 @@ app.controller('VeraController', function ($scope, $location, $http, bridgeServi
|
||||
$scope.device.mapType = "veraDevice";
|
||||
$scope.device.mapId = veradevice.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
$scope.device.dimUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
+ veradevice.id
|
||||
+ "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget="
|
||||
+ dim_control;
|
||||
else
|
||||
$scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
$scope.device.dimUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ veradevice.id;
|
||||
$scope.device.onUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ veradevice.id;
|
||||
$scope.device.offUrl = "http://" + veradevice.veraaddress + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum="
|
||||
+ veradevice.id;
|
||||
@@ -999,8 +981,8 @@ app.controller('NestController', function ($scope, $location, $http, bridgeServi
|
||||
$scope.device.targetDevice = nestitem.location;
|
||||
$scope.device.mapType = "nestThermoSet";
|
||||
$scope.device.mapId = nestitem.id + "-SetTemp";
|
||||
$scope.device.onUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}";
|
||||
$scope.device.offUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}";
|
||||
$scope.device.dimUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"temp\",\"temp\":\"${intensity.percent}\"}";
|
||||
$scope.device.offUrl = "{\"name\":\"" + nestitem.id + "\",\"control\":\"off\"}";
|
||||
};
|
||||
|
||||
$scope.buildNestHeatUrls = function (nestitem) {
|
||||
@@ -1090,7 +1072,7 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi
|
||||
$scope.device_dim_control = "";
|
||||
$scope.bulk = { devices: [] };
|
||||
var veraList = angular.fromJson($scope.bridge.settings.veraaddress);
|
||||
if(veraList != null)
|
||||
if(veraList != null && veraList.length > 0)
|
||||
$scope.vera = {base: "http://" + veraList.devices[0].ip, port: "3480", id: ""};
|
||||
else
|
||||
$scope.vera = {base: "http://", port: "3480", id: ""};
|
||||
@@ -1110,15 +1092,18 @@ app.controller('EditController', function ($scope, $location, $http, bridgeServi
|
||||
$scope.device.mapType = "veraDevice";
|
||||
$scope.device.mapId = $scope.vera.id;
|
||||
if(dim_control.indexOf("byte") >= 0 || dim_control.indexOf("percent") >= 0 || dim_control.indexOf("math") >= 0)
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
$scope.device.dimUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&DeviceNum="
|
||||
+ $scope.vera.id
|
||||
+ "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget="
|
||||
+ dim_control;
|
||||
else
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
$scope.device.dimUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
$scope.device.offUrl = $scope.vera.base + ":" + $scope.vera.port
|
||||
+ "/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum="
|
||||
+ $scope.vera.id;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
<p>
|
||||
<button class="btn btn-info" type="submit"
|
||||
ng-click="testUrl(device, 'on')">Test ON</button>
|
||||
<button class="btn btn-info" type="submit"
|
||||
ng-click="testUrl(device, 'dim')">Test Dim</button>
|
||||
<button class="btn btn-info" type="submit"
|
||||
ng-click="testUrl(device, 'off')">Test OFF</button>
|
||||
<button class="btn btn-warning" type="submit"
|
||||
|
||||
@@ -83,6 +83,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-dim-url">Dim
|
||||
URL </label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-dim-url"
|
||||
ng-model="device.dimUrl" placeholder="URL to dim device"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
|
||||
@@ -107,6 +107,17 @@
|
||||
Clear Device</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-dim-url">Dim
|
||||
URL </label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-dim-url"
|
||||
ng-model="device.dimUrl" placeholder="URL to dim device"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
|
||||
@@ -130,6 +130,17 @@
|
||||
<button class="btn btn-danger" ng-click="clearDevice()">
|
||||
Clear Device</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label" for="device-dim-url">Dim
|
||||
URL </label>
|
||||
|
||||
<div class="col-xs-8 col-sm-7">
|
||||
<textarea rows="3" class="form-control" id="device-dim-url"
|
||||
ng-model="device.dimUrl" placeholder="URL to dim device"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<label class="col-xs-12 col-sm-2 control-label"
|
||||
|
||||
Reference in New Issue
Block a user