org.eclipse.smarthome.core.library.types.StringType Java Examples

The following examples show how to use org.eclipse.smarthome.core.library.types.StringType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RollershutterValue.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * The stop command will not update the internal state and is posted to the framework.
 * <p>
 * The Up/Down commands (100%/0%) are not updating the state directly and are also
 * posted as percent value to the framework. It is up to the user if the posted values
 * are applied to the item state immediately (autoupdate=true) or not.
 */
@Override
public @Nullable Command isPostOnly(Command command) {
    if (command instanceof UpDownType) {
        return command;
    } else if (command instanceof StopMoveType) {
        return command;
    } else if (command instanceof StringType) {
        final String updatedValue = command.toString();
        if (updatedValue.equals(upString)) {
            return UpDownType.UP.as(PercentType.class);
        } else if (updatedValue.equals(downString)) {
            return UpDownType.DOWN.as(PercentType.class);
        } else if (updatedValue.equals(stopString)) {
            return StopMoveType.STOP;
        }
    }
    return null;
}
 
Example #2
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Handle the execution of the notification sound by sequentially executing the required steps.
 *
 * @param notificationURL - the notification url in the format of //host/folder/filename.mp3
 * @param coordinator - {@link ZonePlayerHandler} coordinator for the SONOS device(s)
 */
private void handleNotificationSound(Command notificationURL, ZonePlayerHandler coordinator) {
    String originalVolume = (isAdHocGroup() || isStandalonePlayer()) ? getVolume() : coordinator.getVolume();
    coordinator.stop();
    coordinator.waitForNotTransportState(STATE_PLAYING);
    applyNotificationSoundVolume();
    long notificationPosition = coordinator.getQueueSize() + 1;
    coordinator.addURIToQueue(notificationURL.toString(), "", notificationPosition, false);
    coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");
    coordinator.setPositionTrack(notificationPosition);
    coordinator.play();
    coordinator.waitForFinishedNotification();
    if (originalVolume != null) {
        setVolumeForGroup(DecimalType.valueOf(originalVolume));
    }
    coordinator.removeRangeOfTracksFromQueue(new StringType(Long.toString(notificationPosition) + ",1"));
}
 
Example #3
Source File: IpCameraHandler.java    From IpCamera with Eclipse Public License 2.0 6 votes vote down vote up
void bringCameraOnline() {
    isOnline = true;
    updateStatus(ThingStatus.ONLINE);
    listOfOnlineCameraHandlers.add(this);
    listOfOnlineCameraUID.add(getThing().getUID().getId());
    if (cameraConnectionJob != null) {
        cameraConnectionJob.cancel(true);
        cameraConnection.shutdown();
        cameraConnection = Executors.newScheduledThreadPool(1);
    }
    pollCameraJob = pollCamera.scheduleAtFixedRate(pollingCamera, 4000,
            Integer.parseInt(config.get(CONFIG_POLL_CAMERA_MS).toString()), TimeUnit.MILLISECONDS);
    if (!rtspUri.equals("")) {
        updateState(CHANNEL_RTSP_URL, new StringType(rtspUri));
    }
    if (updateImageChannel) {
        updateState(CHANNEL_UPDATE_IMAGE_NOW, OnOffType.valueOf("ON"));
    } else {
        updateState(CHANNEL_UPDATE_IMAGE_NOW, OnOffType.valueOf("OFF"));
    }
    if (!listOfGroupHandlers.isEmpty()) {
        for (IpCameraGroupHandler handle : listOfGroupHandlers) {
            handle.cameraOnline(getThing().getUID().getId());
        }
    }
}
 
