Search in sources :

Example 6 with CallItem

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());
    }
}
Also used : LocationItem(org.openhab.core.library.items.LocationItem) StringType(org.openhab.core.library.types.StringType) ColorItem(org.openhab.core.library.items.ColorItem) DateTimeItem(org.openhab.core.library.items.DateTimeItem) PlayerItem(org.openhab.core.library.items.PlayerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DimmerItem(org.openhab.core.library.items.DimmerItem) HSBType(org.openhab.core.library.types.HSBType) SwitchItem(org.openhab.core.library.items.SwitchItem) ContactItem(org.openhab.core.library.items.ContactItem) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) RewindFastforwardType(org.openhab.core.library.types.RewindFastforwardType) NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) State(org.openhab.core.types.State) PlayPauseType(org.openhab.core.library.types.PlayPauseType) DecimalType(org.openhab.core.library.types.DecimalType) CallItem(org.openhab.core.library.items.CallItem) ImageItem(org.openhab.core.library.items.ImageItem)

Aggregations

CallItem (org.openhab.core.library.items.CallItem)6 ColorItem (org.openhab.core.library.items.ColorItem)4 ContactItem (org.openhab.core.library.items.ContactItem)4 DateTimeItem (org.openhab.core.library.items.DateTimeItem)4 DimmerItem (org.openhab.core.library.items.DimmerItem)4 LocationItem (org.openhab.core.library.items.LocationItem)4 NumberItem (org.openhab.core.library.items.NumberItem)4 PlayerItem (org.openhab.core.library.items.PlayerItem)4 RollershutterItem (org.openhab.core.library.items.RollershutterItem)4 SwitchItem (org.openhab.core.library.items.SwitchItem)4 StringItem (org.openhab.core.library.items.StringItem)3 State (org.openhab.core.types.State)3 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ImageItem (org.openhab.core.library.items.ImageItem)2 DateTimeType (org.openhab.core.library.types.DateTimeType)2 DecimalType (org.openhab.core.library.types.DecimalType)2 HSBType (org.openhab.core.library.types.HSBType)2 PercentType (org.openhab.core.library.types.PercentType)2 StringListType (org.openhab.core.library.types.StringListType)2 StringType (org.openhab.core.library.types.StringType)2