Skip to content

Commit

Permalink
Fixed an introduced bug and added a new string to login URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
jannegpriv committed Feb 22, 2019
1 parent 3cfd79c commit ac23666
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Expand Up @@ -80,7 +80,8 @@ public class VerisureBindingConstants {
public static final String SMARTLOCK_LOCK_COMMAND = BASEURL + "/remotecontrol/lockunlock.cmd";
public static final String SMARTLOCK_SET_COMMAND = BASEURL + "/overview/setdoorlock.cmd";
public static final String SMARTPLUG_COMMAND = BASEURL + "/settings/smartplug/onoffplug.cmd";
public static final String START_SUF = BASEURL + "/uk/start.html";
public static final String START_REDIRECT = "/uk/start.html";
public static final String START_SUF = BASEURL + START_REDIRECT;

public static final String ALARMSTATUS_PATH = "/remotecontrol";
public static final String SMARTLOCK_PATH = "/overview/doorlock/";
Expand Down
Expand Up @@ -330,8 +330,8 @@ private void handleInstallation(String htmlText, int installationInstance) {
private synchronized boolean logIn() {
logger.debug("Attempting to log in to mypages.verisure.com");
String url = LOGON_SUF;
String source = sendHTTPpost(url, authstring);
logger.debug("Login URL: {}", url);
String source = sendHTTPpost(url, authstring);
if (source == null) {
logger.debug("Failed to login");
return false;
Expand All @@ -351,10 +351,12 @@ private void notifyListeners(VerisureThingJSON thing) {
private String sendHTTPpost(String urlString, @Nullable String data) {
if (data != null) {
try {
logger.debug("sendHTTPpost URL: {} Data:{}", urlString, data);
org.eclipse.jetty.client.api.Request request = httpClient.newRequest(urlString).method(HttpMethod.POST);
request.header("x-csrf-token", csrf).header("Accept", "application/json");
request.content(new BytesContentProvider(data.getBytes("UTF-8")),
"application/x-www-form-urlencoded; charset=UTF-8");
logger.debug("HTTP POST Request {}.", request.toString());
ContentResponse response = request.send();
String content = response.getContentAsString();
String contentUTF8 = new String(content.getBytes("UTF-8"), "ISO-8859-1");
Expand Down Expand Up @@ -409,7 +411,7 @@ private synchronized void updateVerisureBroadbandStatus(String urlString,
int instInst = verisureInstallation.getInstallationInstance();
thing.setId(Integer.toString(instInst));
VerisureThingJSON oldObj = verisureThings.get(thing.getId());
if (oldObj != null && !oldObj.equals(thing)) {
if (oldObj == null || !oldObj.equals(thing)) {
thing.setSiteId(verisureInstallation.getInstallationId());
thing.setSiteName(verisureInstallation.getInstallationName());
String id = thing.getId();
Expand Down Expand Up @@ -448,7 +450,7 @@ private synchronized void updateVerisureThings(String urlString, Class<? extends
}
}
VerisureThingJSON oldObj = verisureThings.get(thing.getId());
if (oldObj != null && !oldObj.equals(thing)) {
if (oldObj == null || !oldObj.equals(thing)) {
thing.setSiteId(inst.getInstallationId());
thing.setSiteName(inst.getInstallationName());
String id = thing.getId();
Expand Down
Expand Up @@ -117,7 +117,8 @@ public void initialize() {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Configuration of username and password is mandatory");
} else {
authstring = "j_username=" + config.username + "&j_password=" + config.password;
authstring = "j_username=" + config.username + "&j_password=" + config.password
+ "&spring-security-redirect=" + START_REDIRECT;
try {
if (session == null) {
// Configuration change
Expand Down

0 comments on commit ac23666

Please sign in to comment.