Java Code Examples for org.eclipse.smarthome.core.library.types.DecimalType#valueOf()
The following examples show how to use
org.eclipse.smarthome.core.library.types.DecimalType#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OwserverConnection.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * read a decimal type * * @param path full owfs path to sensor * @return DecimalType if successful * @throws OwException */ public State readDecimalType(String path) throws OwException { State returnState = UnDefType.UNDEF; OwserverPacket requestPacket = new OwserverPacket(OwserverMessageType.READ, path); OwserverPacket returnPacket = request(requestPacket); if ((returnPacket.getReturnCode() != -1) && returnPacket.hasPayload()) { returnState = DecimalType.valueOf(returnPacket.getPayloadString().trim()); } else { throw new OwException("invalid or empty packet"); } return returnState; }
Example 2
Source File: HueSensorHandler.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Override public void onSensorStateChanged(@Nullable HueBridge bridge, FullSensor sensor) { logger.trace("onSensorStateChanged() was called"); if (!sensor.getId().equals(sensorId)) { logger.trace("Received state change for another handler's sensor ({}). Will be ignored.", sensor.getId()); return; } initializeProperties(); if (Boolean.TRUE.equals(sensor.getConfig().get(CONFIG_REACHABLE))) { updateStatus(ThingStatus.ONLINE); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/offline.sensor-not-reachable"); } // update generic sensor config Configuration config = editConfiguration(); if (sensor.getConfig().containsKey(CONFIG_ON)) { config.put(CONFIG_ON, sensor.getConfig().get(CONFIG_ON)); } // update specific sensor config doSensorStateChanged(bridge, sensor, config); Object lastUpdated = sensor.getState().get(STATE_LAST_UPDATED); if (lastUpdated != null) { try { updateState(CHANNEL_LAST_UPDATED, new DateTimeType(ZonedDateTime.ofInstant( LocalDateTime.parse(String.valueOf(lastUpdated), DateTimeFormatter.ISO_LOCAL_DATE_TIME), ZoneOffset.UTC, ZoneId.systemDefault()))); } catch (DateTimeParseException e) { // do nothing } } Object battery = sensor.getConfig().get(CONFIG_BATTERY); if (battery != null) { DecimalType batteryLevel = DecimalType.valueOf(String.valueOf(battery)); updateState(CHANNEL_BATTERY_LEVEL, batteryLevel); updateState(CHANNEL_BATTERY_LOW, batteryLevel.intValue() <= 10 ? OnOffType.ON : OnOffType.OFF); } updateConfiguration(config); }