Search in sources :

Example 1 with PlayPauseType

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

the class ChromecastCommander method handleControl.

private void handleControl(final Command command) {
    try {
        Application app = chromeCast.getRunningApp();
        statusUpdater.updateStatus(ThingStatus.ONLINE);
        if (app == null) {
            logger.debug("{} command ignored because media player app is not running", command);
            return;
        }
        if (command instanceof PlayPauseType) {
            MediaStatus mediaStatus = chromeCast.getMediaStatus();
            logger.debug("mediaStatus {}", mediaStatus);
            if (mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.IDLE) {
                logger.debug("{} command ignored because media is not loaded", command);
                return;
            }
            final PlayPauseType playPause = (PlayPauseType) command;
            if (playPause == PlayPauseType.PLAY) {
                chromeCast.play();
            } else if (playPause == PlayPauseType.PAUSE && ((mediaStatus.supportedMediaCommands & 0x00000001) == 0x1)) {
                chromeCast.pause();
            } else {
                logger.info("{} command not supported by current media", command);
            }
        }
        if (command instanceof NextPreviousType) {
            // Next is implemented by seeking to the end of the current media
            if (command == NextPreviousType.NEXT) {
                Double duration = statusUpdater.getLastDuration();
                if (duration != null) {
                    chromeCast.seek(duration.doubleValue() - 5);
                } else {
                    logger.info("{} command failed - unknown media duration", command);
                }
            } else {
                logger.info("{} command not yet implemented", command);
                return;
            }
        }
    } catch (final IOException e) {
        logger.debug("{} command failed: {}", command, e.getMessage());
        statusUpdater.updateStatus(ThingStatus.OFFLINE, COMMUNICATION_ERROR, e.getMessage());
    }
}
Also used : PlayPauseType(org.openhab.core.library.types.PlayPauseType) IOException(java.io.IOException) Application(su.litvak.chromecast.api.v2.Application) NextPreviousType(org.openhab.core.library.types.NextPreviousType) MediaStatus(su.litvak.chromecast.api.v2.MediaStatus)

Example 2 with PlayPauseType

use of org.openhab.core.library.types.PlayPauseType 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;
    }
}
Also used : ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) StringType(org.openhab.core.library.types.StringType) QuantityType(org.openhab.core.library.types.QuantityType) KodiPVRChannel(org.openhab.binding.kodi.internal.model.KodiPVRChannel) Channel(org.openhab.core.thing.Channel) PlayPauseType(org.openhab.core.library.types.PlayPauseType) DecimalType(org.openhab.core.library.types.DecimalType) PercentType(org.openhab.core.library.types.PercentType) NextPreviousType(org.openhab.core.library.types.NextPreviousType) RewindFastforwardType(org.openhab.core.library.types.RewindFastforwardType)

Example 3 with PlayPauseType

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

