Search in sources :

Example 66 with StringType

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

the class LedVisualize method visualizationLedsAndLogicOpsStatus.

/**
     * Visualization for {@link DecimalType} and {@link StringType}.
     * {@inheritDoc}
     */
@Override
public boolean visualizationLedsAndLogicOpsStatus(ModStatusLedsAndLogicOps pchkInput, Command cmd, Item item, EventPublisher eventPublisher) {
    if (pchkInput.getLogicalSourceAddr().equals(this.addr)) {
        if (item.getAcceptedDataTypes().contains(DecimalType.class)) {
            int n;
            switch(pchkInput.getLedState(this.ledId)) {
                case OFF:
                    n = 0;
                    break;
                case ON:
                    n = 1;
                    break;
                case BLINK:
                    n = 2;
                    break;
                case FLICKER:
                    n = 3;
                    break;
                default:
                    throw new Error();
            }
            eventPublisher.postUpdate(item.getName(), new DecimalType(n));
            return true;
        } else if (item.getAcceptedDataTypes().contains(StringType.class)) {
            String s;
            switch(pchkInput.getLedState(this.ledId)) {
                case OFF:
                    s = this.stateTexts[0];
                    break;
                case ON:
                    s = this.stateTexts[1];
                    break;
                case BLINK:
                    s = this.stateTexts[2];
                    break;
                case FLICKER:
                    s = this.stateTexts[3];
                    break;
                default:
                    throw new Error();
            }
            eventPublisher.postUpdate(item.getName(), new StringType(s));
            return true;
        }
    }
    return false;
}
Also used : StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 67 with StringType

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

the class MpdBinding method songChanged.

private void songChanged(String playerId, MPDSong newSong) {
    String title = getTitle(newSong);
    logger.debug("Current song {}: {}", playerId, title);
    String[] itemNames = getItemNamesByPlayerAndPlayerCommand(playerId, PlayerCommandTypeMapping.TRACKINFO);
    // move to utilities?
    for (String itemName : itemNames) {
        if (StringUtils.isNotBlank(itemName)) {
            eventPublisher.postUpdate(itemName, new StringType(title));
            logger.debug("Updated title: {}, {}", itemName, title);
        }
    }
    String artist = getArtist(newSong);
    itemNames = getItemNamesByPlayerAndPlayerCommand(playerId, PlayerCommandTypeMapping.TRACKARTIST);
    for (String itemName : itemNames) {
        if (StringUtils.isNotBlank(itemName)) {
            eventPublisher.postUpdate(itemName, new StringType(artist));
            logger.debug("Updated artist: {}, {}", itemName, artist);
        }
    }
    int songID = newSong.getId();
    itemNames = getItemNamesByPlayerAndPlayerCommand(playerId, PlayerCommandTypeMapping.PLAYSONGID);
    for (String itemName : itemNames) {
        if (StringUtils.isNotBlank(itemName)) {
            eventPublisher.postUpdate(itemName, new DecimalType(songID));
            logger.debug("Updated song ID: {}, {}", itemName, songID);
        }
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType)

Example 68 with StringType

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

the class MyStromEcoPowerBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    // the frequently executed code (polling) goes here ...
    logger.debug("execute() method is called!");
    if (this.devicesMap.isEmpty()) {
        return;
    }
    List<MystromDevice> devices = this.mystromClient.getDevicesState();
    for (MyStromEcoPowerBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            logger.debug("Mystrom eco power switch '{}' state will be updated", itemName);
            String friendlyName = provider.getMystromFriendlyName(itemName);
            String id = this.devicesMap.get(friendlyName);
            if (id != null) {
                MystromDevice device = null;
                for (MystromDevice searchDevice : devices) {
                    if (searchDevice.id.equals(id)) {
                        device = searchDevice;
                        break;
                    }
                }
                if (device != null) {
                    if (provider.getIsSwitch(itemName)) {
                        State state = device.state.equals("on") ? OnOffType.ON : OnOffType.OFF;
                        eventPublisher.postUpdate(itemName, state);
                    }
                    if (provider.getIsStringItem(itemName)) {
                        // publish state of device, on/off/offline
                        eventPublisher.postUpdate(itemName, new StringType(device.state));
                    }
                    if (provider.getIsNumberItem(itemName)) {
                        eventPublisher.postUpdate(itemName, new DecimalType(device.power));
                    }
                }
            } else {
                logger.warn("The device itemName '{}' not found on discovery. Verify device is not offline", itemName);
            }
        }
    }
}
Also used : StringType(org.openhab.core.library.types.StringType) State(org.openhab.core.types.State) MyStromEcoPowerBindingProvider(org.openhab.binding.mystromecopower.MyStromEcoPowerBindingProvider) DecimalType(org.openhab.core.library.types.DecimalType) MystromDevice(org.openhab.binding.mystromecopower.internal.api.model.MystromDevice)