Example #4
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void getLabel_labelWithMappedOption() {
    String testLabel = "Label";

    StateDescription stateDescription = mock(StateDescription.class);
    List<StateOption> options = new ArrayList<>();
    options.add(new StateOption("State0", "This is the state 0"));
    options.add(new StateOption("State1", "This is the state 1"));
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(stateDescription.getOptions()).thenReturn(options);
    when(item.getState()).thenReturn(new StringType("State1"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [This is the state 1]", label);
}
 
Example #5
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void getLabel_labelWithUnmappedOption() {
    String testLabel = "Label";

    StateDescription stateDescription = mock(StateDescription.class);
    List<StateOption> options = new ArrayList<>();
    options.add(new StateOption("State0", "This is the state 0"));
    options.add(new StateOption("State1", "This is the state 1"));
    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getStateDescription()).thenReturn(stateDescription);
    when(stateDescription.getPattern()).thenReturn("%s");
    when(stateDescription.getOptions()).thenReturn(options);
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [State]", label);
}
 
Example #6
Source File: GroupItemTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertCyclicGroupItemsCalculateState() {
    GroupFunction countFn = new ArithmeticGroupFunction.Count(new StringType(".*"));
    GroupItem rootGroup = new GroupItem("rootGroup", new SwitchItem("baseItem"), countFn);
    TestItem rootMember = new TestItem("rootMember");
    rootGroup.addMember(rootMember);

    GroupItem group1 = new GroupItem("group1");
    GroupItem group2 = new GroupItem("group2");

    rootGroup.addMember(group1);
    group1.addMember(group2);
    group2.addMember(group1);

    group1.addMember(new TestItem("sub1"));
    group2.addMember(new TestItem("sub2-1"));
    group2.addMember(new TestItem("sub2-2"));
    group2.addMember(new TestItem("sub2-3"));

    // count: rootMember, sub1, sub2-1, sub2-2, sub2-3
    assertThat(rootGroup.getStateAs(DecimalType.class), is(new DecimalType(5)));
}
 
Example #7
Source File: GroupItemTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertCyclicGroupItemsCalculateStateWithSubGroupFunction() {
    GroupFunction countFn = new ArithmeticGroupFunction.Count(new StringType(".*"));
    GroupItem rootGroup = new GroupItem("rootGroup", new SwitchItem("baseItem"), countFn);
    TestItem rootMember = new TestItem("rootMember");
    rootGroup.addMember(rootMember);

    GroupItem group1 = new GroupItem("group1");
    GroupItem group2 = new GroupItem("group2", new SwitchItem("baseItem"), new ArithmeticGroupFunction.Sum());

    rootGroup.addMember(group1);
    group1.addMember(group2);
    group2.addMember(group1);

    group1.addMember(new TestItem("sub1"));
    group2.addMember(new TestItem("sub2-1"));
    group2.addMember(new TestItem("sub2-2"));
    group2.addMember(new TestItem("sub2-3"));

    // count: rootMember, sub1, group2
    assertThat(rootGroup.getStateAs(DecimalType.class), is(new DecimalType(3)));
}
 
Example #8
Source File: ItemDTOMapperTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMapFunctionWithNumberItemAndCountFunction() {

    // testing Group:Number:Count(".*hello.*")
    NumberItem item1 = new NumberItem("item1");

    GroupFunctionDTO gFuncDTO = new GroupFunctionDTO();
    gFuncDTO.name = "COUNT";
    gFuncDTO.params = new String[] { ".*hello.*" };

    GroupFunction gFunc = ItemDTOMapper.mapFunction(item1, gFuncDTO);

    assertThat(gFunc, instanceOf(ArithmeticGroupFunction.Count.class));
    assertThat(gFunc.getParameters().length, is(1));
    assertThat(gFunc.getParameters()[0], instanceOf(StringType.class));

}
 
Example #9
Source File: ValueTests.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void rollershutterUpdate() {
    RollershutterValue v = new RollershutterValue("fancyON", "fancyOff", "fancyStop");
    // Test with command
    v.update(UpDownType.UP);
    assertThat(v.getMQTTpublishValue(), is("0"));
    assertThat(v.getChannelState(), is(PercentType.ZERO));
    v.update(UpDownType.DOWN);
    assertThat(v.getMQTTpublishValue(), is("100"));
    assertThat(v.getChannelState(), is(PercentType.HUNDRED));

    // Test with custom string
    v.update(new StringType("fancyON"));
    assertThat(v.getMQTTpublishValue(), is("0"));
    assertThat(v.getChannelState(), is(PercentType.ZERO));
    v.update(new StringType("fancyOff"));
    assertThat(v.getMQTTpublishValue(), is("100"));
    assertThat(v.getChannelState(), is(PercentType.HUNDRED));
    v.update(new StringType("27"));
    assertThat(v.getMQTTpublishValue(), is("27"));
    assertThat(v.getChannelState(), is(new PercentType(27)));
}
 
Example #10
Source File: PropertyUtils.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the state of the channel.
 */
public static State getState(ChannelUID channelUID, AstroChannelConfig config, Object instance) throws Exception {
    Object value = getPropertyValue(channelUID, instance);
    if (value == null) {
        return UnDefType.UNDEF;
    } else if (value instanceof State) {
        return (State) value;
    } else if (value instanceof Calendar) {
        Calendar cal = (Calendar) value;
        GregorianCalendar gregorianCal = (GregorianCalendar) DateTimeUtils.applyConfig(cal, config);
        cal.setTimeZone(TimeZone.getTimeZone(timeZoneProvider.getTimeZone()));
        ZonedDateTime zoned = gregorianCal.toZonedDateTime().withFixedOffsetZone();
        return new DateTimeType(zoned);
    } else if (value instanceof Number) {
        BigDecimal decimalValue = new BigDecimal(value.toString()).setScale(2, RoundingMode.HALF_UP);
        return new DecimalType(decimalValue);
    } else if (value instanceof String || value instanceof Enum) {
        return new StringType(value.toString());
    } else {
        throw new IllegalStateException("Unsupported value type " + value.getClass().getSimpleName());
    }
}
 
Example #11
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void handleInputCommand(Command command, ChannelUID channelUID, int zone) throws IOException {
    if (command instanceof RefreshType) {
        logger.debug("handleInputCommand RefreshType {}", zone);
        try {
            SonyAudioConnection.SonyAudioInput result = inputCache[zone].getValue();
            if (result != null) {
                if (zone > 0) {
                    input_zone.put(zone, result.input);
                }
                updateState(channelUID, inputSource(result.input));

                if (result.radio_freq.isPresent()) {
                    updateState(SonyAudioBindingConstants.CHANNEL_RADIO_FREQ,
                            new DecimalType(result.radio_freq.get() / 1000000.0));
                }
            }
        } catch (CompletionException ex) {
            throw new IOException(ex.getCause());
        }
    }
    if (command instanceof StringType) {
        logger.debug("handleInputCommand set {} {}", zone, command);
        connection.setInput(setInputCommand(command), zone);
    }
}
 
Example #12
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Play a given notification sound
 *
 * @param url in the format of //host/folder/filename.mp3
 */
public void playNotificationSoundURI(Command notificationURL) {
    if (notificationURL != null && notificationURL instanceof StringType) {
        try {
            ZonePlayerHandler coordinator = getCoordinatorHandler();

            String currentURI = coordinator.getCurrentURI();

            if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(currentURI)
                    || isPlayingRadio(currentURI)) {
                handleRadioStream(currentURI, notificationURL, coordinator);
            } else if (isPlayingLineIn(currentURI)) {
                handleLineIn(currentURI, notificationURL, coordinator);
            } else if (isPlayingQueue(currentURI)) {
                handleSharedQueue(notificationURL, coordinator);
            } else if (isPlaylistEmpty(coordinator)) {
                handleEmptyQueue(notificationURL, coordinator);
            }
            synchronized (notificationLock) {
                notificationLock.notify();
            }
        } catch (IllegalStateException e) {
            logger.debug("Cannot play sound ({})", e.getMessage());
        }
    }
}
 
