Skip to content

Instantly share code, notes, and snippets.

@mikebertiean
Last active January 26, 2016 19:14
Show Gist options
  • Select an option

  • Save mikebertiean/22d9296198a8ba249712 to your computer and use it in GitHub Desktop.

Select an option

Save mikebertiean/22d9296198a8ba249712 to your computer and use it in GitHub Desktop.
Software update of a Philips Hue bridge
private void checkForUpdate() {
String originalVersion = bridge.getResourceCache().getBridgeConfiguration().getSoftwareVersion();
boolean showToast = true;
bridge.getResourceCache().getBridgeConfiguration().setPortalServicesEnabled(true);
if(bridge.getResourceCache().getBridgeConfiguration().getPortalState().getSignedOn()){
bridge.getResourceCache().getBridgeConfiguration().setCheckForUpdate(true); //set the check for update flag to true
Toast.makeText(this, "Checking for update ...",Toast.LENGTH_LONG).show();
while(bridge.getResourceCache().getBridgeConfiguration().getCheckForUpdate() != null){
Log.wtf("While Loop", bridge.getResourceCache().getBridgeConfiguration().getCheckForUpdate() + "");
} //run this until checkforupdate = false or timeout after 5 mins
//If we are still signed on
if(bridge.getResourceCache().getBridgeConfiguration().getPortalState().getSignedOn()){
if(bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().getState() == PHSoftwareUpdateStatus.PHStateType.NO_UPDATE){ //state 0
Toast.makeText(this, "There is no update available.",Toast.LENGTH_LONG).show(); //ALWAYS GETS HERE
}
else{ //the state is not 0 so it is either 1,2 or 3
while(bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().getState() == PHSoftwareUpdateStatus.PHStateType.UPDATE_DOWNLOADING){ //state 1
if(showToast) {
Toast.makeText(this, "Downloading update ... Please wait this may take some time.", Toast.LENGTH_LONG).show();
showToast = false;
}
}
//finished downloading now it is ready for install
if(bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().getState() == PHSoftwareUpdateStatus.PHStateType.UPDATE_READY_FOR_INSTALL){ //state 2
showToast = true;
Toast.makeText(this, "System update available", Toast.LENGTH_SHORT).show();
bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().setState(3); //going from state 2 -> 3 starts the install process
}
while(bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().getState() == PHSoftwareUpdateStatus.PHStateType.INSTALLING_UPDATES){ //state 3
if(showToast) {
Toast.makeText(this, "Installing update... Please wait", Toast.LENGTH_LONG).show();
showToast = false;
}
}
if(bridge.getResourceCache().getBridgeConfiguration().getSoftwareVersion().compareTo(originalVersion) != 0) {
//SUCCESS!!
Toast.makeText(this, "Bridge updated!",Toast.LENGTH_LONG).show();
bridge.getResourceCache().getBridgeConfiguration().getSoftwareStatus().setNotify(false);
}
else
Toast.makeText(this, "Update could not be applied.",Toast.LENGTH_LONG).show();
}
}
else{ //if the while loop timed out
Toast.makeText(this, "There is no portal connection.",Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(this, "There is no portal connection.",Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment