Search in sources :

Example 1 with PercentType

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

the class WagoBinding method updateItemPWM.

public void updateItemPWM(String itemName, String couplerName, int module, int[] values) {
    for (WagoBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            WagoBindingConfig conf = provider.getConfig(itemName);
            if (conf.couplerName.equals(couplerName) && conf.module == module) {
                State currentState = conf.getItemState();
                State newState;
                if (conf.getItem() instanceof DimmerItem) {
                    newState = new PercentType((int) ((float) values[conf.channel] / 1023 * 100));
                } else if (conf.getItem() instanceof SwitchItem) {
                    if (values[conf.channel] == 0) {
                        newState = OnOffType.OFF;
                    } else {
                        newState = OnOffType.ON;
                    }
                } else {
                    logger.debug("Unsupported Itemtype");
                    return;
                }
                if (!newState.equals(currentState)) {
                    eventPublisher.postUpdate(itemName, newState);
                }
            }
        }
    }
}
Also used : WagoBindingConfig(org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig) WagoBindingProvider(org.openhab.binding.wago.WagoBindingProvider) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 2 with PercentType

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

the class UPBBinding method messageReceived.

/**
     * {@inheritDoc}
     */
@Override
public void messageReceived(UPBMessage message) {
    if (message.getType() != Type.MESSAGE_REPORT) {
        return;
    }
    String sourceName = getItemName(message.getSource(), false);
    String destinationName = getItemName(message.getDestination(), message.getControlWord().isLink());
    UPBBindingConfig sourceConfig = getConfig(sourceName);
    UPBBindingConfig destinationConfig = getConfig(destinationName);
    String itemName = isValidId(message.getDestination()) ? destinationName : sourceName;
    UPBBindingConfig config = isValidId(message.getDestination()) ? destinationConfig : sourceConfig;
    if (itemName == null || config == null) {
        logger.debug("Received message for unknown {} with id {}.", message.getControlWord().isLink() ? "Link" : "Device", message.getDestination() & 0xff);
        return;
    }
    State newState = null;
    byte level = 100;
    switch(message.getCommand()) {
        case GOTO:
        case DEVICE_STATE:
        case ACTIVATE:
            if (message.getArguments() != null && message.getArguments().length > 0) {
                level = message.getArguments()[0];
            } else {
                level = (byte) (message.getCommand() == UPBMessage.Command.ACTIVATE ? 100 : 0);
            }
            // Links will send FF (-1) for their level.
            if (level == -1 || level >= 100 || (level > 0 && !config.isDimmable())) {
                newState = OnOffType.ON;
            } else if (level == 0) {
                newState = OnOffType.OFF;
            } else {
                newState = new PercentType(level);
            }
            break;
        case DEACTIVATE:
            newState = OnOffType.OFF;
            break;
        default:
            break;
    }
    if (newState != null) {
        logger.debug("Posting update: {},{}", itemName, newState);
        eventPublisher.postUpdate(itemName, newState);
    }
}
Also used : State(org.openhab.core.types.State) PercentType(org.openhab.core.library.types.PercentType)

Example 3 with PercentType

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

the class XbmcConnector method processApplicationStateChanged.

private void processApplicationStateChanged(String method, Map<String, Object> json) {
    if ("Application.OnVolumeChanged".equals(method)) {
        // get the player id and make a new request for the media details
        Map<String, Object> params = RpcCall.getMap(json, "params");
        Map<String, Object> data = RpcCall.getMap(params, "data");
        Object o = data.get("volume");
        PercentType volume = new PercentType(0);
        if (o instanceof Integer) {
            volume = new PercentType((Integer) o);
        } else {
            if (o instanceof Double) {
                volume = new PercentType(((Double) o).intValue());
            }
        }
        updateProperty("Application.Volume", volume);
        this.volume = new BigDecimal(volume.intValue());
    }
}
Also used : PercentType(org.openhab.core.library.types.PercentType) BigDecimal(java.math.BigDecimal)

Example 4 with PercentType

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

the class LightwaveRfBindingFunctionalTest method testInOnlyMessageReceived.

@Test
public void testInOnlyMessageReceived() 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 5 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)

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