Search in sources :

Example 11 with DateTimeType

use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.

the class EcobeeBinding method createState.

/**
     * Creates an openHAB {@link State} in accordance to the class of the given {@code propertyValue}. Currently
     * {@link Date}, {@link BigDecimal}, {@link Temperature} and {@link Boolean} are handled explicitly. All other
     * {@code dataTypes} are mapped to {@link StringType}.
     * <p>
     * If {@code propertyValue} is {@code null}, {@link UnDefType#NULL} will be returned.
     *
     * Copied/adapted from the Koubachi binding.
     *
     * @param propertyValue
     *
     * @return the new {@link State} in accordance with {@code dataType}. Will never be {@code null}.
     */
private State createState(Object propertyValue) {
    if (propertyValue == null) {
        return UnDefType.NULL;
    }
    Class<?> dataType = propertyValue.getClass();
    if (Date.class.isAssignableFrom(dataType)) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime((Date) propertyValue);
        return new DateTimeType(calendar);
    } else if (Integer.class.isAssignableFrom(dataType)) {
        return new DecimalType((Integer) propertyValue);
    } else if (BigDecimal.class.isAssignableFrom(dataType)) {
        return new DecimalType((BigDecimal) propertyValue);
    } else if (Boolean.class.isAssignableFrom(dataType)) {
        if ((Boolean) propertyValue) {
            return OnOffType.ON;
        } else {
            return OnOffType.OFF;
        }
    } else if (Temperature.class.isAssignableFrom(dataType)) {
        return new DecimalType(((Temperature) propertyValue).toLocalTemperature());
    } else if (State.class.isAssignableFrom(dataType)) {
        return (State) propertyValue;
    } else {
        return new StringType(propertyValue.toString());
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType)

Example 12 with DateTimeType

use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.

the class LightwaveRfBindingFunctionalTest method testWifiLinkStatusReceived.

@Test
public void testWifiLinkStatusReceived() throws Exception {
    String message = "*!{\"trans\":452,\"mac\":\"ab:cd:ef\",\"time\":1447712274,\"type\":\"hub\",\"prod\":\"wfl\",\"fw\":\"U2.91Y\"," + "\"uptime\":1386309,\"timeZone\":0,\"lat\":52.48,\"long\":-87.89,\"duskTime\":1447690400," + "\"dawnTime\":1447659083,\"tmrs\":0,\"evns\":1,\"run\":0,\"macs\":8,\"ip\":\"192.168.0.1\",\"devs\":0}";
    List<ItemConfigAndExpectedState> itemConfigAndExpectedStates = new LinkedList<ItemConfigAndExpectedState>();
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_IP"), "serial=wifilink,type=WIFILINK_IP", new StringType("192.168.0.1")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_FIRMWARE"), "serial=wifilink,type=WIFILINK_FIRMWARE", new StringType("U2.91Y")));
    Calendar duskCal = Calendar.getInstance();
    duskCal.setTime(new Date(1447690400000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DUSK_TIME"), "serial=wifilink,type=WIFILINK_DUSK_TIME", new DateTimeType(duskCal)));
    Calendar dawnCal = Calendar.getInstance();
    dawnCal.setTime(new Date(1447659083000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new DateTimeItem("WIFILINK_DAWN_TIME"), "serial=wifilink,type=WIFILINK_DAWN_TIME", new DateTimeType(dawnCal)));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("WIFILINK_UPTIME"), "serial=wifilink,type=WIFILINK_UPTIME", new DecimalType("1386309")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LONGITUDE"), "serial=wifilink,type=WIFILINK_LONGITUDE", new StringType("-87.89")));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new StringItem("WIFILINK_LATITUDE"), "serial=wifilink,type=WIFILINK_LATITUDE", new StringType("52.48")));
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(1447712274000L));
    itemConfigAndExpectedStates.add(new ItemConfigAndExpectedState(new NumberItem("TIME"), "serial=wifilink,type=UPDATETIME", new DateTimeType(cal)));
    testReceivingACommandAndVerify(itemConfigAndExpectedStates, message);
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) LinkedList(java.util.LinkedList) Date(java.util.Date) Test(org.junit.Test)

Example 13 with DateTimeType

use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.

the class LightwaveRfHeatingInfoResponse method getState.

