use of org.openhab.core.library.items.CallItem in project openhab-addons by openhab.
the class AbstractDynamoDBItem method fromStateNew.
public static DynamoDBItem<?> fromStateNew(Item item, ZonedDateTime time, @Nullable Integer expireDays) {
String name = item.getName();
State state = item.getState();
if (item instanceof CallItem) {
return new DynamoDBStringItem(name, convert(state, StringListType.class).toFullString(), time, expireDays);
} else if (item instanceof ContactItem) {
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof DateTimeItem) {
return new DynamoDBStringItem(name, ZONED_DATE_TIME_CONVERTER_STRING.toString(((DateTimeType) state).getZonedDateTime()), time, expireDays);
} else if (item instanceof ImageItem) {
throw new IllegalArgumentException("Unsupported item " + item.getClass().getSimpleName());
} else if (item instanceof LocationItem) {
return new DynamoDBStringItem(name, state.toFullString(), time, expireDays);
} else if (item instanceof NumberItem) {
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof PlayerItem) {
if (state instanceof PlayPauseType) {
switch((PlayPauseType) state) {
case PLAY:
return new DynamoDBBigDecimalItem(name, PLAY_BIGDECIMAL, time, expireDays);
case PAUSE:
return new DynamoDBBigDecimalItem(name, PAUSE_BIGDECIMAL, time, expireDays);
default:
throw new IllegalArgumentException("Unexpected enum with PlayPauseType: " + state.toString());
}
} else if (state instanceof RewindFastforwardType) {
switch((RewindFastforwardType) state) {
case FASTFORWARD:
return new DynamoDBBigDecimalItem(name, FAST_FORWARD_BIGDECIMAL, time, expireDays);
case REWIND:
return new DynamoDBBigDecimalItem(name, REWIND_BIGDECIMAL, time, expireDays);
default:
throw new IllegalArgumentException("Unexpected enum with RewindFastforwardType: " + state.toString());
}
} else {
throw new IllegalStateException(String.format("Unexpected state type %s with PlayerItem", state.getClass().getSimpleName()));
}
} else if (item instanceof RollershutterItem) {
// Normalize UP/DOWN to %
return new DynamoDBBigDecimalItem(name, convert(state, PercentType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof StringItem) {
if (state instanceof StringType) {
return new DynamoDBStringItem(name, ((StringType) state).toString(), time, expireDays);
} else if (state instanceof DateTimeType) {
return new DynamoDBStringItem(name, ZONED_DATE_TIME_CONVERTER_STRING.toString(((DateTimeType) state).getZonedDateTime()), time, expireDays);
} else {
throw new IllegalStateException(String.format("Unexpected state type %s with StringItem", state.getClass().getSimpleName()));
}
} else if (item instanceof ColorItem) {
// Note: needs to be before parent class DimmerItem
return new DynamoDBStringItem(name, convert(state, HSBType.class).toFullString(), time, expireDays);
} else if (item instanceof DimmerItem) {
// Normalize ON/OFF to %
return new DynamoDBBigDecimalItem(name, convert(state, PercentType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof SwitchItem) {
// Normalize ON/OFF to 1/0
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else {
throw new IllegalArgumentException("Unsupported item " + item.getClass().getSimpleName());
}
}
Aggregations