mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20dedec8ab | ||
|
|
580c037b1e | ||
|
|
77cb064d60 | ||
|
|
0e4319ea1d | ||
|
|
c61e623e23 | ||
|
|
669483f686 |
@@ -26,7 +26,10 @@ java -jar ha-bridge-2.5.0.jar
|
||||
### Automation on Linux systems
|
||||
To have this configured and running automatically there are a few resources to use. One is using Docker and a docker container has been built for this and can be gotten here: https://github.com/aptalca/docker-ha-bridge
|
||||
|
||||
For next gen Linux systems, here is a systemctl unit file that you can install. Here is a link on how to do this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
|
||||
For next gen Linux systems (this includes the Raspberry Pi), here is a systemctl unit file that you can install. Here is a link on how to do this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
|
||||
|
||||
*NOTE ON RC.LOCAL*: Due to the way network subsystem is brought up on the pi, it uses the new systemctl to start services. The old style runlevel setup, which rc.local is part of does not get the benefit of knowing if the network has been fully realized. Starting ha-bridge from rc.local on next gen systems will cause unexpected results and issues with discovering registered devices.
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=HA Bridge
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -9,7 +9,10 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -178,14 +181,15 @@ public class BridgeSettings extends BackupHandler {
|
||||
|
||||
private void _loadConfig(Path aPath) {
|
||||
String jsonContent = configReader(aPath);
|
||||
if(jsonContent == null)
|
||||
return;
|
||||
try {
|
||||
theBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
|
||||
theBridgeSettings = new Gson().fromJson(jsonContent, BridgeSettingsDescriptor.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("Issue loading values from file: " + aPath.toUri().toString() + ", Gson convert failed.");
|
||||
theBridgeSettings = new BridgeSettingsDescriptor();
|
||||
theBridgeSettings.setConfigfile(aPath.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void save(BridgeSettingsDescriptor newBridgeSettings) {
|
||||
@@ -219,6 +223,19 @@ public class BridgeSettings extends BackupHandler {
|
||||
Files.move(filePath, target);
|
||||
}
|
||||
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
|
||||
|
||||
// set attributes to be for user only
|
||||
// using PosixFilePermission to set file permissions
|
||||
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
|
||||
// add owners permission
|
||||
perms.add(PosixFilePermission.OWNER_READ);
|
||||
perms.add(PosixFilePermission.OWNER_WRITE);
|
||||
|
||||
try {
|
||||
Files.setPosixFilePermissions(filePath, perms);
|
||||
} catch(UnsupportedOperationException e) {
|
||||
log.info("Cannot set permissions for config file on this system as it is not supported. Continuing");
|
||||
}
|
||||
if(target != null)
|
||||
Files.delete(target);
|
||||
} catch (IOException e) {
|
||||
@@ -233,7 +250,6 @@ public class BridgeSettings extends BackupHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
content = new String(Files.readAllBytes(filePath));
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -17,6 +17,7 @@ public class DeviceState {
|
||||
private String colormode;
|
||||
private boolean reachable;
|
||||
private List<Double> xy;
|
||||
private int transitiontime;
|
||||
|
||||
public boolean isOn() {
|
||||
return on;
|
||||
@@ -97,7 +98,15 @@ public class DeviceState {
|
||||
public void setXy(List<Double> xy) {
|
||||
this.xy = xy;
|
||||
}
|
||||
public static DeviceState createDeviceState() {
|
||||
public int getTransitiontime() {
|
||||
return transitiontime;
|
||||
}
|
||||
|
||||
public void setTransitiontime(int transitiontime) {
|
||||
this.transitiontime = transitiontime;
|
||||
}
|
||||
|
||||
public static DeviceState createDeviceState() {
|
||||
DeviceState newDeviceState = new DeviceState();
|
||||
newDeviceState.fillIn();
|
||||
// newDeviceState.setColormode("none");
|
||||
|
||||
@@ -519,14 +519,16 @@ public class HueMulator implements HueErrorStringSet {
|
||||
else
|
||||
{
|
||||
if (theStateChanges.isOn()) {
|
||||
state.setOn(true);
|
||||
if(state.getBri() <= 0)
|
||||
state.setBri(255);
|
||||
} else {
|
||||
state.setOn(false);
|
||||
state.setBri(0);
|
||||
}
|
||||
}
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId, device.getDeviceState());
|
||||
device.getDeviceState().setBri(calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc));
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId);
|
||||
|
||||
return responseString;
|
||||
});
|
||||
@@ -625,9 +627,9 @@ public class HueMulator implements HueErrorStringSet {
|
||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||
|
||||
if(responseString == null || !responseString.contains("[{\"error\":")) {
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId, state);
|
||||
state.setBri(calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc));
|
||||
device.setDeviceState(state);
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId);
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
@@ -882,9 +884,9 @@ public class HueMulator implements HueErrorStringSet {
|
||||
}
|
||||
|
||||
if(responseString == null || !responseString.contains("[{\"error\":")) {
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId, state);
|
||||
state.setBri(calculateIntensity(state, theStateChanges, stateHasBri, stateHasBriInc));
|
||||
device.setDeviceState(state);
|
||||
responseString = this.formatSuccessHueResponse(theStateChanges, request.body(), lightId);
|
||||
}
|
||||
return responseString;
|
||||
});
|
||||
@@ -1036,7 +1038,7 @@ public class HueMulator implements HueErrorStringSet {
|
||||
return responseString;
|
||||
}
|
||||
|
||||
private String formatSuccessHueResponse(StateChangeBody state, String body, String lightId) {
|
||||
private String formatSuccessHueResponse(StateChangeBody state, String body, String lightId, DeviceState deviceState) {
|
||||
|
||||
String responseString = "[";
|
||||
boolean notFirstChange = false;
|
||||
@@ -1048,6 +1050,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
} else {
|
||||
responseString = responseString + "false}}";
|
||||
}
|
||||
if(deviceState != null)
|
||||
deviceState.setOn(state.isOn());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1056,6 +1060,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri\":" + state.getBri() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setBri(state.getBri());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1064,7 +1070,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/bri_inc\":" + state.getBri_inc() + "}}";
|
||||
notFirstChange = true;
|
||||
//INFO: Bright inc check for deviceState needs to be outside of this method
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
if(body.contains("\"ct\""))
|
||||
@@ -1072,6 +1079,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/ct\":" + state.getCt() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setCt(state.getCt());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1080,6 +1089,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/xy\":" + state.getXy() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setXy(state.getXy());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1088,6 +1099,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/hue\":" + state.getHue() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setHue(state.getHue());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1096,6 +1109,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/sat\":" + state.getSat() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setSat(state.getSat());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1104,6 +1119,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/ct_inc\":" + state.getCt_inc() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setCt(deviceState.getCt() + state.getCt_inc());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1112,6 +1129,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/xy_inc\":" + state.getXy_inc() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setXy(state.getXy());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1120,6 +1139,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/hue_inc\":" + state.getHue_inc() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setHue(deviceState.getHue() + state.getHue_inc());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1128,6 +1149,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/sat_inc\":" + state.getSat_inc() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setSat(deviceState.getSat() + state.getSat_inc());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1136,6 +1159,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/effect\":" + state.getEffect() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setEffect(state.getEffect());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1144,6 +1169,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/transitiontime\":" + state.getTransitiontime() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setTransitiontime(state.getTransitiontime());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
@@ -1152,6 +1179,8 @@ public class HueMulator implements HueErrorStringSet {
|
||||
if(notFirstChange)
|
||||
responseString = responseString + ",";
|
||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/alert\":" + state.getAlert() + "}}";
|
||||
if(deviceState != null)
|
||||
deviceState.setAlert(state.getAlert());
|
||||
notFirstChange = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user