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());
}
}
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);
}
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;
}
}
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;
}
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;
}
}
}
}
Aggregations