Search in sources :

Example 41 with DecimalType

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);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 42 with DecimalType

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);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 43 with DecimalType

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);
}
Also used : DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 44 with DecimalType

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;
            }
        }
    }
}
Also used : SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) StringType(org.eclipse.smarthome.core.library.types.StringType) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType)

Example 45 with DecimalType

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.");
    }
}
Also used : ControlStates(org.eclipse.smarthome.binding.digitalstrom.internal.lib.climate.constants.ControlStates) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) ControlModes(org.eclipse.smarthome.binding.digitalstrom.internal.lib.climate.constants.ControlModes)

Aggregations

DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)68 Test (org.junit.Test)33 State (org.eclipse.smarthome.core.types.State)17 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)11 StringType (org.eclipse.smarthome.core.library.types.StringType)9 HSBType (org.eclipse.smarthome.core.library.types.HSBType)8 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 Type (org.eclipse.smarthome.core.types.Type)7 Item (org.eclipse.smarthome.core.items.Item)6 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BigDecimal (java.math.BigDecimal)5 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Response (javax.ws.rs.core.Response)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)3