use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ZoneTemperatureControlHandler method sendCommandAndUpdateChannel.
private void sendCommandAndUpdateChannel(Float newValue) {
if (isTemperature()) {
if (temperatureSensorTransmitter.pushTargetTemperature(zoneID, newValue)) {
currentValue = newValue;
updateState(currentChannelID, new DecimalType(newValue));
}
} else {
if (temperatureSensorTransmitter.pushControlValue(zoneID, newValue)) {
currentValue = newValue;
updateState(currentChannelID, new PercentType(newValue.intValue()));
}
}
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImpl method getLabel.
@Override
public String getLabel(Widget w) {
String label = getLabelFromWidget(w);
String itemName = w.getItem();
if (StringUtils.isBlank(itemName)) {
return transform(label, null);
}
String labelMappedOption = null;
State state = null;
StateDescription stateDescription = null;
String formatPattern = getFormatPattern(label);
// (i.e. it contains at least a %)
try {
final Item item = getItem(itemName);
// There is a known issue in the implementation of the method getStateDescription() of class Item
// in the following case:
// - the item provider returns as expected a state description without pattern but with for
// example a min value because a min value is set in the item definition but no label with
// pattern is set.
// - the channel state description provider returns as expected a state description with a pattern
// In this case, the result is no display of value by UIs because no pattern is set in the
// returned StateDescription. What is expected is the display of a value using the pattern
// provided by the channel state description provider.
stateDescription = item.getStateDescription();
if (formatPattern == null && stateDescription != null && stateDescription.getPattern() != null) {
label = label + " [" + stateDescription.getPattern() + "]";
}
String updatedPattern = getFormatPattern(label);
if (updatedPattern != null) {
formatPattern = updatedPattern;
// a number is requested, PercentType must not be converted to DecimalType:
if (formatPattern.contains("%d") && !(item.getState() instanceof PercentType)) {
state = item.getStateAs(DecimalType.class);
} else {
state = item.getState();
}
}
} catch (ItemNotFoundException e) {
logger.error("Cannot retrieve item for widget {}", w.eClass().getInstanceTypeName());
}
if (formatPattern != null) {
if (formatPattern.isEmpty()) {
label = label.substring(0, label.indexOf("[")).trim();
} else {
if (state == null || state instanceof UnDefType) {
formatPattern = formatUndefined(formatPattern);
} else if (state instanceof Type) {
// if the channel contains options, we build a label with the mapped option value
if (stateDescription != null && stateDescription.getOptions() != null) {
for (StateOption option : stateDescription.getOptions()) {
if (option.getValue().equals(state.toString()) && option.getLabel() != null) {
State stateOption = new StringType(option.getLabel());
try {
String formatPatternOption = stateOption.format(formatPattern);
labelMappedOption = label.trim();
labelMappedOption = labelMappedOption.substring(0, labelMappedOption.indexOf("[") + 1) + formatPatternOption + "]";
} catch (IllegalArgumentException e) {
logger.debug("Mapping option value '{}' for item {} using format '{}' failed ({}); mapping is ignored", stateOption, itemName, formatPattern, e.getMessage());
labelMappedOption = null;
}
break;
}
}
}
if (state instanceof QuantityType) {
QuantityType<?> quantityState = (QuantityType<?>) state;
// sanity convert current state to the item state description unit in case it was updated in the
// meantime. The item state is still in the "original" unit while the state description will
// display the new unit:
Unit<?> patternUnit = UnitUtils.parseUnit(formatPattern);
if (patternUnit != null && !quantityState.getUnit().equals(patternUnit)) {
quantityState = quantityState.toUnit(patternUnit);
}
// The widget may define its own unit in the widget label. Convert to this unit:
quantityState = convertStateToWidgetUnit(quantityState, w);
state = quantityState;
}
// This also handles IllegalFormatConversionException, which is a subclass of IllegalArgument.
try {
formatPattern = fillFormatPattern(formatPattern, state);
} catch (IllegalArgumentException e) {
logger.warn("Exception while formatting value '{}' of item {} with format '{}': {}", state, itemName, formatPattern, e.getMessage());
formatPattern = new String("Err");
}
}
label = label.trim();
label = label.substring(0, label.indexOf("[") + 1) + formatPattern + "]";
}
}
return transform(label, labelMappedOption);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class BlukiiHandler method onScanRecordReceived.
@Override
public void onScanRecordReceived(BluetoothScanNotification scanNotification) {
byte[] data = scanNotification.getManufacturerData();
if (data != null && data[0] == 0x4F) {
// only data starting with 0x4F is Blukii-specific data
logger.debug("Manufacturer data: {}", HexUtils.bytesToHex(scanNotification.getManufacturerData(), " "));
int battery = scanNotification.getManufacturerData()[12] & 0x7F;
updateState(BlukiiBindingConstants.CHANNEL_ID_BATTERY, new DecimalType(battery));
if ((data[14] & 0x30) == 0x30) {
processMagnetometerData(data);
} else if ((data[14] & 0x10) == 0x10) {
processEnvironmentData(data);
} else if ((data[14] & 0x20) == 0x20) {
processAccelerometerData(data);
}
}
super.onScanRecordReceived(scanNotification);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class TradfriControllerHandler method onUpdate.
@Override
public void onUpdate(JsonElement data) {
if (active && !(data.isJsonNull())) {
state = new TradfriControllerData(data);
updateStatus(state.getReachabilityStatus() ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
DecimalType batteryLevel = state.getBatteryLevel();
if (batteryLevel != null) {
updateState(CHANNEL_BATTERY_LEVEL, batteryLevel);
}
OnOffType batteryLow = state.getBatteryLow();
if (batteryLow != null) {
updateState(CHANNEL_BATTERY_LOW, batteryLow);
}
updateDeviceProperties(state);
logger.debug("Updating thing for controllerId {} to state {batteryLevel: {}, batteryLow: {}, firmwareVersion: {}, modelId: {}, vendor: {}}", state.getDeviceId(), batteryLevel, batteryLow, state.getFirmwareVersion(), state.getModelId(), state.getVendor());
}
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class TradfriSensorHandler method onUpdate.
@Override
public void onUpdate(JsonElement data) {
if (active && !(data.isJsonNull())) {
state = new TradfriSensorData(data);
updateStatus(state.getReachabilityStatus() ? ThingStatus.ONLINE : ThingStatus.OFFLINE);
DecimalType batteryLevel = state.getBatteryLevel();
if (batteryLevel != null) {
updateState(CHANNEL_BATTERY_LEVEL, batteryLevel);
}
OnOffType batteryLow = state.getBatteryLow();
if (batteryLow != null) {
updateState(CHANNEL_BATTERY_LOW, batteryLow);
}
updateDeviceProperties(state);
logger.debug("Updating thing for sensorId {} to state {batteryLevel: {}, batteryLow: {}, firmwareVersion: {}, modelId: {}, vendor: {}}", state.getDeviceId(), batteryLevel, batteryLow, state.getFirmwareVersion(), state.getModelId(), state.getVendor());
}
}
Aggregations