mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
testing for changes: 3.0.0 not storing extended values (2.0.7 does),
update state not always working, Pi3 systemd not starting, habridge.config created readable by everyone
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>3.0.0</version>
|
||||
<version>3.0.0a</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -9,6 +9,14 @@ 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.AclEntry;
|
||||
import java.nio.file.attribute.AclEntryPermission;
|
||||
import java.nio.file.attribute.AclEntryType;
|
||||
import java.nio.file.attribute.AclFileAttributeView;
|
||||
import java.nio.file.attribute.UserPrincipal;
|
||||
import java.nio.file.attribute.UserPrincipalLookupService;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.http.conn.util.InetAddressUtils;
|
||||
@@ -178,14 +186,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 +228,19 @@ public class BridgeSettings extends BackupHandler {
|
||||
Files.move(filePath, target);
|
||||
}
|
||||
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
|
||||
|
||||
// set attributes to be for user only
|
||||
UserPrincipalLookupService upls = filePath.getFileSystem().getUserPrincipalLookupService();
|
||||
UserPrincipal user = upls.lookupPrincipalByName(System.getProperty("user.name"));
|
||||
AclEntry.Builder builder = AclEntry.newBuilder();
|
||||
builder.setPermissions( EnumSet.of(AclEntryPermission.READ_DATA, AclEntryPermission.EXECUTE,
|
||||
AclEntryPermission.READ_ACL, AclEntryPermission.READ_ATTRIBUTES, AclEntryPermission.READ_NAMED_ATTRS,
|
||||
AclEntryPermission.WRITE_ACL, AclEntryPermission.DELETE
|
||||
));
|
||||
builder.setPrincipal(user);
|
||||
builder.setType(AclEntryType.ALLOW);
|
||||
AclFileAttributeView aclAttr = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
|
||||
aclAttr.setAcl(Collections.singletonList(builder.build()));
|
||||
if(target != null)
|
||||
Files.delete(target);
|
||||
} catch (IOException e) {
|
||||
@@ -233,7 +255,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