Example 69 with StringType

use of org.openhab.core.library.types.StringType 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 70 with StringType

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

the class Zone method updateItem.

@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
    int current = ((properties.getStatus() >> 0) & 0x03);
    int latched = ((properties.getStatus() >> 2) & 0x03);
    int arming = ((properties.getStatus() >> 4) & 0x03);
    String latchedTxt = (latched < LATCHED_TEXT.length ? LATCHED_TEXT[latched] : "?");
    String armingTxt = (arming < ARMING_TEXT.length ? ARMING_TEXT[arming] : "?");
    String currentTxt = (current < CURRENT_TEXT.length ? CURRENT_TEXT[current] : "?");
    int setting = 0;
    String str = "";
    switch(config.getObjectType()) {
        case ZONE_STATUS_ARMING:
            setting = arming;
            str = armingTxt;
            break;
        case ZONE_STATUS_CURRENT:
            setting = current;
            str = currentTxt;
            break;
        case ZONE_STATUS_LATCHED:
            setting = latched;
            str = latchedTxt;
            break;
        case ZONE_STATUS_ALL:
            str = currentTxt + " | " + latchedTxt + " | " + armingTxt;
            break;
        default:
            break;
    }
    if (item instanceof NumberItem) {
        publisher.postUpdate(item.getName(), new DecimalType(setting));
    } else if (item instanceof StringItem) {
        publisher.postUpdate(item.getName(), new StringType(str));
    } else if (item instanceof ContactItem) {
        publisher.postUpdate(item.getName(), current == 0 ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) StringType(org.openhab.core.library.types.StringType) ContactItem(org.openhab.core.library.items.ContactItem) DecimalType(org.openhab.core.library.types.DecimalType) StringItem(org.openhab.core.library.items.StringItem)

Aggregations

StringType (org.openhab.core.library.types.StringType)90 DecimalType (org.openhab.core.library.types.DecimalType)69 State (org.openhab.core.types.State)30 DateTimeType (org.openhab.core.library.types.DateTimeType)28 PercentType (org.openhab.core.library.types.PercentType)27 NumberItem (org.openhab.core.library.items.NumberItem)25 Calendar (java.util.Calendar)23 StringItem (org.openhab.core.library.items.StringItem)18 OnOffType (org.openhab.core.library.types.OnOffType)15 SwitchItem (org.openhab.core.library.items.SwitchItem)12 ContactItem (org.openhab.core.library.items.ContactItem)10 DimmerItem (org.openhab.core.library.items.DimmerItem)10 RollershutterItem (org.openhab.core.library.items.RollershutterItem)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DateTimeItem (org.openhab.core.library.items.DateTimeItem)8 HSBType (org.openhab.core.library.types.HSBType)8 ConfigurationException (org.osgi.service.cm.ConfigurationException)8 IOException (java.io.IOException)7 BigDecimal (java.math.BigDecimal)7