[monopriceaudio] Fix compiler warnings and code improvements (#16991)

* Fix compiler warnings and code improvements

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2024-07-15 23:42:28 -05:00 committed by GitHub
parent f9c8d049b0
commit 4946aa9163
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 232 additions and 269 deletions

View File

@ -12,11 +12,13 @@
*/ */
package org.openhab.binding.monopriceaudio.internal.communication; package org.openhab.binding.monopriceaudio.internal.communication;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.IntStream;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.monopriceaudio.internal.configuration.MonopriceAudioThingConfiguration; import org.openhab.binding.monopriceaudio.internal.configuration.MonopriceAudioThingConfiguration;
@ -82,7 +84,7 @@ public enum AmplifierModel {
2, false, List.of("1", "2", "3", "4", "5", "6")) { 2, false, List.of("1", "2", "3", "4", "5", "6")) {
@Override @Override
public MonopriceAudioZoneDTO getZoneData(String newZoneData) { public MonopriceAudioZoneDTO getZoneData(String newZoneData) {
MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO(); final MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO();
Matcher matcher = MONOPRICE70_PATTERN.matcher(newZoneData); Matcher matcher = MONOPRICE70_PATTERN.matcher(newZoneData);
if (matcher.find()) { if (matcher.find()) {
@ -127,8 +129,8 @@ public enum AmplifierModel {
false, List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16")) { false, List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16")) {
@Override @Override
public MonopriceAudioZoneDTO getZoneData(String newZoneData) { public MonopriceAudioZoneDTO getZoneData(String newZoneData) {
MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO(); final MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO();
Matcher matcher = XANTECH_PATTERN.matcher(newZoneData); final Matcher matcher = XANTECH_PATTERN.matcher(newZoneData);
if (matcher.find()) { if (matcher.find()) {
zoneData.setZone(matcher.group(1)); zoneData.setZone(matcher.group(1));
@ -156,8 +158,8 @@ public enum AmplifierModel {
// Used by 10761/DAX66 and DAX88 // Used by 10761/DAX66 and DAX88
private static MonopriceAudioZoneDTO getMonopriceZoneData(String newZoneData) { private static MonopriceAudioZoneDTO getMonopriceZoneData(String newZoneData) {
MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO(); final MonopriceAudioZoneDTO zoneData = new MonopriceAudioZoneDTO();
Matcher matcher = MONOPRICE_PATTERN.matcher(newZoneData); final Matcher matcher = MONOPRICE_PATTERN.matcher(newZoneData);
if (matcher.find()) { if (matcher.find()) {
zoneData.setZone(matcher.group(1)); zoneData.setZone(matcher.group(1));
@ -191,31 +193,31 @@ public enum AmplifierModel {
private static final Pattern XANTECH_PATTERN = Pattern.compile( private static final Pattern XANTECH_PATTERN = Pattern.compile(
"^#(\\d{1,2})ZS PR(\\d{1}) SS(\\d{1}) VO(\\d{1,2}) MU(\\d{1}) TR(\\d{1,2}) BS(\\d{1,2}) BA(\\d{1,2}) LS(\\d{1}) PS(\\d{1})+"); "^#(\\d{1,2})ZS PR(\\d{1}) SS(\\d{1}) VO(\\d{1,2}) MU(\\d{1}) TR(\\d{1,2}) BS(\\d{1,2}) BA(\\d{1,2}) LS(\\d{1}) PS(\\d{1})+");
private String cmdPrefix; private final String cmdPrefix;
private String cmdSuffix; private final String cmdSuffix;
private String queryPrefix; private final String queryPrefix;
private String querySuffix; private final String querySuffix;
private String respPrefix; private final String respPrefix;
private String powerCmd; private final String powerCmd;
private String sourceCmd; private final String sourceCmd;
private String volumeCmd; private final String volumeCmd;
private String muteCmd; private final String muteCmd;
private String trebleCmd; private final String trebleCmd;
private String bassCmd; private final String bassCmd;
private String balanceCmd; private final String balanceCmd;
private String dndCmd; private final String dndCmd;
private int maxVol; private final int maxVol;
private int minTone; private final int minTone;
private int maxTone; private final int maxTone;
private int toneOffset; private final int toneOffset;
private int minBal; private final int minBal;
private int maxBal; private final int maxBal;
private int balOffset; private final int balOffset;
private int maxZones; private final int maxZones;
private int numSources; private final int numSources;
private boolean padNumbers; private final boolean padNumbers;
private List<String> zoneIds; private final List<String> zoneIds;
private Map<String, String> zoneIdMap = new HashMap<>(); private final Map<String, String> zoneIdMap;
private static final String ON_STR = "1"; private static final String ON_STR = "1";
private static final String OFF_STR = "0"; private static final String OFF_STR = "0";
@ -256,11 +258,10 @@ public enum AmplifierModel {
this.padNumbers = padNumbers; this.padNumbers = padNumbers;
this.zoneIds = zoneIds; this.zoneIds = zoneIds;
int i = 1; // Build a map between the amp's physical zone IDs and the thing's logical zone names
for (String zoneId : zoneIds) { final Map<String, String> zoneIdMap = new HashMap<>();
zoneIdMap.put(zoneId, "zone" + i); IntStream.range(0, zoneIds.size()).forEach(i -> zoneIdMap.put(zoneIds.get(i), "zone" + (i + 1)));
i++; this.zoneIdMap = Collections.unmodifiableMap(zoneIdMap);
}
} }
public abstract MonopriceAudioZoneDTO getZoneData(String newZoneData); public abstract MonopriceAudioZoneDTO getZoneData(String newZoneData);
@ -378,26 +379,14 @@ public enum AmplifierModel {
} }
public String getFormattedValue(Integer value) { public String getFormattedValue(Integer value) {
if (padNumbers) { return padNumbers ? String.format("%02d", value) : value.toString();
return String.format("%02d", value);
} else {
return value.toString();
}
} }
public String getOnStr() { public String getOnStr() {
if (padNumbers) { return padNumbers ? ON_STR_PAD : ON_STR;
return ON_STR_PAD;
} else {
return ON_STR;
}
} }
public String getOffStr() { public String getOffStr() {
if (padNumbers) { return padNumbers ? OFF_STR_PAD : OFF_STR;
return OFF_STR_PAD;
} else {
return OFF_STR;
}
} }
} }

View File

@ -52,7 +52,7 @@ public abstract class MonopriceAudioConnector {
private boolean connected; private boolean connected;
private boolean pingResponseOnly; private boolean pingResponseOnly;
private @Nullable AmplifierModel amp; protected AmplifierModel amp = AmplifierModel.MONOPRICE;
private @Nullable Thread readerThread; private @Nullable Thread readerThread;
@ -77,15 +77,6 @@ public abstract class MonopriceAudioConnector {
this.pingResponseOnly = false; this.pingResponseOnly = false;
} }
/**
* Set the AmplifierModel
*
* @param amp the AmplifierModel being used
*/
protected void setAmplifierModel(AmplifierModel amp) {
this.amp = amp;
}
/** /**
* Set the thread that handles the feedback messages * Set the thread that handles the feedback messages
* *
@ -177,7 +168,7 @@ public abstract class MonopriceAudioConnector {
public void sendPing() throws MonopriceAudioException { public void sendPing() throws MonopriceAudioException {
pingResponseOnly = true; pingResponseOnly = true;
// poll zone 1 status only to see if the amp responds // poll zone 1 status only to see if the amp responds
queryZone(amp.getZoneIds().get(0)); queryZone(amp.getZoneIds().iterator().next());
} }
/** /**

View File

@ -1,50 +0,0 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.monopriceaudio.internal.communication;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.monopriceaudio.internal.MonopriceAudioException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class to create a default MonopriceAudioConnector before initialization is complete.
*
* @author Laurent Garnier - Initial contribution
* @author Michael Lobstein - Adapted for the MonopriceAudio binding
*/
@NonNullByDefault
public class MonopriceAudioDefaultConnector extends MonopriceAudioConnector {
private final Logger logger = LoggerFactory.getLogger(MonopriceAudioDefaultConnector.class);
@Override
public void open() throws MonopriceAudioException {
logger.warn(
"MonopriceAudio binding incorrectly configured. Please configure for Serial or IP over serial connection");
setConnected(false);
}
@Override
public void close() {
setConnected(false);
}
@Override
public void sendCommand(@Nullable String zone, String cmd, @Nullable Integer value) {
logger.warn(
"MonopriceAudio binding incorrectly configured. Please configure for Serial or IP over serial connection");
setConnected(false);
}
}

View File

@ -54,7 +54,16 @@ public class MonopriceAudioIpConnector extends MonopriceAudioConnector {
this.address = address; this.address = address;
this.port = port; this.port = port;
this.uid = uid; this.uid = uid;
setAmplifierModel(amp); super.amp = amp;
}
/**
* Default constructor for temporary connector object that gets replaced during initialize()
*/
public MonopriceAudioIpConnector() {
this.address = "";
this.port = -1;
this.uid = "";
} }
@Override @Override

View File

@ -58,7 +58,7 @@ public class MonopriceAudioSerialConnector extends MonopriceAudioConnector {
this.serialPortManager = serialPortManager; this.serialPortManager = serialPortManager;
this.serialPortName = serialPortName; this.serialPortName = serialPortName;
this.uid = uid; this.uid = uid;
setAmplifierModel(amp); super.amp = amp;
} }
@Override @Override

View File

@ -32,7 +32,6 @@ import org.openhab.binding.monopriceaudio.internal.MonopriceAudioException;
import org.openhab.binding.monopriceaudio.internal.MonopriceAudioStateDescriptionOptionProvider; import org.openhab.binding.monopriceaudio.internal.MonopriceAudioStateDescriptionOptionProvider;
import org.openhab.binding.monopriceaudio.internal.communication.AmplifierModel; import org.openhab.binding.monopriceaudio.internal.communication.AmplifierModel;
import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioConnector; import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioConnector;
import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioDefaultConnector;
import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioIpConnector; import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioIpConnector;
import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioMessageEvent; import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioMessageEvent;
import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioMessageEventListener; import org.openhab.binding.monopriceaudio.internal.communication.MonopriceAudioMessageEventListener;
@ -87,7 +86,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
private @Nullable ScheduledFuture<?> reconnectJob; private @Nullable ScheduledFuture<?> reconnectJob;
private @Nullable ScheduledFuture<?> pollingJob; private @Nullable ScheduledFuture<?> pollingJob;
private MonopriceAudioConnector connector = new MonopriceAudioDefaultConnector(); private MonopriceAudioConnector connector = new MonopriceAudioIpConnector();
private Map<String, MonopriceAudioZoneDTO> zoneDataMap = Map.of(ZONE, new MonopriceAudioZoneDTO()); private Map<String, MonopriceAudioZoneDTO> zoneDataMap = Map.of(ZONE, new MonopriceAudioZoneDTO());
private Set<String> ignoreZones = new HashSet<>(); private Set<String> ignoreZones = new HashSet<>();
@ -214,11 +213,11 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
@Override @Override
public void handleCommand(ChannelUID channelUID, Command command) { public void handleCommand(ChannelUID channelUID, Command command) {
String channel = channelUID.getId(); final String channel = channelUID.getId();
String[] channelSplit = channel.split(CHANNEL_DELIMIT); final String[] channelSplit = channel.split(CHANNEL_DELIMIT);
String channelType = channelSplit[1]; final String channelType = channelSplit[1];
String zoneName = channelSplit[0]; final String zoneName = channelSplit[0];
String zoneId = amp.getZoneIdFromZoneName(zoneName); final String zoneId = amp.getZoneIdFromZoneName(zoneName);
if (getThing().getStatus() != ThingStatus.ONLINE) { if (getThing().getStatus() != ThingStatus.ONLINE) {
logger.debug("Thing is not ONLINE; command {} from channel {} is ignored", command, channel); logger.debug("Thing is not ONLINE; command {} from channel {} is ignored", command, channel);
@ -237,14 +236,19 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
return; return;
} }
Stream<String> zoneStream = amp.getZoneIds().stream().limit(numZones);
try { try {
if (!"all".equals(zoneName)) {
MonopriceAudioZoneDTO dto = zoneDataMap.get(zoneId);
if (dto == null) {
logger.debug("no zoneData for zoneId: {}", zoneId);
return;
}
switch (channelType) { switch (channelType) {
case CHANNEL_TYPE_POWER: case CHANNEL_TYPE_POWER:
if (command instanceof OnOffType) { if (command instanceof OnOffType) {
connector.sendCommand(zoneId, amp.getPowerCmd(), command == OnOffType.ON ? ONE : ZERO); connector.sendCommand(zoneId, amp.getPowerCmd(), command == OnOffType.ON ? ONE : ZERO);
zoneDataMap.get(zoneId) dto.setPower(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr());
.setPower(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr());
} }
break; break;
case CHANNEL_TYPE_SOURCE: case CHANNEL_TYPE_SOURCE:
@ -253,7 +257,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
if (value >= ONE && value <= amp.getNumSources()) { if (value >= ONE && value <= amp.getNumSources()) {
logger.debug("Got source command {} zone {}", value, zoneId); logger.debug("Got source command {} zone {}", value, zoneId);
connector.sendCommand(zoneId, amp.getSourceCmd(), value); connector.sendCommand(zoneId, amp.getSourceCmd(), value);
zoneDataMap.get(zoneId).setSource(amp.getFormattedValue(value)); dto.setSource(amp.getFormattedValue(value));
} }
} }
break; break;
@ -264,13 +268,13 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
+ MIN_VOLUME; + MIN_VOLUME;
logger.debug("Got volume command {} zone {}", value, zoneId); logger.debug("Got volume command {} zone {}", value, zoneId);
connector.sendCommand(zoneId, amp.getVolumeCmd(), value); connector.sendCommand(zoneId, amp.getVolumeCmd(), value);
zoneDataMap.get(zoneId).setVolume(value); dto.setVolume(value);
} }
break; break;
case CHANNEL_TYPE_MUTE: case CHANNEL_TYPE_MUTE:
if (command instanceof OnOffType) { if (command instanceof OnOffType) {
connector.sendCommand(zoneId, amp.getMuteCmd(), command == OnOffType.ON ? ONE : ZERO); connector.sendCommand(zoneId, amp.getMuteCmd(), command == OnOffType.ON ? ONE : ZERO);
zoneDataMap.get(zoneId).setMute(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr()); dto.setMute(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr());
} }
break; break;
case CHANNEL_TYPE_TREBLE: case CHANNEL_TYPE_TREBLE:
@ -279,7 +283,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
if (value >= amp.getMinTone() && value <= amp.getMaxTone()) { if (value >= amp.getMinTone() && value <= amp.getMaxTone()) {
logger.debug("Got treble command {} zone {}", value, zoneId); logger.debug("Got treble command {} zone {}", value, zoneId);
connector.sendCommand(zoneId, amp.getTrebleCmd(), value + amp.getToneOffset()); connector.sendCommand(zoneId, amp.getTrebleCmd(), value + amp.getToneOffset());
zoneDataMap.get(zoneId).setTreble(value + amp.getToneOffset()); dto.setTreble(value + amp.getToneOffset());
} }
} }
break; break;
@ -289,7 +293,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
if (value >= amp.getMinTone() && value <= amp.getMaxTone()) { if (value >= amp.getMinTone() && value <= amp.getMaxTone()) {
logger.debug("Got bass command {} zone {}", value, zoneId); logger.debug("Got bass command {} zone {}", value, zoneId);
connector.sendCommand(zoneId, amp.getBassCmd(), value + amp.getToneOffset()); connector.sendCommand(zoneId, amp.getBassCmd(), value + amp.getToneOffset());
zoneDataMap.get(zoneId).setBass(value + amp.getToneOffset()); dto.setBass(value + amp.getToneOffset());
} }
} }
break; break;
@ -299,32 +303,45 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
if (value >= amp.getMinBal() && value <= amp.getMaxBal()) { if (value >= amp.getMinBal() && value <= amp.getMaxBal()) {
logger.debug("Got balance command {} zone {}", value, zoneId); logger.debug("Got balance command {} zone {}", value, zoneId);
connector.sendCommand(zoneId, amp.getBalanceCmd(), value + amp.getBalOffset()); connector.sendCommand(zoneId, amp.getBalanceCmd(), value + amp.getBalOffset());
zoneDataMap.get(zoneId).setBalance(value + amp.getBalOffset()); dto.setBalance(value + amp.getBalOffset());
} }
} }
break; break;
case CHANNEL_TYPE_DND: case CHANNEL_TYPE_DND:
if (command instanceof OnOffType) { if (command instanceof OnOffType) {
connector.sendCommand(zoneId, amp.getDndCmd(), command == OnOffType.ON ? ONE : ZERO); connector.sendCommand(zoneId, amp.getDndCmd(), command == OnOffType.ON ? ONE : ZERO);
zoneDataMap.get(zoneId).setDnd(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr()); dto.setDnd(command == OnOffType.ON ? amp.getOnStr() : amp.getOffStr());
} }
break; break;
default:
success = false;
logger.debug("Command {} from channel {} failed: unexpected command", command, channel);
break;
}
} else {
Stream<String> zoneStream = amp.getZoneIds().stream().limit(numZones);
switch (channelType) {
case CHANNEL_TYPE_ALLPOWER: case CHANNEL_TYPE_ALLPOWER:
if (command instanceof OnOffType) { if (command instanceof OnOffType) {
final int cmd = command == OnOffType.ON ? ONE : ZERO; final int cmd = command == OnOffType.ON ? ONE : ZERO;
zoneStream.forEach((streamZoneId) -> { zoneStream.forEach((streamZoneId) -> {
if (command == OnOffType.OFF || !ignoreZones.contains(amp.getZoneName(streamZoneId))) { if (command == OnOffType.OFF
|| !ignoreZones.contains(amp.getZoneName(streamZoneId))) {
try { try {
MonopriceAudioZoneDTO streamDto = zoneDataMap.get(streamZoneId);
if (streamDto != null) {
connector.sendCommand(streamZoneId, amp.getPowerCmd(), cmd); connector.sendCommand(streamZoneId, amp.getPowerCmd(), cmd);
zoneDataMap.get(streamZoneId).setPower(amp.getFormattedValue(cmd)); streamDto.setPower(amp.getFormattedValue(cmd));
updateChannelState(streamZoneId, CHANNEL_TYPE_POWER); updateChannelState(streamZoneId, CHANNEL_TYPE_POWER);
if (command == OnOffType.ON) { if (command == OnOffType.ON) {
// reset the volume of each zone to allVolume // reset the volume of each zone to allVolume
connector.sendCommand(streamZoneId, amp.getVolumeCmd(), allVolume); connector.sendCommand(streamZoneId, amp.getVolumeCmd(), allVolume);
zoneDataMap.get(streamZoneId).setVolume(allVolume); streamDto.setVolume(allVolume);
updateChannelState(streamZoneId, CHANNEL_TYPE_VOLUME); updateChannelState(streamZoneId, CHANNEL_TYPE_VOLUME);
} }
}
} catch (MonopriceAudioException e) { } catch (MonopriceAudioException e) {
logger.debug("Error Turning All Zones On: {}", e.getMessage()); logger.debug("Error Turning All Zones On: {}", e.getMessage());
} }
@ -340,12 +357,14 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
zoneStream.forEach((streamZoneId) -> { zoneStream.forEach((streamZoneId) -> {
if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) { if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) {
try { try {
MonopriceAudioZoneDTO streamDto = zoneDataMap.get(streamZoneId);
if (streamDto != null) {
connector.sendCommand(streamZoneId, amp.getSourceCmd(), value); connector.sendCommand(streamZoneId, amp.getSourceCmd(), value);
if (zoneDataMap.get(streamZoneId).isPowerOn() if (streamDto.isPowerOn() && !streamDto.isMuted()) {
&& !zoneDataMap.get(streamZoneId).isMuted()) { streamDto.setSource(amp.getFormattedValue(value));
zoneDataMap.get(streamZoneId).setSource(amp.getFormattedValue(value));
updateChannelState(streamZoneId, CHANNEL_TYPE_SOURCE); updateChannelState(streamZoneId, CHANNEL_TYPE_SOURCE);
} }
}
} catch (MonopriceAudioException e) { } catch (MonopriceAudioException e) {
logger.debug("Error Setting Source for All Zones: {}", e.getMessage()); logger.debug("Error Setting Source for All Zones: {}", e.getMessage());
} }
@ -362,12 +381,14 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
zoneStream.forEach((streamZoneId) -> { zoneStream.forEach((streamZoneId) -> {
if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) { if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) {
try { try {
MonopriceAudioZoneDTO streamDto = zoneDataMap.get(streamZoneId);
if (streamDto != null) {
connector.sendCommand(streamZoneId, amp.getVolumeCmd(), allVolume); connector.sendCommand(streamZoneId, amp.getVolumeCmd(), allVolume);
if (zoneDataMap.get(streamZoneId).isPowerOn() if (streamDto.isPowerOn() && !streamDto.isMuted()) {
&& !zoneDataMap.get(streamZoneId).isMuted()) { streamDto.setVolume(allVolume);
zoneDataMap.get(streamZoneId).setVolume(allVolume);
updateChannelState(streamZoneId, CHANNEL_TYPE_VOLUME); updateChannelState(streamZoneId, CHANNEL_TYPE_VOLUME);
} }
}
} catch (MonopriceAudioException e) { } catch (MonopriceAudioException e) {
logger.debug("Error Setting Volume for All Zones: {}", e.getMessage()); logger.debug("Error Setting Volume for All Zones: {}", e.getMessage());
} }
@ -381,11 +402,14 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
zoneStream.forEach((streamZoneId) -> { zoneStream.forEach((streamZoneId) -> {
if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) { if (!ignoreZones.contains(amp.getZoneName(streamZoneId))) {
try { try {
MonopriceAudioZoneDTO streamDto = zoneDataMap.get(streamZoneId);
if (streamDto != null) {
connector.sendCommand(streamZoneId, amp.getMuteCmd(), cmd); connector.sendCommand(streamZoneId, amp.getMuteCmd(), cmd);
if (zoneDataMap.get(streamZoneId).isPowerOn()) { if (streamDto.isPowerOn()) {
zoneDataMap.get(streamZoneId).setMute(amp.getFormattedValue(cmd)); streamDto.setMute(amp.getFormattedValue(cmd));
updateChannelState(streamZoneId, CHANNEL_TYPE_MUTE); updateChannelState(streamZoneId, CHANNEL_TYPE_MUTE);
} }
}
} catch (MonopriceAudioException e) { } catch (MonopriceAudioException e) {
logger.debug("Error Setting Mute for All Zones: {}", e.getMessage()); logger.debug("Error Setting Mute for All Zones: {}", e.getMessage());
} }
@ -395,9 +419,10 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
break; break;
default: default:
success = false; success = false;
logger.debug("Command {} from channel {} failed: unexpected command", command, channel); logger.debug("Command {} from all channel {} failed: unexpected command", command, channel);
break; break;
} }
}
if (success) { if (success) {
logger.trace("Command {} from channel {} succeeded", command, channel); logger.trace("Command {} from channel {} succeeded", command, channel);
@ -442,9 +467,8 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
@Override @Override
public void onNewMessageEvent(MonopriceAudioMessageEvent evt) { public void onNewMessageEvent(MonopriceAudioMessageEvent evt) {
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
String key = evt.getKey();
switch (key) { switch (evt.getKey()) {
case MonopriceAudioConnector.KEY_ZONE_UPDATE: case MonopriceAudioConnector.KEY_ZONE_UPDATE:
MonopriceAudioZoneDTO newZoneData = amp.getZoneData(evt.getValue()); MonopriceAudioZoneDTO newZoneData = amp.getZoneData(evt.getValue());
MonopriceAudioZoneDTO zoneData = zoneDataMap.get(newZoneData.getZone()); MonopriceAudioZoneDTO zoneData = zoneDataMap.get(newZoneData.getZone());
@ -455,7 +479,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
processZoneUpdate(zoneData, newZoneData); processZoneUpdate(zoneData, newZoneData);
} }
} else { } else {
logger.debug("invalid event: {} for key: {} or zone data null", evt.getValue(), key); logger.debug("invalid event: {} for key: {} or zone data null", evt.getValue(), evt.getKey());
} }
break; break;
@ -464,7 +488,7 @@ public class MonopriceAudioHandler extends BaseThingHandler implements Monoprice
break; break;
default: default:
logger.debug("onNewMessageEvent: unhandled key {}", key); logger.debug("onNewMessageEvent: unhandled key {}", evt.getKey());
break; break;
} }
} }