use of org.openhab.io.neeo.internal.models.NeeoDeviceType in project openhab-addons by openhab.
the class NeeoDeviceSerializer method deserialize.
@Override
@Nullable
public NeeoDevice deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext) throws JsonParseException {
if (!(elm instanceof JsonObject)) {
throw new JsonParseException("Element not an instance of JsonObject: " + elm);
}
final JsonObject jo = (JsonObject) elm;
final NeeoThingUID uid = jsonContext.deserialize(jo.get("uid"), NeeoThingUID.class);
final NeeoDeviceType devType = jsonContext.deserialize(jo.get("type"), NeeoDeviceType.class);
final String manufacturer = NeeoUtil.getString(jo, "manufacturer");
final String name = NeeoUtil.getString(jo, "name");
final NeeoDeviceChannel[] channels = jsonContext.deserialize(jo.get("channels"), NeeoDeviceChannel[].class);
final NeeoDeviceTiming timing = jo.has("timing") ? jsonContext.deserialize(jo.get("timing"), NeeoDeviceTiming.class) : null;
final String[] deviceCapabilities = jo.has("deviceCapabilities") ? jsonContext.deserialize(jo.get("deviceCapabilities"), String[].class) : null;
final String specificName = jo.has("specificName") ? jo.get("specificName").getAsString() : null;
final String iconName = jo.has("iconName") ? jo.get("iconName").getAsString() : null;
final int driverVersion = jo.has("driverVersion") ? jo.get("driverVersion").getAsInt() : 0;
try {
return new NeeoDevice(uid, driverVersion, devType, manufacturer == null || manufacturer.isEmpty() ? NeeoUtil.NOTAVAILABLE : manufacturer, name, Arrays.asList(channels), timing, deviceCapabilities == null ? null : Arrays.asList(deviceCapabilities), specificName, iconName);
} catch (NullPointerException | IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
Aggregations