Search in sources :

Example 86 with PercentType

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

the class OutputDimAbs method send.

/** {@inheritDoc} */
@Override
public void send(Connection conn, Item item, Command cmd) {
    double value = this.percent;
    if (value == -1 && cmd instanceof PercentType) {
        value = ((PercentType) cmd).doubleValue();
    }
    if (value >= 0 && value <= 100) {
        if (this.outputId == -1) {
            // All
            // Default
            boolean is1805 = false;
            if (!this.addr.isGroup()) {
                ModInfo info = conn.getModInfo((LcnAddrMod) this.addr);
                if (info != null) {
                    is1805 = info.getSwAge() >= 0x180501;
                }
            }
            conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.dimAllOutputs(value, LcnDefs.timeToRampValue(this.rampMSec), is1805));
        } else {
            // Single
            conn.queue(this.addr, !this.addr.isGroup(), PckGenerator.dimOutput(this.outputId, value, LcnDefs.timeToRampValue(this.rampMSec)));
        }
    }
}
Also used : PercentType(org.openhab.core.library.types.PercentType) ModInfo(org.openhab.binding.lcn.connection.ModInfo)

Example 87 with PercentType

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

the class Unit method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int status = properties.getState();
    logger.debug("Unit state {}", status);
    int level = prevLevel;
    String display = "Off";
    if (status == UNIT_ON) {
        level = 100;
        display = "On";
    } else if ((status >= UNIT_SCENE_A) && (status <= UNIT_SCENE_L)) {
        level = 100;
        display = String.format("Scene %c", status - UNIT_SCENE_A + 'A');
    } else if ((status >= UNIT_DIM_1) && (status <= UNIT_DIM_9)) {
        display = String.format("Dim %d", level);
    } else if ((status >= UNIT_BRIGHTEN_1) && (status <= UNIT_BRIGHTEN_9)) {
        display = String.format("Brighten %d", level);
    } else if ((status >= UNIT_LEVEL_0) && (status <= UNIT_LEVEL_100)) {
        level = status - UNIT_LEVEL_0;
        display = String.format("Level %d", level);
    }
    if (item instanceof DimmerItem) {
        logger.debug("updating percent type {}", level);
        publisher.postUpdate(item.getName(), new PercentType(level));
    } else if (item instanceof SwitchItem) {
        logger.debug("updating switch type {}", level > 0 ? OnOffType.ON : OnOffType.OFF);
        publisher.postUpdate(item.getName(), level > 0 ? OnOffType.ON : OnOffType.OFF);
    } else if (item instanceof StringItem) {
        logger.debug("updating string type {}", display);
        publisher.postUpdate(item.getName(), new StringType(display));
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 88 with PercentType

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

the class PilightBinding method processSwitchEvent.

private void processSwitchEvent(List<PilightBindingConfig> configs, Status status) {
    Integer type = status.getType();
    State state = OnOffType.valueOf(status.getValues().get("state").toUpperCase());
    if (type.equals(DeviceType.SWITCH)) {
    // noop, just use on/off state defined above
    } else if (type.equals(DeviceType.DIMMER)) {
        BigDecimal dimLevel = BigDecimal.ZERO;
        if (status.getValues().get("dimlevel") != null) {
            dimLevel = getPercentageFromDimLevel(status.getValues().get("dimlevel"));
        } else {
            // Dimmer items can can also be switched on or off in pilight.
            // When this happens, the dimmer value is not reported. At least we know it's on or off.
            dimLevel = state.equals(OnOffType.ON) ? new BigDecimal("100") : BigDecimal.ZERO;
        }
        state = new PercentType(dimLevel);
    }
    for (PilightBindingConfig config : configs) {
        eventPublisher.postUpdate(config.getItemName(), state);
    }
}
Also used : State(org.openhab.core.types.State) PercentType(org.openhab.core.library.types.PercentType) BigDecimal(java.math.BigDecimal)

Example 89 with PercentType

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

the class TinkerforgeBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     *
     * Searches the item with the given {@code itemName} in the {@link TinkerforgeBindingProvider}
     * collection and gets the uid and subid of the device. The appropriate device is searched in the
     * ecosystem and the command is executed on the device.
     *
     * {@code OnOffType} commands are executed on {@link MInSwitchActor} objects. {@code StringType}
     * commands are executed on {@link MTextActor} objects.
     *
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    logger.debug("received command {} for item {}", command, itemName);
    for (TinkerforgeBindingProvider provider : providers) {
        for (String itemNameP : provider.getItemNames()) {
            if (itemNameP.equals(itemName)) {
                String deviceUid = provider.getUid(itemName);
                String deviceSubId = provider.getSubId(itemName);
                String deviceName = provider.getName(itemName);
                if (deviceName != null) {
                    String[] ids = getDeviceIdsForDeviceName(deviceName);
                    deviceUid = ids[0];
                    deviceSubId = ids[1];
                }
                logger.trace("{} found item for command: uid: {}, subid: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
                MBaseDevice mDevice = tinkerforgeEcosystem.getDevice(deviceUid, deviceSubId);
                if (mDevice != null && mDevice.getEnabledA().get()) {
                    if (command instanceof OnOffType) {
                        logger.trace("{} found onoff command", LoggerConstants.COMMAND);
                        OnOffType cmd = (OnOffType) command;
                        if (mDevice instanceof MSwitchActor) {
                            OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
                            ((MSwitchActor) mDevice).turnSwitch(state);
                        } else if (mDevice instanceof DigitalActor) {
                            HighLowValue state = cmd == OnOffType.OFF ? HighLowValue.LOW : HighLowValue.HIGH;
                            ((DigitalActor) mDevice).turnDigital(state);
                        } else if (mDevice instanceof ProgrammableSwitchActor) {
                            OnOffValue state = cmd == OnOffType.OFF ? OnOffValue.OFF : OnOffValue.ON;
                            ((ProgrammableSwitchActor) mDevice).turnSwitch(state, provider.getDeviceOptions(itemName));
                        } else {
                            logger.error("{} received OnOff command for non-SwitchActor", LoggerConstants.COMMAND);
                        }
                    } else if (command instanceof StringType) {
                        logger.trace("{} found string command", LoggerConstants.COMMAND);
                        if (mDevice instanceof MTextActor) {
                            ((MTextActor) mDevice).write(command.toString());
                        }
                    } else if (command instanceof DecimalType) {
                        logger.debug("{} found number command", LoggerConstants.COMMAND);
                        if (command instanceof HSBType) {
                            logger.debug("{} found HSBType command", LoggerConstants.COMMAND);
                            if (mDevice instanceof ProgrammableColorActor) {
                                logger.debug("{} found ProgrammableColorActor {}", itemName);
                                ((ProgrammableColorActor) mDevice).setSelectedColor((HSBType) command, provider.getDeviceOptions(itemName));
                            } else if (mDevice instanceof SimpleColorActor) {
                                logger.debug("{} found SimpleColorActor {}", itemName);
                                ((SimpleColorActor) mDevice).setSelectedColor((HSBType) command);
                            }
                        } else if (command instanceof PercentType) {
                            if (mDevice instanceof SetPointActor) {
                                ((SetPointActor<?>) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
                                logger.debug("found SetpointActor");
                            } else if (mDevice instanceof PercentTypeActor) {
                                ((PercentTypeActor) mDevice).setValue(((PercentType) command), provider.getDeviceOptions(itemName));
                                logger.debug("found PercentType actor");
                            } else {
                                logger.error("found no percenttype actor");
                            }
                        } else {
                            if (mDevice instanceof NumberActor) {
                                ((NumberActor) mDevice).setNumber(((DecimalType) command).toBigDecimal());
                            } else if (mDevice instanceof SetPointActor) {
                                ((SetPointActor<?>) mDevice).setValue(((DecimalType) command).toBigDecimal(), provider.getDeviceOptions(itemName));
                            } else {
                                logger.error("found no number actor");
                            }
                        }
                    } else if (command instanceof UpDownType) {
                        UpDownType cmd = (UpDownType) command;
                        logger.debug("{} UpDownType command {}", itemName, cmd);
                        if (mDevice instanceof MoveActor) {
                            ((MoveActor) mDevice).move((UpDownType) command, provider.getDeviceOptions(itemName));
                        }
                    } else if (command instanceof StopMoveType) {
                        StopMoveType cmd = (StopMoveType) command;
                        if (mDevice instanceof MoveActor) {
                            if (cmd == StopMoveType.STOP) {
                                ((MoveActor) mDevice).stop();
                            } else {
                                ((MoveActor) mDevice).moveon(provider.getDeviceOptions(itemName));
                            }
                        }
                        logger.debug("{} StopMoveType command {}", itemName, cmd);
                    } else if (command instanceof IncreaseDecreaseType) {
                        IncreaseDecreaseType cmd = (IncreaseDecreaseType) command;
                        if (mDevice instanceof DimmableActor) {
                            ((DimmableActor<?>) mDevice).dimm((IncreaseDecreaseType) command, provider.getDeviceOptions(itemName));
                        }
                        logger.debug("{} IncreaseDecreaseType command {}", itemName, cmd);
                    } else {
                        logger.error("{} got unknown command type: {}", LoggerConstants.COMMAND, command.toString());
                    }
                } else {
                    logger.error("{} no tinkerforge device found for command for item uid: {} subId: {}", LoggerConstants.COMMAND, deviceUid, deviceSubId);
                }
            }
        }
    }
}
Also used : MSwitchActor(org.openhab.binding.tinkerforge.internal.model.MSwitchActor) StringType(org.openhab.core.library.types.StringType) PercentTypeActor(org.openhab.binding.tinkerforge.internal.model.PercentTypeActor) MBaseDevice(org.openhab.binding.tinkerforge.internal.model.MBaseDevice) ProgrammableColorActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableColorActor) StopMoveType(org.openhab.core.library.types.StopMoveType) TinkerforgeBindingProvider(org.openhab.binding.tinkerforge.TinkerforgeBindingProvider) HighLowValue(org.openhab.binding.tinkerforge.internal.types.HighLowValue) HSBType(org.openhab.core.library.types.HSBType) ProgrammableSwitchActor(org.openhab.binding.tinkerforge.internal.model.ProgrammableSwitchActor) OnOffValue(org.openhab.binding.tinkerforge.internal.types.OnOffValue) SetPointActor(org.openhab.binding.tinkerforge.internal.model.SetPointActor) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) DigitalActor(org.openhab.binding.tinkerforge.internal.model.DigitalActor) OnOffType(org.openhab.core.library.types.OnOffType) MoveActor(org.openhab.binding.tinkerforge.internal.model.MoveActor) DimmableActor(org.openhab.binding.tinkerforge.internal.model.DimmableActor) MTextActor(org.openhab.binding.tinkerforge.internal.model.MTextActor) DecimalType(org.openhab.core.library.types.DecimalType) NumberActor(org.openhab.binding.tinkerforge.internal.model.NumberActor) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) SimpleColorActor(org.openhab.binding.tinkerforge.internal.model.SimpleColorActor)

Example 90 with PercentType

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

the class XbmcConnector method requestApplicationUpdate.

public void requestApplicationUpdate() {
    final ApplicationGetProperties app = new ApplicationGetProperties(client, httpUri);
    app.execute(new Runnable() {

        @Override
        public void run() {
            // now update each of the openHAB items for each property
            volume = new BigDecimal(app.getVolume());
            updateProperty("Application.Volume", new PercentType(volume));
        }
    });
}
Also used : PercentType(org.openhab.core.library.types.PercentType) BigDecimal(java.math.BigDecimal) ApplicationGetProperties(org.openhab.binding.xbmc.rpc.calls.ApplicationGetProperties)

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