use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithHexValueAndWidth.
@Test
public void getLabel_labelWithHexValueAndWidth() throws ItemNotFoundException {
String testLabel = "Label [%3x]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DecimalType(20));
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [ 14]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithPercent.
@Test
public void getLabel_labelWithPercent() throws ItemNotFoundException {
String testLabel = "Label [%.1f %%]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DecimalType(10f / 3f));
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(10f / 3f));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [3" + sep + "3 %]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ItemUIRegistryImplTest method getLabel_labelWithIntegerValueAndWidth.
@Test
public void getLabel_labelWithIntegerValueAndWidth() throws ItemNotFoundException {
String testLabel = "Label [%3d]";
when(widget.getLabel()).thenReturn(testLabel);
when(item.getState()).thenReturn(new DecimalType(20));
when(item.getStateAs(DecimalType.class)).thenReturn(new DecimalType(20));
String label = uiRegistry.getLabel(widget);
assertEquals("Label [ 20]", label);
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class DeviceHandler method channelLinked.
@Override
public void channelLinked(ChannelUID channelUID) {
if (device != null) {
SensorEnum sensorType = getSensorEnum(channelUID.getId());
if (sensorType != null) {
Float val = device.getFloatSensorValue(sensorType);
if (val != null) {
updateState(channelUID, new DecimalType(val));
}
}
Short val = device.getBinaryInputState(getBinaryInput(channelUID.getId()));
if (val != null) {
if (val == 1) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
}
if (channelUID.getId().contains(DsChannelTypeProvider.DIMMER)) {
if (device.isOn()) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getOutputValue(), device.getMaxOutputValue())));
} else {
updateState(channelUID, new PercentType(0));
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SWITCH)) {
if (device.isOn()) {
updateState(channelUID, OnOffType.ON);
} else {
updateState(channelUID, OnOffType.OFF);
}
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getSlatPosition(), device.getMaxSlatPosition())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
updateState(channelUID, new PercentType(fromValueToPercent(device.getAnglePosition(), device.getMaxSlatAngle())));
return;
}
if (channelUID.getId().contains(DsChannelTypeProvider.STAGE)) {
if (channelUID.getId().contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 2, device.getOutputValue())));
return;
}
if (channelUID.getId().contains(THREE_STAGE_SWITCH_IDENTICATOR)) {
updateState(channelUID, new StringType(convertStageValue((short) 3, device.getOutputValue())));
return;
}
}
}
}
use of org.eclipse.smarthome.core.library.types.DecimalType in project smarthome by eclipse.
the class ZoneTemperatureControlHandler method configChanged.
@Override
public synchronized void configChanged(TemperatureControlStatus tempControlStatus) {
if (tempControlStatus != null && tempControlStatus.getIsConfigured()) {
ControlModes controlMode = ControlModes.getControlMode(tempControlStatus.getControlMode());
ControlStates controlState = ControlStates.getControlState(tempControlStatus.getControlState());
if (controlMode != null && controlState != null) {
logger.debug("config changed: {}", tempControlStatus.toString());
if (controlMode.equals(ControlModes.OFF) && currentChannelID != null) {
currentChannelID = null;
loadChannel();
} else if (controlMode.equals(ControlModes.PID_CONTROL) && (currentChannelID == null || !currentChannelID.contains(DsChannelTypeProvider.TEMPERATURE_CONTROLLED)) && !controlState.equals(ControlStates.EMERGENCY)) {
currentChannelID = DsChannelTypeProvider.getOutputChannelTypeID(FunctionalColorGroupEnum.BLUE, OutputModeEnum.TEMPRETURE_PWM);
loadChannel();
currentValue = tempControlStatus.getNominalValue();
updateState(currentChannelID, new DecimalType(currentValue.doubleValue()));
} else if (!controlMode.equals(ControlModes.PID_CONTROL) && !controlMode.equals(ControlModes.OFF)) {
currentChannelID = DsChannelTypeProvider.getOutputChannelTypeID(FunctionalColorGroupEnum.BLUE, OutputModeEnum.HEATING_PWM);
loadChannel();
currentValue = tempControlStatus.getControlValue();
updateState(currentChannelID, new PercentType(fixPercent(currentValue.intValue())));
if (controlState.equals(ControlStates.EMERGENCY)) {
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR, "The communication with temperation sensor fails. Temperature control state emergency (temperature control though the control value) is active.");
}
}
// TODO: in case of control-mode zone-follower it is maybe useful to add the followed zone-id, but this
// info is not in the control-status
Map<String, String> properties = editProperties();
properties.put("controlDSUID", tempControlStatus.getControlDSUID());
properties.put("controlMode", controlMode.getKey());
properties.put("controlState", controlState.getKey());
updateProperties(properties);
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "digitalSTROM temperature control is for this zone not configured in.");
}
}
Aggregations