Example #13
Source File: LightStateConverter.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Transforms the given {@link StringType} into a light state containing the {@link AlertMode} to be triggered.
 *
 * @param alertType {@link StringType} representing the required {@link AlertMode} . <br>
 *            Supported values are:
 *            <ul>
 *            <li>{@value #ALERT_MODE_NONE}.
 *            <li>{@value #ALERT_MODE_SELECT}.
 *            <li>{@value #ALERT_MODE_LONG_SELECT}.
 *            <ul>
 * @return light state containing the {@link AlertMode} or <b><code>null </code></b> if the provided
 *         {@link StringType} represents unsupported mode.
 */
public static @Nullable StateUpdate toAlertState(StringType alertType) {
    AlertMode alertMode;

    switch (alertType.toString()) {
        case ALERT_MODE_NONE:
            alertMode = State.AlertMode.NONE;
            break;
        case ALERT_MODE_SELECT:
            alertMode = State.AlertMode.SELECT;
            break;
        case ALERT_MODE_LONG_SELECT:
            alertMode = State.AlertMode.LSELECT;
            break;
        default:
            return null;
    }
    return new StateUpdate().setAlert(alertMode);
}
 
Example #14
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void setRepeat(Command command) {
    if ((command != null) && (command instanceof StringType)) {
        try {
            ZonePlayerHandler coordinator = getCoordinatorHandler();

            switch (command.toString()) {
                case "ALL":
                    coordinator.updatePlayMode(coordinator.isShuffleActive() ? "SHUFFLE" : "REPEAT_ALL");
                    break;
                case "ONE":
                    coordinator.updatePlayMode(coordinator.isShuffleActive() ? "SHUFFLE_REPEAT_ONE" : "REPEAT_ONE");
                    break;
                case "OFF":
                    coordinator.updatePlayMode(coordinator.isShuffleActive() ? "SHUFFLE_NOREPEAT" : "NORMAL");
                    break;
                default:
                    logger.debug("{}: unexpected repeat command; accepted values are ALL, ONE and OFF",
                            command.toString());
                    break;
            }
        } catch (IllegalStateException e) {
            logger.debug("Cannot handle repeat command ({})", e.getMessage());
        }
    }
}
 
Example #15
Source File: CommandExecutor.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void updateOperatingValues() {
    OperationModeType operationMode;
    if (currentContentItem != null) {
        updatePresetGUIState(new DecimalType(currentContentItem.getPresetID()));
        operationMode = currentContentItem.getOperationMode();
    } else {
        operationMode = OperationModeType.STANDBY;
    }

    updateOperationModeGUIState(new StringType(operationMode.toString()));
    currentOperationMode = operationMode;
    if (currentOperationMode == OperationModeType.STANDBY) {
        updatePowerStateGUIState(OnOffType.OFF);
        updatePlayerControlGUIState(PlayPauseType.PAUSE);
    } else {
        updatePowerStateGUIState(OnOffType.ON);
    }
}
 
Example #16
Source File: MapTransformationProfile.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private Type transformState(Type state) {
    String result = state.toFullString();
    try {
        result = TransformationHelper.transform(service, function, sourceFormat, state.toFullString());
        if (result != null && result.isEmpty()) {
            // map transformation service returns an empty string if the entry is not found in the map, we will use
            // the original value
            result = state.toFullString();
        }
    } catch (TransformationException e) {
        logger.warn("Could not transform state '{}' with function '{}' and format '{}'", state, function,
                sourceFormat);
    }
    StringType resultType = new StringType(result);
    logger.debug("Transformed '{}' into '{}'", state, resultType);
    return resultType;
}
 
Example #17
Source File: TextValue.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a string value with a limited number of allowed states.
 *
 * @param states Allowed states. Empty states are filtered out. If the resulting set is empty, all string values
 *            will be allowed.
 */
public TextValue(String[] states) {
    super(CoreItemFactory.STRING, Collections.singletonList(StringType.class));
    Set<String> s = Stream.of(states).filter(e -> StringUtils.isNotBlank(e)).collect(Collectors.toSet());
    if (s.size() > 0) {
        this.states = s;
    } else {
        this.states = null;
    }
}
 
Example #18
Source File: ImageRenderer.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Image image = (Image) w;
    String snippet = (image.getChildren().size() > 0) ? getSnippet("image_link") : getSnippet("image");

    if (image.getRefresh() > 0) {
        snippet = StringUtils.replace(snippet, "%refresh%", "id=\"%id%\" data-timeout=\"" + image.getRefresh()
                + "\" onload=\"startReloadImage('%url%', '%id%')\"");
    } else {
        snippet = StringUtils.replace(snippet, "%refresh%", "");
    }

    String widgetId = itemUIRegistry.getWidgetId(w);
    snippet = StringUtils.replace(snippet, "%id%", widgetId);

    String sitemap = null;
    if (w.eResource() != null) {
        sitemap = w.eResource().getURI().path();
    }
    boolean validUrl = isValidURL(image.getUrl());
    String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
    State state = itemUIRegistry.getState(w);
    String url;
    if (state instanceof RawType) {
        url = state.toFullString();
    } else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
        url = proxiedUrl + "&t=" + (new Date()).getTime();
    } else {
        url = "images/none.png";
    }
    snippet = StringUtils.replace(snippet, "%url%", url);

    sb.append(snippet);
    return null;
}
 
Example #19
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public void playTuneinStation(Command command) {
    if (command instanceof StringType) {
        String stationId = command.toString();
        List<SonosMusicService> allServices = getAvailableMusicServices();

        SonosMusicService tuneinService = null;
        // search for the TuneIn music service based on its name
        if (allServices != null) {
            for (SonosMusicService service : allServices) {
                if (service.getName().equals("TuneIn")) {
                    tuneinService = service;
                    break;
                }
            }
        }

        // set the URI of the group coordinator
        if (tuneinService != null) {
            try {
                ZonePlayerHandler coordinator = getCoordinatorHandler();
                SonosEntry entry = new SonosEntry("", "TuneIn station", "", "", "", "",
                        "object.item.audioItem.audioBroadcast",
                        String.format(TUNEIN_URI, stationId, tuneinService.getId()));
                entry.setDesc("SA_RINCON" + tuneinService.getType().toString() + "_");
                coordinator.setCurrentURI(entry);
                coordinator.play();
            } catch (IllegalStateException e) {
                logger.debug("Cannot play TuneIn station {} ({})", stationId, e.getMessage());
            }
        } else {
            logger.debug("TuneIn service not found");
        }
    }
}
 
Example #20
Source File: HeosPlayerHandler.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void refreshChannels() {
    if (player.getLevel() != null) {
        updateState(CH_ID_VOLUME, PercentType.valueOf(player.getLevel()));
    }

    if (player.getMute().equals(ON)) {
        updateState(CH_ID_MUTE, OnOffType.ON);
    } else {
        updateState(CH_ID_MUTE, OnOffType.OFF);
    }

    if (player.getState().equals(PLAY)) {
        updateState(CH_ID_CONTROL, PlayPauseType.PLAY);
    }
    if (player.getState().equals(PAUSE) || player.getState().equals(STOP)) {
        updateState(CH_ID_CONTROL, PlayPauseType.PAUSE);
    }
    if (player.getShuffle().equals(HeosConstants.HEOS_ON)) {
        updateState(CH_ID_SHUFFLE_MODE, OnOffType.ON);
    }
    if (player.getShuffle().equals(HeosConstants.HEOS_OFF)) {
        updateState(CH_ID_SHUFFLE_MODE, OnOffType.OFF);
    }
    updateState(CH_ID_SONG, StringType.valueOf(player.getSong()));
    updateState(CH_ID_ARTIST, StringType.valueOf(player.getArtist()));
    updateState(CH_ID_ALBUM, StringType.valueOf(player.getAlbum()));
    updateState(CH_ID_IMAGE_URL, StringType.valueOf(player.getImageUrl()));
    updateState(CH_ID_STATION, StringType.valueOf(player.getStation()));
    updateState(CH_ID_TYPE, StringType.valueOf(player.getType()));
    updateState(CH_ID_CUR_POS, StringType.valueOf("0"));
    updateState(CH_ID_DURATION, StringType.valueOf("0"));
    updateState(CH_ID_INPUTS, StringType.valueOf("NULL"));
    updateState(CH_ID_REPEAT_MODE, StringType.valueOf(player.getRepeatMode()));

}
 
Example #21
Source File: HeosGroupHandler.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void refreshChannels() {
    postCommand(CH_ID_UNGROUP, OnOffType.ON);
    updateState(CH_ID_VOLUME, PercentType.valueOf(heosGroup.getLevel()));

    if (heosGroup.getMute().equals(ON)) {
        updateState(CH_ID_MUTE, OnOffType.ON);
    } else {
        updateState(CH_ID_MUTE, OnOffType.OFF);
    }

    if (heosGroup.getState().equals(PLAY)) {
        updateState(CH_ID_CONTROL, PlayPauseType.PLAY);
    }
    if (heosGroup.getState().equals(PAUSE) || heosGroup.getState().equals(STOP)) {
        updateState(CH_ID_CONTROL, PlayPauseType.PAUSE);
    }
    if (heosGroup.getShuffle().equals(HeosConstants.HEOS_ON)) {
        updateState(CH_ID_SHUFFLE_MODE, OnOffType.ON);
    }
    if (heosGroup.getShuffle().equals(HeosConstants.HEOS_OFF)) {
        updateState(CH_ID_SHUFFLE_MODE, OnOffType.OFF);
    }
    updateState(CH_ID_SONG, StringType.valueOf(heosGroup.getSong()));
    updateState(CH_ID_ARTIST, StringType.valueOf(heosGroup.getArtist()));
    updateState(CH_ID_ALBUM, StringType.valueOf(heosGroup.getAlbum()));
    updateState(CH_ID_IMAGE_URL, StringType.valueOf(heosGroup.getImageUrl()));
    updateState(CH_ID_STATION, StringType.valueOf(heosGroup.getStation()));
    updateState(CH_ID_TYPE, StringType.valueOf(heosGroup.getType()));
    updateState(CH_ID_CUR_POS, StringType.valueOf("0"));
    updateState(CH_ID_DURATION, StringType.valueOf("0"));
    updateState(CH_ID_REPEAT_MODE, StringType.valueOf(heosGroup.getRepeatMode()));
}
 
Example #22
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public void handleRadioSeekStationCommand(Command command, ChannelUID channelUID) throws IOException {
    if (command instanceof RefreshType) {
        updateState(channelUID, new StringType(""));
    }
    if (command instanceof StringType) {
        switch (((StringType) command).toString()) {
            case "fwdSeeking":
                connection.radioSeekFwd();
                break;
            case "bwdSeeking":
                connection.radioSeekBwd();
                break;
        }
    }
}
 
Example #23
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public void addMember(Command command) {
    if (command != null && command instanceof StringType) {
        SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", GROUP_URI + getUDN());
        try {
            getHandlerByName(command.toString()).setCurrentURI(entry);
        } catch (IllegalStateException e) {
            logger.debug("Cannot add group member ({})", e.getMessage());
        }
    }
}
 
Example #24
Source File: HtSt5000Handler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public StringType inputSource(String input) {
    String in = input.toLowerCase();
    if (in.contains("extinput:btaudio".toLowerCase())) {
        return new StringType("btaudio");
    }
    if (in.contains("extinput:tv".toLowerCase())) {
        return new StringType("tv");
    }
    if (in.contains("extinput:hdmi?port=1".toLowerCase())) {
        return new StringType("hdmi1");
    }
    if (in.contains("extinput:hdmi?port=2".toLowerCase())) {
        return new StringType("hdmi2");
    }
    if (in.contains("extinput:hdmi?port=3".toLowerCase())) {
        return new StringType("hdmi3");
    }
    if (in.contains("extinput:line".toLowerCase())) {
        return new StringType("analog");
    }
    if (in.contains("storage:usb1".toLowerCase())) {
        return new StringType("usb");
    }
    if (in.contains("dlna:music".toLowerCase())) {
        return new StringType("network");
    }
    if (in.contains("cast:audio".toLowerCase())) {
        return new StringType("cast");
    }
    return new StringType(input);
}
 
Example #25
Source File: HeosThingBaseHandler.java    From org.openhab.binding.heos with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleThingMediaUpdate(HashMap<String, String> info) {
    for (String key : info.keySet()) {
        switch (key) {
            case SONG:
                updateState(CH_ID_SONG, StringType.valueOf(info.get(key)));
                break;
            case ARTIST:
                updateState(CH_ID_ARTIST, StringType.valueOf(info.get(key)));
                break;
            case ALBUM:
                updateState(CH_ID_ALBUM, StringType.valueOf(info.get(key)));
                break;
            case IMAGE_URL:
                updateState(CH_ID_IMAGE_URL, StringType.valueOf(info.get(key)));
                break;
            case STATION:
                if (info.get(SID).equals(INPUT_SID)) {
                    String inputName = info.get(MID).substring(info.get(MID).indexOf("/") + 1); // removes the
                                                                                                // "input/" part
                                                                                                // before the
                                                                                                // input name
                    updateState(CH_ID_INPUTS, StringType.valueOf(inputName));
                }
                updateState(CH_ID_STATION, StringType.valueOf(info.get(key)));
                break;
            case TYPE:
                updateState(CH_ID_TYPE, StringType.valueOf(info.get(key)));
                if (info.get(key).equals(STATION)) {
                    updateState(CH_ID_STATION, StringType.valueOf(info.get(STATION)));
                } else {
                    updateState(CH_ID_STATION, StringType.valueOf("No Station"));
                }
                break;
        }
    }
}
 
Example #26
Source File: ItemUIRegistryImplTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void getLabel_labelWithStringValue() {
    String testLabel = "Label [%s]";

    when(widget.getLabel()).thenReturn(testLabel);
    when(item.getState()).thenReturn(new StringType("State"));
    String label = uiRegistry.getLabel(widget);
    assertEquals("Label [State]", label);
}
 
Example #27
Source File: GenericThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void handleCommandUpdateString() {
    TextValue value = spy(new TextValue());
    ChannelState channelConfig = spy(
            new ChannelState(ChannelConfigBuilder.create("stateTopic", "commandTopic").build(), textChannelUID,
                    value, thingHandler));
    doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
    thingHandler.initialize();
    thingHandler.connection = connection;

    StringType updateValue = new StringType("UPDATE");
    thingHandler.handleCommand(textChannelUID, updateValue);
    verify(value).update(eq(updateValue));
    assertThat(channelConfig.getCache().getChannelState().toString(), is("UPDATE"));
}
 
Example #28
Source File: StateTypeAdapterTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void readWriteRoundtripShouldRecreateTheWrittenState() {
    assertThat(roundtrip(OnOffType.ON), is(equalTo(OnOffType.ON)));
    assertThat(roundtrip(PercentType.HUNDRED), is(equalTo(PercentType.HUNDRED)));
    assertThat(roundtrip(HSBType.GREEN), is(equalTo(HSBType.GREEN)));
    assertThat(roundtrip(StringType.valueOf("test")), is(equalTo(StringType.valueOf("test"))));
}
 
Example #29
Source File: HtZ9fHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public StringType inputSource(String input) {
    String in = input.toLowerCase();
    if (in.contains("extinput:btaudio".toLowerCase())) {
        return new StringType("btaudio");
    }
    if (in.contains("extinput:tv".toLowerCase())) {
        return new StringType("tv");
    }
    if (in.contains("extinput:hdmi?port=1".toLowerCase())) {
        return new StringType("hdmi1");
    }
    if (in.contains("extinput:hdmi?port=2".toLowerCase())) {
        return new StringType("hdmi2");
    }
    if (in.contains("extinput:line".toLowerCase())) {
        return new StringType("analog");
    }
    if (in.contains("storage:usb1".toLowerCase())) {
        return new StringType("usb");
    }
    if (in.contains("dlna:music".toLowerCase())) {
        return new StringType("network");
    }
    if (in.contains("cast:audio".toLowerCase())) {
        return new StringType("cast");
    }
    return new StringType(input);
}
 
Example #30
Source File: ScaleTransformationProfile.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private Type transformState(Type state) {
    String result = state.toFullString();
    try {
        result = TransformationHelper.transform(service, function, sourceFormat, state.toFullString());
    } catch (TransformationException e) {
        logger.warn("Could not transform state '{}' with function '{}' and format '{}'", state, function,
                sourceFormat);
    }
    StringType resultType = new StringType(result);
    logger.debug("Transformed '{}' into '{}'", state, resultType);
    return resultType;
}