Search in sources :

Example 26 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class LightwaveRfBindingFunctionalTest method testDimMessageSentByAndriodApp.

@Test
public void testDimMessageSentByAndriodApp() throws Exception {
    String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
    testReceivingACommandAndVerify(new DimmerItem("LivingRoom"), "room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
Also used : DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) Test(org.junit.Test)

Example 27 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class LightwaveRfBindingFunctionalTest method testOutOnlyMessageReceived.

@Test
public void testOutOnlyMessageReceived() throws Exception {
    String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
    testReceivingACommandAndVerifyNoInteractions(new DimmerItem("LivingRoom"), ">room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
Also used : DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) Test(org.junit.Test)

Example 28 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class OnkyoBinding method convertDeviceValueToOpenHabState.

/**
     * Convert receiver value to OpenHAB state.
     *
     * @param itemType
     * @param data
     *
     * @return
     */
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data) {
    State state = UnDefType.UNDEF;
    try {
        int index;
        String s;
        if (itemType == SwitchItem.class) {
            index = Integer.parseInt(data.substring(3, 5), 16);
            state = index == 0 ? OnOffType.OFF : OnOffType.ON;
        } else if (itemType == NumberItem.class) {
            index = Integer.parseInt(data.substring(3, 5), 16);
            state = new DecimalType(index);
        } else if (itemType == DimmerItem.class) {
            index = Integer.parseInt(data.substring(3, 5), 16);
            state = new PercentType(index);
        } else if (itemType == RollershutterItem.class) {
            index = Integer.parseInt(data.substring(3, 5), 16);
            state = new PercentType(index);
        } else if (itemType == StringItem.class) {
            s = data.substring(3, data.length());
            state = new StringType(s);
        }
    } catch (Exception e) {
        logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
    }
    return state;
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 29 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class PioneerAvrBinding method convertDeviceValueToOpenHabState.

/**
     * Convert receiver value to OpenHAB state.
     * 
     * @param itemType
     * @param data
     * 
     * @return
     */
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data, IpControlCommand cmdType) {
    State state = UnDefType.UNDEF;
    try {
        int index;
        // cut off the leading response identifier to get the payload string
        String payloadSubstring = data.substring(cmdType.getResponse().length());
        // the selected source will then be set to "ON"
        if (payloadSubstring.length() == 0) {
            payloadSubstring = "1";
        }
        // special case for display info query: convert to human readable string
        if (cmdType.getCommandRef() == IpControlCommandRef.DISPLAY_INFO_QUERY) {
            IpControlDisplayInformation displayInfo = new IpControlDisplayInformation(payloadSubstring);
            payloadSubstring = displayInfo.getInfoText();
            logger.debug("DisplayInfo: converted value '{}' to string '{}'", data, payloadSubstring);
        }
        if (itemType == SwitchItem.class) {
            index = Integer.parseInt(payloadSubstring);
            // according to Spec: 0=ON, 1=OFF!
            state = (index == 0) ? OnOffType.ON : OnOffType.OFF;
        } else if (itemType == DimmerItem.class) {
            if (cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_QUERY.getCommand() || cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_SET.getCommand()) {
                index = convertVolumeToPercent(Integer.parseInt(payloadSubstring));
            } else {
                index = Integer.parseInt(payloadSubstring);
            }
            state = new PercentType(index);
        } else if (itemType == NumberItem.class) {
            index = Integer.parseInt(payloadSubstring);
            state = new DecimalType(index);
        } else if (itemType == RollershutterItem.class) {
            index = Integer.parseInt(payloadSubstring);
            state = new PercentType(index);
        } else if (itemType == StringItem.class) {
            state = new StringType(payloadSubstring);
        }
    } catch (Exception e) {
        logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
    }
    return state;
}
Also used : IpControlDisplayInformation(org.openhab.binding.pioneeravr.internal.ipcontrolprotocol.IpControlDisplayInformation) StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) ConfigurationException(org.osgi.service.cm.ConfigurationException)

Example 30 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class PlexConnector method getProgressCommand.

private String getProgressCommand(PlexBindingConfig config, Command command) {
    PlexSession session = getSessionByMachineId(config.getMachineIdentifier());
    String url = null;
    if (session != null) {
        int offset = 0;
        if (command.getClass().equals(PercentType.class)) {
            PercentType percent = (PercentType) command;
            offset = new BigDecimal(session.getDuration()).multiply(percent.toBigDecimal().divide(new BigDecimal("100"), new MathContext(5, RoundingMode.HALF_UP))).intValue();
            offset = Math.max(0, offset);
            offset = Math.min(session.getDuration(), offset);
            url = String.format("playback/seekTo?offset=%d", offset);
        } else if (command.getClass().equals(IncreaseDecreaseType.class)) {
            if (command.equals(IncreaseDecreaseType.DECREASE)) {
                url = PlexProperty.STEP_BACK.getName();
            } else {
                url = PlexProperty.STEP_FORWARD.getName();
            }
        }
    }
    return url;
}
Also used : IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext)

Aggregations

PercentType (org.openhab.core.library.types.PercentType)105 DecimalType (org.openhab.core.library.types.DecimalType)43 State (org.openhab.core.types.State)29 StringType (org.openhab.core.library.types.StringType)27 DimmerItem (org.openhab.core.library.items.DimmerItem)22 Test (org.junit.Test)21 HSBType (org.openhab.core.library.types.HSBType)19 OnOffType (org.openhab.core.library.types.OnOffType)19 RollershutterItem (org.openhab.core.library.items.RollershutterItem)17 NumberItem (org.openhab.core.library.items.NumberItem)16 BigDecimal (java.math.BigDecimal)14 SwitchItem (org.openhab.core.library.items.SwitchItem)13 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)13 ColorItem (org.openhab.core.library.items.ColorItem)11 DateTimeType (org.openhab.core.library.types.DateTimeType)11 Calendar (java.util.Calendar)9 ContactItem (org.openhab.core.library.items.ContactItem)9 UpDownType (org.openhab.core.library.types.UpDownType)9 StopMoveType (org.openhab.core.library.types.StopMoveType)7 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6