Skip to content

Commit

Permalink
Merge pull request #109 from halfninja/hue-bridge-register-fix
Browse files Browse the repository at this point in the history
Hue bridge register fix
  • Loading branch information
ekux44 authored Jun 10, 2016
2 parents 4589bdd + 46f3296 commit e5be0a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ public static void PreformGetBulbList(Route route, String hash, Context context,

public static void PreformRegister(RequestQueue queue,
Listener<RegistrationResponse[]>[] listeners, Bridge[] bridges,
String username,
String deviceType) {
if (queue == null || bridges == null) {
return;
}
Gson gson = new Gson();
RegistrationRequest request = new RegistrationRequest();
request.username = username;
request.devicetype = deviceType;
String registrationRequest = gson.toJson(request);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.kuxhausen.huemore.net.hue.api;

public class RegistrationRequest {

public String username;
public String devicetype;

public RegistrationRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ResponseError {
}

public class ResponseSuccess {
private String username;

public String getUsername() {
return username;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,15 @@ public void onTick(long millisUntilFinished) {
progressBar
.setProgress((int) (((length_in_milliseconds - millisUntilFinished) * 100.0)
/ length_in_milliseconds));
NetworkMethods.PreformRegister(rq, getListeners(getUserName()), bridges, getUserName(),
getDeviceType());
NetworkMethods.PreformRegister(rq, getListeners(), bridges, getDeviceType());
}
}

@Override
public void onFinish() {
if (isAdded()) {
// try one last time
NetworkMethods.PreformRegister(rq, getListeners(getUserName()), bridges, getUserName(),
getDeviceType());
NetworkMethods.PreformRegister(rq, getListeners(), bridges, getDeviceType());

// launch the failed registration dialog
RegistrationFailDialogFragment rfdf = new RegistrationFailDialogFragment();
Expand All @@ -116,11 +114,11 @@ public void onFinish() {
return builder.create();
}

protected Listener<RegistrationResponse[]>[] getListeners(String username) {
protected Listener<RegistrationResponse[]>[] getListeners() {
Listener<RegistrationResponse[]>[] listeners = new Listener[bridges.length];
for (int i = 0; i < bridges.length; i++) {
if (bridges[i] != null && bridges[i].internalipaddress != null) {
listeners[i] = new RegistrationListener(bridges[i].internalipaddress, username);
listeners[i] = new RegistrationListener(bridges[i].internalipaddress);
}
}
return listeners;
Expand All @@ -133,36 +131,16 @@ public void onSaveInstanceState(Bundle outState) {
onDestroyView();
}

public String getUserName() {

try {
MessageDigest md;
String serialID = Settings.Secure.ANDROID_ID;
md = MessageDigest.getInstance(InternalArguments.MD5);
String resultString = new BigInteger(1, md.digest(serialID.getBytes())).toString(16);

return resultString;
} catch (NoSuchAlgorithmException e) {

e.printStackTrace();
}

// fall back on hash of hueMore if android ID fails
return InternalArguments.FALLBACK_USERNAME_HASH;
}

public String getDeviceType() {
return getString(R.string.app_name);
}

class RegistrationListener implements Listener<RegistrationResponse[]> {

public String bridgeIP;
public String username;

public RegistrationListener(String ip, String userName) {
public RegistrationListener(String ip) {
bridgeIP = ip;
username = userName;
}

@Override
Expand All @@ -185,7 +163,7 @@ public void onResponse(RegistrationResponse[] response) {
} else {
mHubData.localHubAddress = bridgeIP;
}
mHubData.hashedUsername = username;
mHubData.hashedUsername = response[0].success.getUsername();
ContentValues cv = new ContentValues();

cv.put(Definitions.NetConnectionColumns.TYPE_COLUMN,
Expand Down

0 comments on commit e5be0a2

Please sign in to comment.