Skip to content

Commit

Permalink
[nanoleaf] Bugfix: Handle non-integer panel ids (openhab#13951)
Browse files Browse the repository at this point in the history
Panel ids are sometimes returned as BigInteger

We haven't been able to understand why this happens somewhere and
somewhere not, but this is an sledgehammer attempt to fix it quickly
to unblock users, and then we will try to understand it later.

Discussions:
https://community.openhab.org/t/java-lang-classcastexception-class-java-math-bigdecimal-cannot-be-cast-to-class-java-lang-integer/142035/16
https://community.openhab.org/t/nanoleaf-binding-oh3-stabilization-update/116300/61

Signed-off-by: Jørgen Austvik <[email protected]>
Signed-off-by: Ben Rosenblum <[email protected]>
austvik authored and morph166955 committed Dec 18, 2022

Verified

This commit was signed with the committer’s verified signature.
saw-jan Sawjan Gurung
1 parent 6815c67 commit bd0d5b9
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -286,7 +286,21 @@ public void updatePanelGesture(int gesture) {
}

public Integer getPanelID() {
return (Integer) getThing().getConfiguration().get(CONFIG_PANEL_ID);
Object panelId = getThing().getConfiguration().get(CONFIG_PANEL_ID);
if (panelId instanceof Integer) {
return (Integer) panelId;
} else if (panelId instanceof Number) {
return ((Number) panelId).intValue();
} else {
// Fall back to parsing string representation of panel if it is not returning an integer
String stringPanelId = panelId.toString();
Integer parsedPanelId = Integer.getInteger(stringPanelId);
if (parsedPanelId == null) {
return 0;
} else {
return parsedPanelId;
}
}
}

private void setPanelColor(HSBType color) {

0 comments on commit bd0d5b9

Please sign in to comment.