Search in sources :

Example 76 with PercentType

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

the class DenonConnector method updateMainZone.

private void updateMainZone() {
    String url = statusUrl + URL_ZONE_MAIN;
    logger.trace("Refreshing URL: {}", url);
    ZoneStatus mainZone = getDocument(url, ZoneStatus.class);
    if (mainZone != null) {
        stateCache.put(DenonProperty.INPUT.getCode(), new StringType(mainZone.getInputFuncSelect().getValue()));
        stateCache.put("SI" + mainZone.getInputFuncSelect().getValue(), OnOffType.ON);
        stateCache.put(DenonProperty.MASTER_VOLUME.getCode(), new PercentType(mainZone.getMasterVolume().getValue()));
        stateCache.put(DenonProperty.POWER_MAINZONE.getCode(), mainZone.getPower().getValue() ? OnOffType.ON : OnOffType.OFF);
        stateCache.put(DenonProperty.MUTE.getCode(), mainZone.getMute().getValue() ? OnOffType.ON : OnOffType.OFF);
        if (mainZone.getSurrMode() == null) {
            logger.debug("Unable to get the SURROUND_MODE. MainZone update may not be correct.");
        } else {
            stateCache.put(DenonProperty.SURROUND_MODE.getCode(), new StringType(mainZone.getSurrMode().getValue()));
        }
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) ZoneStatus(org.openhab.binding.denon.internal.communication.entities.ZoneStatus) PercentType(org.openhab.core.library.types.PercentType)

Example 77 with PercentType

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

the class DiyOnXBeeBinding method changeColorBrightness.

private String changeColorBrightness(final HSBType hsbType, IncreaseDecreaseType increaseDecrease) {
    final PercentType brightness = hsbType.getBrightness();
    final PercentType newBrightness = changeBrightness(increaseDecrease, brightness);
    final HSBType newHSB = new HSBType(hsbType.getHue(), hsbType.getSaturation(), newBrightness);
    return makeRGB(newHSB.toColor());
}
Also used : PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Example 78 with PercentType

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

the class DmxColorItem method processCommand.

/**
     * {@inheritDoc}
     */
@Override
public void processCommand(DmxService service, Command command) {
    // process HSB command
    if (command instanceof HSBType) {
        HSBType hsbValue = (HSBType) command;
        setHSBValue(service, hsbValue);
        return;
    }
    // process increase/decrease
    if (command instanceof IncreaseDecreaseType && !isRedefinedByCustomCommand(command) && !service.hasChannelActions(channels[0])) {
        // rather than doing a linear fade on all channels, we fade only the
        // V part of HSV to maintain the color during the fade
        HSBType hsb = hsbState;
        int brightness = 0;
        IncreaseDecreaseType t = (IncreaseDecreaseType) command;
        if (IncreaseDecreaseType.INCREASE.equals(t)) {
            if (hsb == null) {
                hsb = new HSBType(Color.WHITE);
            }
            for (int ch : channels) {
                service.enableChannel(ch);
            }
            brightness = hsb.getBrightness().intValue();
            brightness += BRIGHTNESS_STEP_SIZE;
            if (brightness > 100) {
                brightness = 100;
            }
        } else {
            if (hsb == null) {
                hsb = new HSBType(Color.BLACK);
            }
            brightness = hsb.getBrightness().intValue();
            brightness -= BRIGHTNESS_STEP_SIZE;
            if (brightness <= 0) {
                brightness = 0;
            }
        }
        HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(brightness));
        setHSBValue(service, newHsb);
        return;
    }
    // process percent command
    if (command instanceof PercentType && !isRedefinedByCustomCommand(command) && !service.hasChannelActions(channels[0])) {
        PercentType t = (PercentType) command;
        HSBType hsb = hsbState;
        if (hsb == null) {
            hsb = new HSBType(Color.WHITE);
        }
        HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), t);
        setHSBValue(service, newHsb);
        return;
    }
    // process on/off, increase/decrease, percent type
    super.processCommand(service, command);
}
Also used : IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Example 79 with PercentType

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

the class DmxDimmerItem method processCommand.

/**
     * {@inheritDoc}
     */
@Override
public void processCommand(DmxService service, Command command) {
    // process increase/decrease
    if (command instanceof IncreaseDecreaseType && !isRedefinedByCustomCommand(command)) {
        IncreaseDecreaseType t = (IncreaseDecreaseType) command;
        if (IncreaseDecreaseType.INCREASE.equals(t)) {
            for (int channelId : channels) {
                service.enableChannel(channelId);
                service.increaseChannel(channelId, DIMMER_STEP_SIZE);
                if (service.getChannelValue(channelId) == 0) {
                    service.setChannelValue(channelId, DmxChannel.DMX_MAX_VALUE);
                }
            }
        } else {
            for (int channelId : channels) {
                service.decreaseChannel(channelId, DIMMER_STEP_SIZE);
            }
        }
        return;
    }
    // process percent command
    if (command instanceof PercentType && !isRedefinedByCustomCommand(command)) {
        for (int channelId : channels) {
            service.setChannelValue(channelId, DmxChannel.DMX_MAX_VALUE);
            service.setChannelValue(channelId, (PercentType) command);
        }
        return;
    }
    // process switch command
    super.processCommand(service, command);
}
Also used : IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType)

Example 80 with PercentType

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

the class DmxColorItemTest method canBeSetWithPercentType.

@Override
@Test
public void canBeSetWithPercentType() throws BindingConfigParseException {
    DmxItem item = getValidInstance();
    DmxService service = Mockito.mock(DmxService.class);
    item.processCommand(service, new PercentType(50));
    Mockito.verify(service).setChannelValue(3, 129);
    Mockito.verify(service).setChannelValue(4, 129);
    Mockito.verify(service).setChannelValue(5, 129);
}
Also used : DmxService(org.openhab.binding.dmx.DmxService) 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