use of org.openhab.core.library.types.RewindFastforwardType in project openhab-addons by openhab.
the class KodiHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
switch(channelUID.getIdWithoutGroup()) {
case CHANNEL_SCREENSAVER:
if (RefreshType.REFRESH == command) {
connection.updateScreenSaverState();
}
break;
case CHANNEL_MUTE:
if (command.equals(OnOffType.ON)) {
connection.setMute(true);
} else if (command.equals(OnOffType.OFF)) {
connection.setMute(false);
} else if (RefreshType.REFRESH == command) {
connection.updateVolume();
}
break;
case CHANNEL_VOLUME:
if (command instanceof PercentType) {
connection.setVolume(((PercentType) command).intValue());
} else if (command.equals(IncreaseDecreaseType.INCREASE)) {
connection.increaseVolume();
} else if (command.equals(IncreaseDecreaseType.DECREASE)) {
connection.decreaseVolume();
} else if (command.equals(OnOffType.OFF)) {
connection.setVolume(0);
} else if (command.equals(OnOffType.ON)) {
connection.setVolume(100);
} else if (RefreshType.REFRESH == command) {
connection.updateVolume();
}
break;
case CHANNEL_CONTROL:
if (command instanceof PlayPauseType) {
if (command.equals(PlayPauseType.PLAY)) {
connection.playerPlayPause();
} else if (command.equals(PlayPauseType.PAUSE)) {
connection.playerPlayPause();
}
} else if (command instanceof NextPreviousType) {
if (command.equals(NextPreviousType.NEXT)) {
connection.playerNext();
} else if (command.equals(NextPreviousType.PREVIOUS)) {
connection.playerPrevious();
}
} else if (command instanceof RewindFastforwardType) {
if (command.equals(RewindFastforwardType.REWIND)) {
connection.playerRewind();
} else if (command.equals(RewindFastforwardType.FASTFORWARD)) {
connection.playerFastForward();
}
} else if (RefreshType.REFRESH == command) {
connection.updatePlayerStatus();
}
break;
case CHANNEL_STOP:
if (command.equals(OnOffType.ON)) {
stop();
} else if (RefreshType.REFRESH == command) {
connection.updatePlayerStatus();
}
break;
case CHANNEL_PLAYURI:
if (command instanceof StringType) {
playURI(command);
updateState(CHANNEL_PLAYURI, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_PLAYURI, UnDefType.UNDEF);
}
break;
case CHANNEL_PLAYNOTIFICATION:
if (command instanceof StringType) {
playNotificationSoundURI((StringType) command);
updateState(CHANNEL_PLAYNOTIFICATION, UnDefType.UNDEF);
} else if (command.equals(RefreshType.REFRESH)) {
updateState(CHANNEL_PLAYNOTIFICATION, UnDefType.UNDEF);
}
break;
case CHANNEL_PLAYFAVORITE:
if (command instanceof StringType) {
playFavorite(command);
updateState(favoriteChannelUID, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(favoriteChannelUID, UnDefType.UNDEF);
}
break;
case CHANNEL_PVR_OPEN_TV:
if (command instanceof StringType) {
playPVRChannel(command, PVR_TV, CHANNEL_PVR_OPEN_TV);
updateState(CHANNEL_PVR_OPEN_TV, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_PVR_OPEN_TV, UnDefType.UNDEF);
}
break;
case CHANNEL_PVR_OPEN_RADIO:
if (command instanceof StringType) {
playPVRChannel(command, PVR_RADIO, CHANNEL_PVR_OPEN_RADIO);
updateState(CHANNEL_PVR_OPEN_RADIO, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_PVR_OPEN_RADIO, UnDefType.UNDEF);
}
break;
case CHANNEL_SHOWNOTIFICATION:
showNotification(channelUID, command);
break;
case CHANNEL_INPUT:
if (command instanceof StringType) {
connection.input(command.toString());
updateState(CHANNEL_INPUT, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_INPUT, UnDefType.UNDEF);
}
break;
case CHANNEL_INPUTTEXT:
if (command instanceof StringType) {
connection.inputText(command.toString());
updateState(CHANNEL_INPUTTEXT, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_INPUTTEXT, UnDefType.UNDEF);
}
break;
case CHANNEL_INPUTACTION:
if (command instanceof StringType) {
connection.inputAction(command.toString());
updateState(CHANNEL_INPUTACTION, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_INPUTACTION, UnDefType.UNDEF);
}
break;
case CHANNEL_INPUTBUTTONEVENT:
logger.debug("handleCommand CHANNEL_INPUTBUTTONEVENT {}.", command);
if (command instanceof StringType) {
connection.inputButtonEvent(command.toString());
updateState(CHANNEL_INPUTBUTTONEVENT, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_INPUTBUTTONEVENT, UnDefType.UNDEF);
}
break;
case CHANNEL_SYSTEMCOMMAND:
if (command instanceof StringType) {
handleSystemCommand(command.toString());
updateState(CHANNEL_SYSTEMCOMMAND, UnDefType.UNDEF);
} else if (RefreshType.REFRESH == command) {
updateState(CHANNEL_SYSTEMCOMMAND, UnDefType.UNDEF);
}
break;
case CHANNEL_PROFILE:
if (command instanceof StringType) {
connection.profile(command.toString());
} else if (RefreshType.REFRESH == command) {
connection.updateCurrentProfile();
}
break;
case CHANNEL_ARTIST:
case CHANNEL_ALBUM:
case CHANNEL_TITLE:
case CHANNEL_SHOWTITLE:
case CHANNEL_MEDIATYPE:
case CHANNEL_GENRELIST:
case CHANNEL_PVR_CHANNEL:
case CHANNEL_THUMBNAIL:
case CHANNEL_FANART:
case CHANNEL_AUDIO_CODEC:
break;
case CHANNEL_AUDIO_INDEX:
if (command instanceof DecimalType) {
connection.setAudioStream(((DecimalType) command).intValue());
}
break;
case CHANNEL_VIDEO_CODEC:
case CHANNEL_VIDEO_INDEX:
if (command instanceof DecimalType) {
connection.setVideoStream(((DecimalType) command).intValue());
}
break;
case CHANNEL_SUBTITLE_ENABLED:
if (command.equals(OnOffType.ON)) {
connection.setSubtitleEnabled(true);
} else if (command.equals(OnOffType.OFF)) {
connection.setSubtitleEnabled(false);
}
break;
case CHANNEL_SUBTITLE_INDEX:
if (command instanceof DecimalType) {
connection.setSubtitle(((DecimalType) command).intValue());
}
break;
case CHANNEL_CURRENTTIME:
if (command instanceof QuantityType) {
connection.setTime(((QuantityType<?>) command).intValue());
}
break;
case CHANNEL_CURRENTTIMEPERCENTAGE:
case CHANNEL_DURATION:
if (RefreshType.REFRESH == command) {
connection.updatePlayerStatus();
}
break;
default:
Channel channel = getThing().getChannel(channelUID);
if (channel != null) {
ChannelTypeUID ctuid = channel.getChannelTypeUID();
if (ctuid != null) {
if (ctuid.getId().equals(CHANNEL_TYPE_SHOWNOTIFICATION)) {
showNotification(channelUID, command);
break;
}
}
}
logger.debug("Received unknown channel {}", channelUID.getIdWithoutGroup());
break;
}
}
use of org.openhab.core.library.types.RewindFastforwardType in project openhab-addons by openhab.
the class UpnpRendererHandler method handleCommandControl.
private void handleCommandControl(ChannelUID channelUID, Command command) {
String state;
if (command instanceof RefreshType) {
state = transportState;
State newState = UnDefType.UNDEF;
if ("PLAYING".equals(state)) {
newState = PlayPauseType.PLAY;
} else if ("STOPPED".equals(state)) {
newState = PlayPauseType.PAUSE;
} else if ("PAUSED_PLAYBACK".equals(state)) {
newState = PlayPauseType.PAUSE;
}
updateState(channelUID, newState);
} else if (command instanceof PlayPauseType) {
if (PlayPauseType.PLAY.equals(command)) {
if (registeredQueue) {
registeredQueue = false;
playingQueue = true;
oneplayed = false;
serve();
} else {
play();
}
} else if (PlayPauseType.PAUSE.equals(command)) {
checkPaused();
pause();
}
} else if (command instanceof NextPreviousType) {
if (NextPreviousType.NEXT.equals(command)) {
serveNext();
} else if (NextPreviousType.PREVIOUS.equals(command)) {
servePrevious();
}
} else if (command instanceof RewindFastforwardType) {
int pos = 0;
if (RewindFastforwardType.FASTFORWARD.equals(command)) {
pos = Integer.min(trackDuration, trackPosition + config.seekStep);
} else if (command == RewindFastforwardType.REWIND) {
pos = Integer.max(0, trackPosition - config.seekStep);
}
seek(String.format("%02d:%02d:%02d", pos / 3600, (pos % 3600) / 60, pos % 60));
}
}
use of org.openhab.core.library.types.RewindFastforwardType in project openhab-addons by openhab.
the class PlayerItemRewindFastForwardIntegrationTest method storeData.
@SuppressWarnings("null")
@BeforeAll
public static void storeData(TestInfo testInfo) throws InterruptedException {
@NonNull RewindFastforwardType localState1, localState2;
if (isLegacyTest(testInfo)) {
// In legacy, FASTFORWARD < REWIND
STATE1 = RewindFastforwardType.FASTFORWARD;
STATE2 = RewindFastforwardType.REWIND;
} else {
// In non-legacy, FASTFORWARD (serialized as 1) > REWIND (-1)
STATE1 = RewindFastforwardType.REWIND;
STATE2 = RewindFastforwardType.FASTFORWARD;
}
localState1 = (@NonNull RewindFastforwardType) STATE1;
localState2 = (@NonNull RewindFastforwardType) STATE2;
assert localState1 != null;
assert localState2 != null;
PlayerItem item = (PlayerItem) ITEMS.get(NAME);
item.setState(localState1);
beforeStore = ZonedDateTime.now();
Thread.sleep(10);
service.store(item);
afterStore1 = ZonedDateTime.now();
Thread.sleep(10);
item.setState(localState2);
service.store(item);
Thread.sleep(10);
afterStore2 = ZonedDateTime.now();
LOGGER.info("Created item between {} and {}", AbstractDynamoDBItem.DATEFORMATTER.format(beforeStore), AbstractDynamoDBItem.DATEFORMATTER.format(afterStore1));
}
use of org.openhab.core.library.types.RewindFastforwardType in project openhab-addons by openhab.
the class SqueezeBoxPlayerHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (squeezeBoxServerHandler == null) {
logger.debug("Player {} has no server configured, ignoring command: {}", getThing().getUID(), command);
return;
}
// Some of the code below is not designed to handle REFRESH, only reply to channels where cached values exist
if (command == RefreshType.REFRESH) {
String channelID = channelUID.getId();
State newState = stateMap.get(channelID);
if (newState != null) {
updateState(channelID, newState);
}
return;
}
switch(channelUID.getIdWithoutGroup()) {
case CHANNEL_POWER:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.powerOn(mac);
} else {
squeezeBoxServerHandler.powerOff(mac);
}
break;
case CHANNEL_MUTE:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.mute(mac);
} else {
squeezeBoxServerHandler.unMute(mac);
}
break;
case CHANNEL_STOP:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.stop(mac);
} else if (command.equals(OnOffType.OFF)) {
squeezeBoxServerHandler.play(mac);
}
break;
case CHANNEL_PLAY_PAUSE:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.play(mac);
} else if (command.equals(OnOffType.OFF)) {
squeezeBoxServerHandler.pause(mac);
}
break;
case CHANNEL_PREV:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.prev(mac);
}
break;
case CHANNEL_NEXT:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.next(mac);
}
break;
case CHANNEL_VOLUME:
if (command instanceof PercentType) {
squeezeBoxServerHandler.setVolume(mac, ((PercentType) command).intValue());
} else if (command.equals(IncreaseDecreaseType.INCREASE)) {
squeezeBoxServerHandler.volumeUp(mac, currentVolume());
} else if (command.equals(IncreaseDecreaseType.DECREASE)) {
squeezeBoxServerHandler.volumeDown(mac, currentVolume());
} else if (command.equals(OnOffType.OFF)) {
squeezeBoxServerHandler.mute(mac);
} else if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.unMute(mac);
}
break;
case CHANNEL_CONTROL:
if (command instanceof PlayPauseType) {
if (command.equals(PlayPauseType.PLAY)) {
squeezeBoxServerHandler.play(mac);
} else if (command.equals(PlayPauseType.PAUSE)) {
squeezeBoxServerHandler.pause(mac);
}
}
if (command instanceof NextPreviousType) {
if (command.equals(NextPreviousType.NEXT)) {
squeezeBoxServerHandler.next(mac);
} else if (command.equals(NextPreviousType.PREVIOUS)) {
squeezeBoxServerHandler.prev(mac);
}
}
if (command instanceof RewindFastforwardType) {
if (command.equals(RewindFastforwardType.REWIND)) {
squeezeBoxServerHandler.setPlayingTime(mac, currentPlayingTime() - 5);
} else if (command.equals(RewindFastforwardType.FASTFORWARD)) {
squeezeBoxServerHandler.setPlayingTime(mac, currentPlayingTime() + 5);
}
}
break;
case CHANNEL_STREAM:
squeezeBoxServerHandler.playUrl(mac, command.toString());
break;
case CHANNEL_SYNC:
if (command.toString().isBlank()) {
squeezeBoxServerHandler.unSyncPlayer(mac);
} else {
squeezeBoxServerHandler.syncPlayer(mac, command.toString());
}
break;
case CHANNEL_UNSYNC:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.unSyncPlayer(mac);
}
break;
case CHANNEL_PLAYLIST_INDEX:
squeezeBoxServerHandler.playPlaylistItem(mac, ((DecimalType) command).intValue());
break;
case CHANNEL_CURRENT_PLAYING_TIME:
squeezeBoxServerHandler.setPlayingTime(mac, ((DecimalType) command).intValue());
break;
case CHANNEL_CURRENT_PLAYLIST_SHUFFLE:
squeezeBoxServerHandler.setShuffleMode(mac, ((DecimalType) command).intValue());
break;
case CHANNEL_CURRENT_PLAYLIST_REPEAT:
squeezeBoxServerHandler.setRepeatMode(mac, ((DecimalType) command).intValue());
break;
case CHANNEL_FAVORITES_PLAY:
squeezeBoxServerHandler.playFavorite(mac, command.toString());
break;
case CHANNEL_RATE:
if (command.equals(OnOffType.ON)) {
squeezeBoxServerHandler.rate(mac, likeCommand);
} else if (command.equals(OnOffType.OFF)) {
squeezeBoxServerHandler.rate(mac, unlikeCommand);
}
break;
case CHANNEL_SLEEP:
if (command instanceof DecimalType) {
Duration sleepDuration = Duration.ofMinutes(((DecimalType) command).longValue());
if (sleepDuration.isNegative() || sleepDuration.compareTo(Duration.ofDays(1)) > 0) {
logger.debug("Sleep timer of {} minutes must be >= 0 and <= 1 day", sleepDuration.toMinutes());
return;
}
squeezeBoxServerHandler.sleep(mac, sleepDuration);
}
break;
default:
break;
}
}
use of org.openhab.core.library.types.RewindFastforwardType in project openhab-addons by openhab.
the class AbstractDynamoDBItem method fromStateNew.
public static DynamoDBItem<?> fromStateNew(Item item, ZonedDateTime time, @Nullable Integer expireDays) {
String name = item.getName();
State state = item.getState();
if (item instanceof CallItem) {
return new DynamoDBStringItem(name, convert(state, StringListType.class).toFullString(), time, expireDays);
} else if (item instanceof ContactItem) {
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof DateTimeItem) {
return new DynamoDBStringItem(name, ZONED_DATE_TIME_CONVERTER_STRING.toString(((DateTimeType) state).getZonedDateTime()), time, expireDays);
} else if (item instanceof ImageItem) {
throw new IllegalArgumentException("Unsupported item " + item.getClass().getSimpleName());
} else if (item instanceof LocationItem) {
return new DynamoDBStringItem(name, state.toFullString(), time, expireDays);
} else if (item instanceof NumberItem) {
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof PlayerItem) {
if (state instanceof PlayPauseType) {
switch((PlayPauseType) state) {
case PLAY:
return new DynamoDBBigDecimalItem(name, PLAY_BIGDECIMAL, time, expireDays);
case PAUSE:
return new DynamoDBBigDecimalItem(name, PAUSE_BIGDECIMAL, time, expireDays);
default:
throw new IllegalArgumentException("Unexpected enum with PlayPauseType: " + state.toString());
}
} else if (state instanceof RewindFastforwardType) {
switch((RewindFastforwardType) state) {
case FASTFORWARD:
return new DynamoDBBigDecimalItem(name, FAST_FORWARD_BIGDECIMAL, time, expireDays);
case REWIND:
return new DynamoDBBigDecimalItem(name, REWIND_BIGDECIMAL, time, expireDays);
default:
throw new IllegalArgumentException("Unexpected enum with RewindFastforwardType: " + state.toString());
}
} else {
throw new IllegalStateException(String.format("Unexpected state type %s with PlayerItem", state.getClass().getSimpleName()));
}
} else if (item instanceof RollershutterItem) {
// Normalize UP/DOWN to %
return new DynamoDBBigDecimalItem(name, convert(state, PercentType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof StringItem) {
if (state instanceof StringType) {
return new DynamoDBStringItem(name, ((StringType) state).toString(), time, expireDays);
} else if (state instanceof DateTimeType) {
return new DynamoDBStringItem(name, ZONED_DATE_TIME_CONVERTER_STRING.toString(((DateTimeType) state).getZonedDateTime()), time, expireDays);
} else {
throw new IllegalStateException(String.format("Unexpected state type %s with StringItem", state.getClass().getSimpleName()));
}
} else if (item instanceof ColorItem) {
// Note: needs to be before parent class DimmerItem
return new DynamoDBStringItem(name, convert(state, HSBType.class).toFullString(), time, expireDays);
} else if (item instanceof DimmerItem) {
// Normalize ON/OFF to %
return new DynamoDBBigDecimalItem(name, convert(state, PercentType.class).toBigDecimal(), time, expireDays);
} else if (item instanceof SwitchItem) {
// Normalize ON/OFF to 1/0
return new DynamoDBBigDecimalItem(name, convert(state, DecimalType.class).toBigDecimal(), time, expireDays);
} else {
throw new IllegalArgumentException("Unsupported item " + item.getClass().getSimpleName());
}
}
Aggregations