the class RotelHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    String channel = channelUID.getId();
    if (getThing().getStatus() != ThingStatus.ONLINE) {
        logger.debug("Thing is not ONLINE; command {} from channel {} is ignored", command, channel);
        return;
    }
    if (command instanceof RefreshType) {
        updateChannelState(channel);
        return;
    }
    if (!connector.isConnected()) {
        logger.debug("Command {} from channel {} is ignored: connection not established", command, channel);
        return;
    }
    RotelSource src;
    RotelCommand cmd;
    boolean success = true;
    synchronized (sequenceLock) {
        try {
            switch(channel) {
                case CHANNEL_POWER:
                case CHANNEL_MAIN_POWER:
                    handlePowerCmd(channel, command, getPowerOnCommand(), getPowerOffCommand());
                    break;
                case CHANNEL_ZONE2_POWER:
                    if (connector.getModel().hasZone2Commands()) {
                        handlePowerCmd(channel, command, RotelCommand.ZONE2_POWER_ON, RotelCommand.ZONE2_POWER_OFF);
                    } else if (connector.getModel().getNbAdditionalZones() == 1) {
                        if (isPowerOn() || powerZone2) {
                            selectZone(2, connector.getModel().getZoneSelectCmd());
                        }
                        connector.sendCommand(RotelCommand.ZONE_SELECT);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE3_POWER:
                    if (connector.getModel().hasZone3Commands()) {
                        handlePowerCmd(channel, command, RotelCommand.ZONE3_POWER_ON, RotelCommand.ZONE3_POWER_OFF);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE4_POWER:
                    if (connector.getModel().hasZone4Commands()) {
                        handlePowerCmd(channel, command, RotelCommand.ZONE4_POWER_ON, RotelCommand.ZONE4_POWER_OFF);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_SOURCE:
                case CHANNEL_MAIN_SOURCE:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = connector.getModel().hasOtherThanPrimaryCommands() ? src.getMainZoneCommand() : src.getCommand();
                        if (cmd != null) {
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined source command", command, channel);
                        }
                    }
                    break;
                case CHANNEL_MAIN_RECORD_SOURCE:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (connector.getModel().hasOtherThanPrimaryCommands()) {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getRecordCommand();
                        if (cmd != null) {
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined record source command", command, channel);
                        }
                    } else {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getCommand();
                        if (cmd != null) {
                            connector.sendCommand(RotelCommand.RECORD_FONCTION_SELECT);
                            Thread.sleep(100);
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined source command", command, channel);
                        }
                    }
                    break;
                case CHANNEL_ZONE2_SOURCE:
                    if (!powerZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 2 in standby", command, channel);
                    } else if (connector.getModel().hasZone2Commands()) {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getZone2Command();
                        if (cmd != null) {
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined zone 2 source command", command, channel);
                        }
                    } else if (connector.getModel().getNbAdditionalZones() >= 1) {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getCommand();
                        if (cmd != null) {
                            selectZone(2, connector.getModel().getZoneSelectCmd());
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined source command", command, channel);
                        }
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE3_SOURCE:
                    if (!powerZone3) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 3 in standby", command, channel);
                    } else if (connector.getModel().hasZone3Commands()) {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getZone3Command();
                        if (cmd != null) {
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined zone 3 source command", command, channel);
                        }
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE4_SOURCE:
                    if (!powerZone4) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 4 in standby", command, channel);
                    } else if (connector.getModel().hasZone4Commands()) {
                        src = connector.getModel().getSourceFromName(command.toString());
                        cmd = src.getZone4Command();
                        if (cmd != null) {
                            connector.sendCommand(cmd);
                        } else {
                            success = false;
                            logger.debug("Command {} from channel {} failed: undefined zone 4 source command", command, channel);
                        }
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_DSP:
                case CHANNEL_MAIN_DSP:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else {
                        connector.sendCommand(connector.getModel().getCommandFromDspName(command.toString()));
                    }
                    break;
                case CHANNEL_VOLUME:
                case CHANNEL_MAIN_VOLUME:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl()) {
                        handleVolumeCmd(volume, channel, command, getVolumeUpCommand(), getVolumeDownCommand(), RotelCommand.VOLUME_SET);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_MAIN_VOLUME_UP_DOWN:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl()) {
                        handleVolumeCmd(volume, channel, command, getVolumeUpCommand(), getVolumeDownCommand(), null);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE2_VOLUME:
                    if (!powerZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 2 in standby", command, channel);
                    } else if (fixedVolumeZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: fixed volume in zone 2", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().getNbAdditionalZones() >= 1) {
                        if (connector.getModel().hasZone2Commands()) {
                            handleVolumeCmd(volumeZone2, channel, command, RotelCommand.ZONE2_VOLUME_UP, RotelCommand.ZONE2_VOLUME_DOWN, RotelCommand.ZONE2_VOLUME_SET);
                        } else {
                            selectZone(2, connector.getModel().getZoneSelectCmd());
                            handleVolumeCmd(volumeZone2, channel, command, RotelCommand.VOLUME_UP, RotelCommand.VOLUME_DOWN, RotelCommand.VOLUME_SET);
                        }
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE2_VOLUME_UP_DOWN:
                    if (!powerZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 2 in standby", command, channel);
                    } else if (fixedVolumeZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: fixed volume in zone 2", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().getNbAdditionalZones() >= 1) {
                        if (connector.getModel().hasZone2Commands()) {
                            handleVolumeCmd(volumeZone2, channel, command, RotelCommand.ZONE2_VOLUME_UP, RotelCommand.ZONE2_VOLUME_DOWN, null);
                        } else {
                            selectZone(2, connector.getModel().getZoneSelectCmd());
                            handleVolumeCmd(volumeZone2, channel, command, RotelCommand.VOLUME_UP, RotelCommand.VOLUME_DOWN, null);
                        }
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE3_VOLUME:
                    if (!powerZone3) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 3 in standby", command, channel);
                    } else if (fixedVolumeZone3) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: fixed volume in zone 3", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().hasZone3Commands()) {
                        handleVolumeCmd(volumeZone3, channel, command, RotelCommand.ZONE3_VOLUME_UP, RotelCommand.ZONE3_VOLUME_DOWN, RotelCommand.ZONE3_VOLUME_SET);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE4_VOLUME:
                    if (!powerZone4) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 4 in standby", command, channel);
                    } else if (fixedVolumeZone4) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: fixed volume in zone 4", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().hasZone4Commands()) {
                        handleVolumeCmd(volumeZone4, channel, command, RotelCommand.ZONE4_VOLUME_UP, RotelCommand.ZONE4_VOLUME_DOWN, RotelCommand.ZONE4_VOLUME_SET);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_MUTE:
                case CHANNEL_MAIN_MUTE:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl()) {
                        handleMuteCmd(connector.getProtocol() == RotelProtocol.HEX, channel, command, getMuteOnCommand(), getMuteOffCommand(), getMuteToggleCommand());
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE2_MUTE:
                    if (!powerZone2) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 2 in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().hasZone2Commands()) {
                        handleMuteCmd(false, channel, command, RotelCommand.ZONE2_MUTE_ON, RotelCommand.ZONE2_MUTE_OFF, RotelCommand.ZONE2_MUTE_TOGGLE);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE3_MUTE:
                    if (!powerZone3) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 3 in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().hasZone3Commands()) {
                        handleMuteCmd(false, channel, command, RotelCommand.ZONE3_MUTE_ON, RotelCommand.ZONE3_MUTE_OFF, RotelCommand.ZONE3_MUTE_TOGGLE);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_ZONE4_MUTE:
                    if (!powerZone4) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: zone 4 in standby", command, channel);
                    } else if (connector.getModel().hasVolumeControl() && connector.getModel().hasZone4Commands()) {
                        handleMuteCmd(false, channel, command, RotelCommand.ZONE4_MUTE_ON, RotelCommand.ZONE4_MUTE_OFF, RotelCommand.ZONE4_MUTE_TOGGLE);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    }
                    break;
                case CHANNEL_BASS:
                case CHANNEL_MAIN_BASS:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else {
                        handleToneCmd(bass, channel, command, 2, RotelCommand.BASS_UP, RotelCommand.BASS_DOWN, RotelCommand.BASS_SET);
                    }
                    break;
                case CHANNEL_TREBLE:
                case CHANNEL_MAIN_TREBLE:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else {
                        handleToneCmd(treble, channel, command, 1, RotelCommand.TREBLE_UP, RotelCommand.TREBLE_DOWN, RotelCommand.TREBLE_SET);
                    }
                    break;
                case CHANNEL_PLAY_CONTROL:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (command instanceof PlayPauseType && command == PlayPauseType.PLAY) {
                        connector.sendCommand(RotelCommand.PLAY);
                    } else if (command instanceof PlayPauseType && command == PlayPauseType.PAUSE) {
                        connector.sendCommand(RotelCommand.PAUSE);
                        if (connector.getProtocol() == RotelProtocol.ASCII_V1 && connector.getModel() != RotelModel.RCD1570 && connector.getModel() != RotelModel.RCD1572 && connector.getModel() != RotelModel.RCX1500) {
                            Thread.sleep(50);
                            connector.sendCommand(RotelCommand.PLAY_STATUS);
                        }
                    } else if (command instanceof NextPreviousType && command == NextPreviousType.NEXT) {
                        connector.sendCommand(RotelCommand.TRACK_FORWARD);
                    } else if (command instanceof NextPreviousType && command == NextPreviousType.PREVIOUS) {
                        connector.sendCommand(RotelCommand.TRACK_BACKWORD);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: invalid command value", command, channel);
                    }
                    break;
                case CHANNEL_BRIGHTNESS:
                    if (!isPowerOn()) {
                        success = false;
                        logger.debug("Command {} from channel {} ignored: device in standby", command, channel);
                    } else if (!connector.getModel().hasDimmerControl()) {
                        success = false;
                        logger.debug("Command {} from channel {} failed: unavailable feature", command, channel);
                    } else if (command instanceof PercentType) {
                        int dimmer = (int) Math.round(((PercentType) command).doubleValue() / 100.0 * (connector.getModel().getDimmerLevelMax() - connector.getModel().getDimmerLevelMin())) + connector.getModel().getDimmerLevelMin();
                        connector.sendCommand(RotelCommand.DIMMER_LEVEL_SET, dimmer);
                    } else {
                        success = false;
                        logger.debug("Command {} from channel {} failed: invalid command value", command, channel);
                    }
                    break;
                default:
                    success = false;
                    logger.debug("Command {} from channel {} failed: nnexpected command", command, channel);
                    break;
            }
            if (success) {
                logger.debug("Command {} from channel {} succeeded", command, channel);
            } else {
                updateChannelState(channel);
            }
        } catch (RotelException e) {
            logger.debug("Command {} from channel {} failed: {}", command, channel, e.getMessage());
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "@text/offline.comm-error-sending-command");
            closeConnection();
            scheduleReconnectJob();
        } catch (InterruptedException e) {
            logger.debug("Command {} from channel {} interrupted: {}", command, channel, e.getMessage());
            Thread.currentThread().interrupt();
        }
    }
}
Also used : RotelException(org.openhab.binding.rotel.internal.RotelException) RotelSource(org.openhab.binding.rotel.internal.communication.RotelSource) PlayPauseType(org.openhab.core.library.types.PlayPauseType) RotelCommand(org.openhab.binding.rotel.internal.communication.RotelCommand) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) NextPreviousType(org.openhab.core.library.types.NextPreviousType)