@Override
public State getState(LightwaveRfType type) {
    switch(type) {
        case HEATING_BATTERY:
            return new DecimalType(getBatteryLevel());
        case SIGNAL:
            return new DecimalType(getSignal());
        case HEATING_CURRENT_TEMP:
            return new DecimalType(getCurrentTemperature());
        case HEATING_SET_TEMP:
            return new DecimalType(getCurrentTargetTemperature());
        case HEATING_MODE:
            return new StringType(getState());
        case HEATING_OUTPUT:
            return new PercentType(getOutput());
        case UPDATETIME:
            Calendar cal = Calendar.getInstance();
            cal.setTime(getTime());
            return new DateTimeType(cal);
        case VERSION:
            return new StringType(getVersion());
        default:
            return null;
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) StringType(org.openhab.core.library.types.StringType) Calendar(java.util.Calendar) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType)

Example 14 with DateTimeType

use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.

the class ItemStateRequestProcessor method getState.

private StateTransformable getState(Item item) {
    StateTransformable state = null;
    if (item.getState() instanceof HSBType) {
        HSBType hsb = (HSBType) item.getState();
        state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue());
    } else if (item.getState() instanceof DateTimeType) {
        DateTimeType dt = (DateTimeType) item.getState();
        DateTimeDataType data = new DateTimeDataType(dt.toString());
        state = new DateTimeData(data);
    } else if (item.getState() instanceof DecimalType) {
    } else if (item.getState() instanceof OnOffType) {
    } else if (item.getState() instanceof OpenClosedType) {
    } else if (item.getState() instanceof PercentType) {
    } else if (item.getState() instanceof UpDownType) {
    }
    return state;
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) DateTimeDataType(org.creek.mailcontrol.model.types.DateTimeDataType) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) HSBData(org.creek.mailcontrol.model.data.HSBData) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeData(org.creek.mailcontrol.model.data.DateTimeData) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Example 15 with DateTimeType

use of org.openhab.core.library.types.DateTimeType in project openhab1-addons by openhab.

the class Panel method refreshItem.

/**
     * {@inheritDoc}
     */
@Override
public void refreshItem(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, int state, String description) {
    logger.debug("refreshItem(): Panel Item Name: {}", item.getName());
    String str = "";
    OnOffType onOffType;
    if (config != null) {
        if (config.getDSCAlarmItemType() != null) {
            switch(config.getDSCAlarmItemType()) {
                case PANEL_CONNECTION:
                    publisher.postUpdate(item.getName(), new DecimalType(state));
                    break;
                case PANEL_MESSAGE:
                    publisher.postUpdate(item.getName(), new StringType(description));
                    break;
                case PANEL_SYSTEM_ERROR:
                    str = String.format("%03d: %s", state, ((state == 0) ? "No Error" : description));
                    publisher.postUpdate(item.getName(), new StringType(str));
                    break;
                case PANEL_TIME:
                    str = getFormattedPanelTime(description);
                    publisher.postUpdate(item.getName(), new DateTimeType(str));
                    break;
                case PANEL_TIME_STAMP:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TIME_BROADCAST:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_COMMAND:
                    publisher.postUpdate(item.getName(), new DecimalType(state));
                    break;
                case PANEL_TROUBLE_MESSAGE:
                    publisher.postUpdate(item.getName(), new StringType(description));
                    break;
                case PANEL_TROUBLE_LED:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_SERVICE_REQUIRED:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AC_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TELEPHONE_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_FTC_TROUBLE:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_FAULT:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_TAMPER:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_ZONE_LOW_BATTERY:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_TIME_LOSS:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_FIRE_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_PANIC_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AUX_KEY_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                case PANEL_AUX_INPUT_ALARM:
                    onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
                    publisher.postUpdate(item.getName(), onOffType);
                    break;
                default:
                    logger.debug("refreshItem(): Panel item not updated.");
                    break;
            }
        }
    }
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Aggregations

DateTimeType (org.openhab.core.library.types.DateTimeType)49 Calendar (java.util.Calendar)37 DecimalType (org.openhab.core.library.types.DecimalType)30 StringType (org.openhab.core.library.types.StringType)29 State (org.openhab.core.types.State)16 DateTimeItem (org.openhab.core.library.items.DateTimeItem)12 PercentType (org.openhab.core.library.types.PercentType)12 NumberItem (org.openhab.core.library.items.NumberItem)11 BigDecimal (java.math.BigDecimal)10 OnOffType (org.openhab.core.library.types.OnOffType)9 ContactItem (org.openhab.core.library.items.ContactItem)8 DimmerItem (org.openhab.core.library.items.DimmerItem)8 StringItem (org.openhab.core.library.items.StringItem)8 HSBType (org.openhab.core.library.types.HSBType)8 Test (org.junit.Test)7 SwitchItem (org.openhab.core.library.items.SwitchItem)7 Date (java.util.Date)6 ColorItem (org.openhab.core.library.items.ColorItem)6 RollershutterItem (org.openhab.core.library.items.RollershutterItem)6 ArrayList (java.util.ArrayList)5