use of org.openhab.binding.rotel.internal.communication.RotelSource 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();
}
}
}
use of org.openhab.binding.rotel.internal.communication.RotelSource in project openhab-addons by openhab.
the class RotelHandler method updateChannelState.
/**
* Update the state of a channel
*
* @param channel the channel
*/
private void updateChannelState(String channel) {
if (!isLinked(channel)) {
return;
}
State state = UnDefType.UNDEF;
switch(channel) {
case CHANNEL_POWER:
case CHANNEL_MAIN_POWER:
if (power != null) {
state = power ? OnOffType.ON : OnOffType.OFF;
}
break;
case CHANNEL_ZONE2_POWER:
state = powerZone2 ? OnOffType.ON : OnOffType.OFF;
break;
case CHANNEL_ZONE3_POWER:
state = powerZone3 ? OnOffType.ON : OnOffType.OFF;
break;
case CHANNEL_ZONE4_POWER:
state = powerZone4 ? OnOffType.ON : OnOffType.OFF;
break;
case CHANNEL_SOURCE:
case CHANNEL_MAIN_SOURCE:
if (isPowerOn()) {
state = new StringType(source.getName());
}
break;
case CHANNEL_MAIN_RECORD_SOURCE:
RotelSource recordSource = this.recordSource;
if (isPowerOn() && recordSource != null) {
state = new StringType(recordSource.getName());
}
break;
case CHANNEL_ZONE2_SOURCE:
RotelSource sourceZone2 = this.sourceZone2;
if (powerZone2 && sourceZone2 != null) {
state = new StringType(sourceZone2.getName());
}
break;
case CHANNEL_ZONE3_SOURCE:
RotelSource sourceZone3 = this.sourceZone3;
if (powerZone3 && sourceZone3 != null) {
state = new StringType(sourceZone3.getName());
}
break;
case CHANNEL_ZONE4_SOURCE:
RotelSource sourceZone4 = this.sourceZone4;
if (powerZone4 && sourceZone4 != null) {
state = new StringType(sourceZone4.getName());
}
break;
case CHANNEL_DSP:
case CHANNEL_MAIN_DSP:
if (isPowerOn()) {
state = new StringType(dsp.getName());
}
break;
case CHANNEL_VOLUME:
case CHANNEL_MAIN_VOLUME:
if (isPowerOn()) {
long volumePct = Math.round((double) (volume - minVolume) / (double) (maxVolume - minVolume) * 100.0);
state = new PercentType(BigDecimal.valueOf(volumePct));
}
break;
case CHANNEL_MAIN_VOLUME_UP_DOWN:
if (isPowerOn()) {
state = new DecimalType(volume);
}
break;
case CHANNEL_ZONE2_VOLUME:
if (powerZone2 && !fixedVolumeZone2) {
long volumePct = Math.round((double) (volumeZone2 - minVolume) / (double) (maxVolume - minVolume) * 100.0);
state = new PercentType(BigDecimal.valueOf(volumePct));
}
break;
case CHANNEL_ZONE2_VOLUME_UP_DOWN:
if (powerZone2 && !fixedVolumeZone2) {
state = new DecimalType(volumeZone2);
}
break;
case CHANNEL_ZONE3_VOLUME:
if (powerZone3 && !fixedVolumeZone3) {
long volumePct = Math.round((double) (volumeZone3 - minVolume) / (double) (maxVolume - minVolume) * 100.0);
state = new PercentType(BigDecimal.valueOf(volumePct));
}
break;
case CHANNEL_ZONE4_VOLUME:
if (powerZone4 && !fixedVolumeZone4) {
long volumePct = Math.round((double) (volumeZone4 - minVolume) / (double) (maxVolume - minVolume) * 100.0);
state = new PercentType(BigDecimal.valueOf(volumePct));
}
break;
case CHANNEL_MUTE:
case CHANNEL_MAIN_MUTE:
if (isPowerOn()) {
state = mute ? OnOffType.ON : OnOffType.OFF;
}
break;
case CHANNEL_ZONE2_MUTE:
if (powerZone2) {
state = muteZone2 ? OnOffType.ON : OnOffType.OFF;
}
break;
case CHANNEL_ZONE3_MUTE:
if (powerZone3) {
state = muteZone3 ? OnOffType.ON : OnOffType.OFF;
}
break;
case CHANNEL_ZONE4_MUTE:
if (powerZone4) {
state = muteZone4 ? OnOffType.ON : OnOffType.OFF;
}
break;
case CHANNEL_BASS:
case CHANNEL_MAIN_BASS:
if (isPowerOn()) {
state = new DecimalType(bass);
}
break;
case CHANNEL_TREBLE:
case CHANNEL_MAIN_TREBLE:
if (isPowerOn()) {
state = new DecimalType(treble);
}
break;
case CHANNEL_TRACK:
if (track > 0 && isPowerOn()) {
state = new DecimalType(track);
}
break;
case CHANNEL_PLAY_CONTROL:
if (isPowerOn()) {
switch(playStatus) {
case PLAYING:
state = PlayPauseType.PLAY;
break;
case PAUSED:
case STOPPED:
state = PlayPauseType.PAUSE;
break;
}
}
break;
case CHANNEL_FREQUENCY:
if (frequency > 0.0 && isPowerOn()) {
state = new DecimalType(frequency);
}
break;
case CHANNEL_LINE1:
state = new StringType(frontPanelLine1);
break;
case CHANNEL_LINE2:
state = new StringType(frontPanelLine2);
break;
case CHANNEL_BRIGHTNESS:
if (isPowerOn() && connector.getModel().hasDimmerControl()) {
long dimmerPct = Math.round((double) (brightness - connector.getModel().getDimmerLevelMin()) / (double) (connector.getModel().getDimmerLevelMax() - connector.getModel().getDimmerLevelMin()) * 100.0);
state = new PercentType(BigDecimal.valueOf(dimmerPct));
}
break;
default:
break;
}
updateState(channel, state);
}
use of org.openhab.binding.rotel.internal.communication.RotelSource in project openhab-addons by openhab.
the class RotelHandler method initialize.
@Override
public void initialize() {
logger.debug("Start initializing handler for thing {}", getThing().getUID());
RotelModel rotelModel;
switch(getThing().getThingTypeUID().getId()) {
case THING_TYPE_ID_RSP1066:
rotelModel = RotelModel.RSP1066;
break;
case THING_TYPE_ID_RSP1068:
rotelModel = RotelModel.RSP1068;
break;
case THING_TYPE_ID_RSP1069:
rotelModel = RotelModel.RSP1069;
break;
case THING_TYPE_ID_RSP1098:
rotelModel = RotelModel.RSP1098;
break;
case THING_TYPE_ID_RSP1570:
rotelModel = RotelModel.RSP1570;
break;
case THING_TYPE_ID_RSP1572:
rotelModel = RotelModel.RSP1572;
break;
case THING_TYPE_ID_RSX1055:
rotelModel = RotelModel.RSX1055;
break;
case THING_TYPE_ID_RSX1056:
rotelModel = RotelModel.RSX1056;
break;
case THING_TYPE_ID_RSX1057:
rotelModel = RotelModel.RSX1057;
break;
case THING_TYPE_ID_RSX1058:
rotelModel = RotelModel.RSX1058;
break;
case THING_TYPE_ID_RSX1065:
rotelModel = RotelModel.RSX1065;
break;
case THING_TYPE_ID_RSX1067:
rotelModel = RotelModel.RSX1067;
break;
case THING_TYPE_ID_RSX1550:
rotelModel = RotelModel.RSX1550;
break;
case THING_TYPE_ID_RSX1560:
rotelModel = RotelModel.RSX1560;
break;
case THING_TYPE_ID_RSX1562:
rotelModel = RotelModel.RSX1562;
break;
case THING_TYPE_ID_A11:
rotelModel = RotelModel.A11;
break;
case THING_TYPE_ID_A12:
rotelModel = RotelModel.A12;
break;
case THING_TYPE_ID_A14:
rotelModel = RotelModel.A14;
break;
case THING_TYPE_ID_CD11:
rotelModel = RotelModel.CD11;
break;
case THING_TYPE_ID_CD14:
rotelModel = RotelModel.CD14;
break;
case THING_TYPE_ID_RA11:
rotelModel = RotelModel.RA11;
break;
case THING_TYPE_ID_RA12:
rotelModel = RotelModel.RA12;
break;
case THING_TYPE_ID_RA1570:
rotelModel = RotelModel.RA1570;
break;
case THING_TYPE_ID_RA1572:
rotelModel = RotelModel.RA1572;
break;
case THING_TYPE_ID_RA1592:
rotelModel = RotelModel.RA1592;
break;
case THING_TYPE_ID_RAP1580:
rotelModel = RotelModel.RAP1580;
break;
case THING_TYPE_ID_RC1570:
rotelModel = RotelModel.RC1570;
break;
case THING_TYPE_ID_RC1572:
rotelModel = RotelModel.RC1572;
break;
case THING_TYPE_ID_RC1590:
rotelModel = RotelModel.RC1590;
break;
case THING_TYPE_ID_RCD1570:
rotelModel = RotelModel.RCD1570;
break;
case THING_TYPE_ID_RCD1572:
rotelModel = RotelModel.RCD1572;
break;
case THING_TYPE_ID_RCX1500:
rotelModel = RotelModel.RCX1500;
break;
case THING_TYPE_ID_RDD1580:
rotelModel = RotelModel.RDD1580;
break;
case THING_TYPE_ID_RDG1520:
case THING_TYPE_ID_RT09:
rotelModel = RotelModel.RDG1520;
break;
case THING_TYPE_ID_RSP1576:
rotelModel = RotelModel.RSP1576;
break;
case THING_TYPE_ID_RSP1582:
rotelModel = RotelModel.RSP1582;
break;
case THING_TYPE_ID_RT11:
rotelModel = RotelModel.RT11;
break;
case THING_TYPE_ID_RT1570:
rotelModel = RotelModel.RT1570;
break;
case THING_TYPE_ID_T11:
rotelModel = RotelModel.T11;
break;
case THING_TYPE_ID_T14:
rotelModel = RotelModel.T14;
break;
default:
rotelModel = DEFAULT_MODEL;
break;
}
RotelThingConfiguration config = getConfigAs(RotelThingConfiguration.class);
RotelProtocol rotelProtocol = RotelProtocol.HEX;
if (config.protocol != null && !config.protocol.isEmpty()) {
try {
rotelProtocol = RotelProtocol.getFromName(config.protocol);
} catch (RotelException e) {
}
} else {
Map<String, String> properties = editProperties();
String property = properties.get(RotelBindingConstants.PROPERTY_PROTOCOL);
if (property != null && !property.isEmpty()) {
try {
rotelProtocol = RotelProtocol.getFromName(property);
} catch (RotelException e) {
}
}
}
logger.debug("rotelProtocol {}", rotelProtocol.getName());
Map<RotelSource, String> sourcesCustomLabels = new HashMap<>();
Map<RotelSource, String> sourcesLabels = new HashMap<>();
String readerThreadName = "OH-binding-" + getThing().getUID().getAsString();
connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels, readerThreadName);
if (rotelModel.hasVolumeControl()) {
maxVolume = rotelModel.getVolumeMax();
if (!rotelModel.hasDirectVolumeControl()) {
logger.info("Set minValue to {} and maxValue to {} for your sitemap widget attached to your volume item.", minVolume, maxVolume);
}
}
if (rotelModel.hasToneControl()) {
maxToneLevel = rotelModel.getToneLevelMax();
minToneLevel = -maxToneLevel;
logger.info("Set minValue to {} and maxValue to {} for your sitemap widget attached to your bass or treble item.", minToneLevel, maxToneLevel);
}
// Check configuration settings
String configError = null;
if ((config.serialPort == null || config.serialPort.isEmpty()) && (config.host == null || config.host.isEmpty())) {
configError = "@text/offline.config-error-unknown-serialport-and-host";
} else if (config.host == null || config.host.isEmpty()) {
if (config.serialPort.toLowerCase().startsWith("rfc2217")) {
configError = "@text/offline.config-error-invalid-serial-over-ip";
}
} else {
if (config.port == null) {
configError = "@text/offline.config-error-unknown-port";
} else if (config.port <= 0) {
configError = "@text/offline.config-error-invalid-port";
}
}
if (configError != null) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, configError);
} else {
for (RotelSource src : rotelModel.getSources()) {
// Consider custom input labels
String label = null;
switch(src.getName()) {
case "CD":
label = config.inputLabelCd;
break;
case "TUNER":
label = config.inputLabelTuner;
break;
case "TAPE":
label = config.inputLabelTape;
break;
case "PHONO":
label = config.inputLabelPhono;
break;
case "VIDEO1":
label = config.inputLabelVideo1;
break;
case "VIDEO2":
label = config.inputLabelVideo2;
break;
case "VIDEO3":
label = config.inputLabelVideo3;
break;
case "VIDEO4":
label = config.inputLabelVideo4;
break;
case "VIDEO5":
label = config.inputLabelVideo5;
break;
case "VIDEO6":
label = config.inputLabelVideo6;
break;
case "USB":
label = config.inputLabelUsb;
break;
case "MULTI":
label = config.inputLabelMulti;
break;
default:
break;
}
if (label != null && !label.isEmpty()) {
sourcesCustomLabels.put(src, label);
}
sourcesLabels.put(src, (label == null || label.isEmpty()) ? src.getLabel() : label);
}
if (USE_SIMULATED_DEVICE) {
connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels, readerThreadName);
} else if (config.serialPort != null) {
connector = new RotelSerialConnector(serialPortManager, config.serialPort, rotelModel, rotelProtocol, sourcesLabels, readerThreadName);
} else {
connector = new RotelIpConnector(config.host, config.port, rotelModel, rotelProtocol, sourcesLabels, readerThreadName);
}
if (rotelModel.hasSourceControl()) {
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_SOURCE), getStateOptions(rotelModel.getSources(), sourcesCustomLabels));
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_MAIN_SOURCE), getStateOptions(rotelModel.getSources(), sourcesCustomLabels));
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_MAIN_RECORD_SOURCE), getStateOptions(rotelModel.getRecordSources(), sourcesCustomLabels));
}
if (rotelModel.hasZone2SourceControl()) {
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_ZONE2_SOURCE), getStateOptions(rotelModel.getZone2Sources(), sourcesCustomLabels));
}
if (rotelModel.hasZone3SourceControl()) {
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_ZONE3_SOURCE), getStateOptions(rotelModel.getZone3Sources(), sourcesCustomLabels));
}
if (rotelModel.hasZone4SourceControl()) {
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_ZONE4_SOURCE), getStateOptions(rotelModel.getZone4Sources(), sourcesCustomLabels));
}
if (rotelModel.hasDspControl()) {
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_DSP), rotelModel.getDspStateOptions());
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_MAIN_DSP), rotelModel.getDspStateOptions());
}
updateStatus(ThingStatus.UNKNOWN);
scheduleReconnectJob();
}
logger.debug("Finished initializing!");
}
use of org.openhab.binding.rotel.internal.communication.RotelSource in project openhab-addons by openhab.
the class RotelHandler method getStateOptions.
public List<StateOption> getStateOptions(List<RotelSource> list, Map<RotelSource, String> sourcesLabels) {
List<StateOption> options = new ArrayList<>();
for (RotelSource item : list) {
String label = sourcesLabels.get(item);
options.add(new StateOption(item.getName(), label == null ? ("@text/source." + item.getName()) : label));
}
return options;
}
Aggregations