Example 4 with PlayPauseType

use of org.openhab.core.library.types.PlayPauseType 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));
    }
}
Also used : State(org.openhab.core.types.State) PlayPauseType(org.openhab.core.library.types.PlayPauseType) RefreshType(org.openhab.core.types.RefreshType) NextPreviousType(org.openhab.core.library.types.NextPreviousType) RewindFastforwardType(org.openhab.core.library.types.RewindFastforwardType)

Example 5 with PlayPauseType

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

the class YamahaZoneThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (zoneControl == null) {
        return;
    }
    String id = channelUID.getIdWithoutGroup();
    try {
        if (command instanceof RefreshType) {
            refreshFromState(channelUID);
            return;
        }
        switch(id) {
            case CHANNEL_POWER:
                zoneControl.setPower(((OnOffType) command) == OnOffType.ON);
                break;
            case CHANNEL_INPUT:
                zoneControl.setInput(((StringType) command).toString());
                break;
            case CHANNEL_SURROUND:
                zoneControl.setSurroundProgram(((StringType) command).toString());
                break;
            case CHANNEL_VOLUME_DB:
                zoneControl.setVolumeDB(((DecimalType) command).floatValue());
                break;
            case CHANNEL_VOLUME:
                if (command instanceof DecimalType) {
                    zoneControl.setVolume(((DecimalType) command).floatValue());
                } else if (command instanceof IncreaseDecreaseType) {
                    zoneControl.setVolumeRelative(zoneState, (((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE ? 1 : -1) * zoneConfig.getVolumeRelativeChangeFactor());
                }
                break;
            case CHANNEL_MUTE:
                zoneControl.setMute(((OnOffType) command) == OnOffType.ON);
                break;
            case CHANNEL_SCENE:
                zoneControl.setScene(((StringType) command).toString());
                break;
            case CHANNEL_DIALOGUE_LEVEL:
                zoneControl.setDialogueLevel(((DecimalType) command).intValue());
                break;
            case CHANNEL_HDMI1OUT:
                zoneControl.setHDMI1Out(((OnOffType) command) == OnOffType.ON);
                break;
            case CHANNEL_HDMI2OUT:
                zoneControl.setHDMI2Out(((OnOffType) command) == OnOffType.ON);
                break;
            case CHANNEL_NAVIGATION_MENU:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                String path = ((StringType) command).toFullString();
                inputWithNavigationControl.selectItemFullPath(path);
                break;
            case CHANNEL_NAVIGATION_UPDOWN:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                if (((UpDownType) command) == UpDownType.UP) {
                    inputWithNavigationControl.goUp();
                } else {
                    inputWithNavigationControl.goDown();
                }
                break;
            case CHANNEL_NAVIGATION_LEFTRIGHT:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                if (((UpDownType) command) == UpDownType.UP) {
                    inputWithNavigationControl.goLeft();
                } else {
                    inputWithNavigationControl.goRight();
                }
                break;
            case CHANNEL_NAVIGATION_SELECT:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                inputWithNavigationControl.selectCurrentItem();
                break;
            case CHANNEL_NAVIGATION_BACK:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                inputWithNavigationControl.goBack();
                break;
            case CHANNEL_NAVIGATION_BACKTOROOT:
                if (inputWithNavigationControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                inputWithNavigationControl.goToRoot();
                break;
            case CHANNEL_PLAYBACK_PRESET:
                if (inputWithPresetControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                if (command instanceof DecimalType) {
                    inputWithPresetControl.selectItemByPresetNumber(((DecimalType) command).intValue());
                } else if (command instanceof StringType) {
                    try {
                        int v = Integer.valueOf(((StringType) command).toString());
                        inputWithPresetControl.selectItemByPresetNumber(v);
                    } catch (NumberFormatException e) {
                        logger.warn("Provide a number for {}", id);
                    }
                }
                break;
            case CHANNEL_TUNER_BAND:
                if (inputWithDabBandControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                if (command instanceof StringType) {
                    inputWithDabBandControl.selectBandByName(command.toString());
                } else {
                    logger.warn("Provide a string for {}", id);
                }
                break;
            case CHANNEL_PLAYBACK:
                if (inputWithPlayControl == null) {
                    logger.warn("Channel {} not working with {} input!", id, zoneState.inputID);
                    return;
                }
                if (command instanceof PlayPauseType) {
                    PlayPauseType t = ((PlayPauseType) command);
                    switch(t) {
                        case PAUSE:
                            inputWithPlayControl.pause();
                            break;
                        case PLAY:
                            inputWithPlayControl.play();
                            break;
                    }
                } else if (command instanceof NextPreviousType) {
                    NextPreviousType t = ((NextPreviousType) command);
                    switch(t) {
                        case NEXT:
                            inputWithPlayControl.nextTrack();
                            break;
                        case PREVIOUS:
                            inputWithPlayControl.previousTrack();
                            break;
                    }
                } else if (command instanceof DecimalType) {
                    int v = ((DecimalType) command).intValue();
                    if (v < 0) {
                        inputWithPlayControl.skipREV();
                    } else if (v > 0) {
                        inputWithPlayControl.skipFF();
                    }
                } else if (command instanceof StringType) {
                    String v = ((StringType) command).toFullString();
                    switch(v) {
                        case "Play":
                            inputWithPlayControl.play();
                            break;
                        case "Pause":
                            inputWithPlayControl.pause();
                            break;
                        case "Stop":
                            inputWithPlayControl.stop();
                            break;
                        case "Rewind":
                            inputWithPlayControl.skipREV();
                            break;
                        case "FastForward":
                            inputWithPlayControl.skipFF();
                            break;
                        case "Next":
                            inputWithPlayControl.nextTrack();
                            break;
                        case "Previous":
                            inputWithPlayControl.previousTrack();
                            break;
                    }
                }
                break;
            default:
                logger.warn("Channel {} not supported!", id);
        }
    } catch (IOException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
    } catch (ReceivedMessageParseException e) {
        // Some AVRs send unexpected responses. We log parser exceptions therefore.
        logger.debug("Parse error!", e);
    }
}
Also used : ReceivedMessageParseException(org.openhab.binding.yamahareceiver.internal.protocol.ReceivedMessageParseException) StringType(org.openhab.core.library.types.StringType) PlayPauseType(org.openhab.core.library.types.PlayPauseType) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) UpDownType(org.openhab.core.library.types.UpDownType) IOException(java.io.IOException) RefreshType(org.openhab.core.types.RefreshType) NextPreviousType(org.openhab.core.library.types.NextPreviousType)

Aggregations

PlayPauseType (org.openhab.core.library.types.PlayPauseType)12 NextPreviousType (org.openhab.core.library.types.NextPreviousType)9 DecimalType (org.openhab.core.library.types.DecimalType)7 PercentType (org.openhab.core.library.types.PercentType)6 RewindFastforwardType (org.openhab.core.library.types.RewindFastforwardType)6 StringType (org.openhab.core.library.types.StringType)5 RefreshType (org.openhab.core.types.RefreshType)5 Channel (org.openhab.core.thing.Channel)3 State (org.openhab.core.types.State)3 IOException (java.io.IOException)2 DateTimeType (org.openhab.core.library.types.DateTimeType)2 HSBType (org.openhab.core.library.types.HSBType)2 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)2 OnOffType (org.openhab.core.library.types.OnOffType)2 UpDownType (org.openhab.core.library.types.UpDownType)2 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)2 Duration (java.time.Duration)1 BoseSoundTouchNotificationChannelConfiguration (org.openhab.binding.bosesoundtouch.internal.BoseSoundTouchNotificationChannelConfiguration)1 OperationModeType (org.openhab.binding.bosesoundtouch.internal.OperationModeType)1 RemoteKeyType (org.openhab.binding.bosesoundtouch.internal.RemoteKeyType)1