Skip to content

Commit

Permalink
Fix powerview configuration to use String for id (openhab#2521)
Browse files Browse the repository at this point in the history
In 2.0, referencing a configuration defined with type 'text' as an int was allowed, so long as the value was initialized as an int originally. In 2.1, this no longer works.

Updating all references to the config to a String. Doing that instead of just changing the thing-type in order to preserve user's configuration. We don't really care about the type anyways - it's just a unique identifier for us.

Fixes openhab#2520

Signed-off-by: Andy Lintner [email protected]
  • Loading branch information
andylintner authored and kaikreuzer committed Dec 11, 2017
1 parent 1941cf6 commit 0cbbd19
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void pollShades() throws IOException {
Shades shades = webTargets.getShades();
updateStatus(ThingStatus.ONLINE);
if (shades != null) {
Map<Integer, Thing> things = getThingsByShadeId();
Map<String, Thing> things = getThingsByShadeId();
logger.debug("Found {} shades", things.size());
for (Shade shade : shades.shadeData) {
Thing thing = things.get(shade.id);
Expand Down Expand Up @@ -206,11 +206,11 @@ private void pollScenes() throws JsonParseException, IOException {
}
}

private Map<Integer, Thing> getThingsByShadeId() {
Map<Integer, Thing> ret = new HashMap<>();
private Map<String, Thing> getThingsByShadeId() {
Map<String, Thing> ret = new HashMap<>();
for (Thing thing : getThing().getThings()) {
if (thing.getThingTypeUID().equals(HDPowerViewBindingConstants.THING_TYPE_SHADE)) {
Integer id = thing.getConfiguration().as(HDPowerViewShadeConfiguration.class).id;
String id = thing.getConfiguration().as(HDPowerViewShadeConfiguration.class).id;
ret.put(id, thing);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void setPosition(ShadePosition position) {
if ((bridge = getBridgeHandler()) == null) {
return;
}
int shadeId = getShadeId();
String shadeId = getShadeId();
Response response;
try {
response = bridge.getWebTargets().moveShade(shadeId, position);
Expand All @@ -121,7 +121,7 @@ private void setPosition(ShadePosition position) {
}
}

private int getShadeId() {
private String getShadeId() {
return getConfigAs(HDPowerViewShadeConfiguration.class).id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Shades getShades() throws IOException {
}
}

public Response moveShade(int shadeId, ShadePosition position) throws IOException {
public Response moveShade(String shadeId, ShadePosition position) throws IOException {
WebTarget target = shadeMove.resolveTemplate("id", shadeId);
String body = gson.toJson(new ShadeMove(shadeId, position));
return invoke(target.request().buildPut(Entity.entity(body, MediaType.APPLICATION_JSON_TYPE)), shadeMove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
class ShadeIdPosition {

int id;
String id;
ShadePosition positions;

public ShadeIdPosition(int id, ShadePosition position) {
public ShadeIdPosition(String id, ShadePosition position) {
this.id = id;
this.positions = position;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ShadeMove {

ShadeIdPosition shade;

public ShadeMove(int id, ShadePosition position) {
public ShadeMove(String id, ShadePosition position) {
this.shade = new ShadeIdPosition(id, position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Shades {
public List<String> shadeIds;

public static class Shade {
public int id;
public String id;
String name;
public int roomId;
public int groupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class HDPowerViewShadeConfiguration {

public static String ID = "id";

public int id;
public String id;

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private Runnable createScanner() {
}
if (shades != null) {
for (Shade shade : shades.shadeData) {
ThingUID thingUID = new ThingUID(HDPowerViewBindingConstants.THING_TYPE_SHADE,
Integer.toString(shade.id));
ThingUID thingUID = new ThingUID(HDPowerViewBindingConstants.THING_TYPE_SHADE, shade.id);
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID)
.withProperty(HDPowerViewShadeConfiguration.ID, shade.id).withLabel(shade.getName())
.withBridge(hub.getThing().getUID()).build();
Expand Down

0 comments on commit 0cbbd19

Please sign in to comment.