Java Code Examples for org.eclipse.smarthome.core.library.types.StringType
The following examples show how to use
org.eclipse.smarthome.core.library.types.StringType. These examples are extracted from open source projects.
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 Project: smarthome Source File: ValueTests.java License: Eclipse Public License 2.0 | 6 votes |
@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 2
Source Project: IpCamera Source File: IpCameraHandler.java License: Eclipse Public License 2.0 | 6 votes |
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 3
Source Project: smarthome Source File: ZonePlayerHandler.java License: Eclipse Public License 2.0 | 6 votes |
/** * 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 4
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 6 votes |
@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 Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 6 votes |
@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 Project: smarthome Source File: GroupItemTest.java License: Eclipse Public License 2.0 | 6 votes |
@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 Project: smarthome Source File: GroupItemTest.java License: Eclipse Public License 2.0 | 6 votes |
@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 Project: smarthome Source File: ItemDTOMapperTest.java License: Eclipse Public License 2.0 | 6 votes |
@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 Project: smarthome Source File: ZonePlayerHandler.java License: Eclipse Public License 2.0 | 6 votes |
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 10
Source Project: smarthome Source File: MapTransformationProfile.java License: Eclipse Public License 2.0 | 6 votes |
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 11
Source Project: smarthome Source File: PropertyUtils.java License: Eclipse Public License 2.0 | 6 votes |
/** * 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 12
Source Project: smarthome Source File: SonyAudioHandler.java License: Eclipse Public License 2.0 | 6 votes |
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 13
Source Project: smarthome Source File: ZonePlayerHandler.java License: Eclipse Public License 2.0 | 6 votes |
/** * 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 14
Source Project: smarthome Source File: LightStateConverter.java License: Eclipse Public License 2.0 | 6 votes |
/** * 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 15
Source Project: smarthome Source File: CommandExecutor.java License: Eclipse Public License 2.0 | 6 votes |
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 Project: smarthome Source File: RollershutterValue.java License: Eclipse Public License 2.0 | 6 votes |
/** * 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 17
Source Project: org.openhab.binding.heos Source File: HeosPlayerHandler.java License: Eclipse Public License 1.0 | 5 votes |
@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 18
Source Project: org.openhab.binding.heos Source File: HeosGroupHandler.java License: Eclipse Public License 1.0 | 5 votes |
@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 19
Source Project: org.openhab.binding.heos Source File: HeosThingBaseHandler.java License: Eclipse Public License 1.0 | 5 votes |
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 20
Source Project: org.openhab.binding.heos Source File: HeosPlayerHandler.java License: Eclipse Public License 1.0 | 5 votes |
@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 Project: org.openhab.binding.heos Source File: HeosGroupHandler.java License: Eclipse Public License 1.0 | 5 votes |
@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 Project: smarthome Source File: ValueTests.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void openCloseUpdate() { OpenCloseValue v = new OpenCloseValue("fancyON", "fancyOff"); // Test with command v.update(OpenClosedType.CLOSED); assertThat(v.getMQTTpublishValue(), is("fancyOff")); assertThat(v.getChannelState(), is(OpenClosedType.CLOSED)); v.update(OpenClosedType.OPEN); assertThat(v.getMQTTpublishValue(), is("fancyON")); assertThat(v.getChannelState(), is(OpenClosedType.OPEN)); // Test with string, representing the command v.update(new StringType("CLOSED")); assertThat(v.getMQTTpublishValue(), is("fancyOff")); assertThat(v.getChannelState(), is(OpenClosedType.CLOSED)); v.update(new StringType("OPEN")); assertThat(v.getMQTTpublishValue(), is("fancyON")); assertThat(v.getChannelState(), is(OpenClosedType.OPEN)); // Test with custom string, setup in the constructor v.update(new StringType("fancyOff")); assertThat(v.getMQTTpublishValue(), is("fancyOff")); assertThat(v.getChannelState(), is(OpenClosedType.CLOSED)); v.update(new StringType("fancyON")); assertThat(v.getMQTTpublishValue(), is("fancyON")); assertThat(v.getChannelState(), is(OpenClosedType.OPEN)); }
Example 23
Source Project: smarthome Source File: LIRCRemoteHandler.java License: Eclipse Public License 2.0 | 5 votes |
@Override public void handleCommand(ChannelUID channelUID, Command command) { logger.debug("Received channel: {}, command: {}", channelUID, command); if (remoteName == null) { logger.error("Remote name is not set in {}", getThing().getUID()); return; } if (channelUID.getId().equals(LIRCBindingConstants.CHANNEL_TRANSMIT)) { // command instanceof RefreshType is not supported if (command instanceof StringType) { bridgeHandler.transmit(remoteName, command.toString()); } } }
Example 24
Source Project: smarthome Source File: ZonePlayerHandler.java License: Eclipse Public License 2.0 | 5 votes |
/** * Play a given url to music in one of the music libraries. * * @param url * in the format of //host/folder/filename.mp3 */ public void playURI(Command command) { if (command != null && command instanceof StringType) { try { String url = command.toString(); ZonePlayerHandler coordinator = getCoordinatorHandler(); // stop whatever is currently playing coordinator.stop(); coordinator.waitForNotTransportState(STATE_PLAYING); // clear any tracks which are pending in the queue coordinator.removeAllTracksFromQueue(); // add the new track we want to play to the queue // The url will be prefixed with x-file-cifs if it is NOT a http URL if (!url.startsWith("x-") && (!url.startsWith("http"))) { // default to file based url url = FILE_URI + url; } coordinator.addURIToQueue(url, "", 0, true); // set the current playlist to our new queue coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", ""); // take the system off mute coordinator.setMute(OnOffType.OFF); // start jammin' coordinator.play(); } catch (IllegalStateException e) { logger.debug("Cannot play URI ({})", e.getMessage()); } } }
Example 25
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@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 26
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void getLabel_itemNotFound() throws ItemNotFoundException { String testLabel = "Label [%s]"; when(widget.getLabel()).thenReturn(testLabel); when(widget.eClass()).thenReturn(SitemapFactory.eINSTANCE.createText().eClass()); when(registry.getItem("Item")).thenThrow(new ItemNotFoundException("Item")); when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label [-]", label); }
Example 27
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void getLabel_labelWithFunctionValue() { String testLabel = "Label [MAP(de.map):%s]"; when(widget.getLabel()).thenReturn(testLabel); when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label [State]", label); }
Example 28
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void getLabel_labelWithoutStateDescription() { String testLabel = "Label"; when(widget.getLabel()).thenReturn(testLabel); when(item.getStateDescription()).thenReturn(null); when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label", label); }
Example 29
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void getLabel_labelWithoutPatternInStateDescription() { String testLabel = "Label"; StateDescription stateDescription = mock(StateDescription.class); when(widget.getLabel()).thenReturn(testLabel); when(item.getStateDescription()).thenReturn(stateDescription); when(stateDescription.getPattern()).thenReturn(null); when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label", label); }
Example 30
Source Project: smarthome Source File: ItemUIRegistryImplTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void getLabel_labelWithPatternInStateDescription() { String testLabel = "Label"; StateDescription stateDescription = mock(StateDescription.class); when(widget.getLabel()).thenReturn(testLabel); when(item.getStateDescription()).thenReturn(stateDescription); when(stateDescription.getPattern()).thenReturn("%s"); when(item.getState()).thenReturn(new StringType("State")); String label = uiRegistry.getLabel(widget); assertEquals("Label [State]", label); }