Skip to content

Commit

Permalink
Fix always set online even when init fails.
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Jun 21, 2020
1 parent bdeee2b commit d770c0c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class BondHomeBindingConstants {

public static final String BINDING_ID = "bondhome";
public static final String CURRENT_BINDING_VERSION = "v0.01.24";
public static final String CURRENT_BINDING_VERSION = "v0.01.25";

/**
* List of all Thing Type UIDs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,12 @@ private void initializeThing() {
}
}

BondSysVersion myVersion = null;
try {
myVersion = api.getBridgeVersion();
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable to access Bond local API through bridge");
}
if (myVersion != null) {
// Update all the thing properties based on the result
Map<String, String> thingProperties = new HashMap<String, String>();
thingProperties.put(PROPERTY_VENDOR, myVersion.make);
thingProperties.put(PROPERTY_MODEL_ID, myVersion.model);
thingProperties.put(PROPERTY_SERIAL_NUMBER, myVersion.bondid);
thingProperties.put(PROPERTY_FIRMWARE_VERSION, myVersion.firmwareVersion);
updateProperties(thingProperties);
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable get Bond bridge version via API");
}
// Ask the bridge it's current status and update the properties with the info
// This will also set the thing status to online/offline based on whether it
// succeeds in getting the properties from the bridge.
updateBridgeProperties();

// Now we're online!
updateStatus(ThingStatus.ONLINE);
// Finish
logger.debug("Finished initializing Bond bridge!");
}

Expand Down Expand Up @@ -288,5 +271,29 @@ public void setBridgeOffline(ThingStatusDetail detail, String description) {
*/
public void setBridgeOnline() {
updateStatus(ThingStatus.ONLINE);
updateBridgeProperties();
}

private void updateBridgeProperties() {
BondSysVersion myVersion = null;
try {
myVersion = api.getBridgeVersion();
} catch (IOException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable to access Bond local API through bridge");
}
if (myVersion != null) {
// Update all the thing properties based on the result
Map<String, String> thingProperties = new HashMap<String, String>();
thingProperties.put(PROPERTY_VENDOR, myVersion.make);
thingProperties.put(PROPERTY_MODEL_ID, myVersion.model);
thingProperties.put(PROPERTY_SERIAL_NUMBER, myVersion.bondid);
thingProperties.put(PROPERTY_FIRMWARE_VERSION, myVersion.firmwareVersion);
updateProperties(thingProperties);
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable get Bond bridge version via API");
}
}
}

0 comments on commit d770c0c

Please sign in to comment.