Ignore NuvoNet events for sources not managed by openHAB (#13535)

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
This commit is contained in:
mlobstein 2022-10-15 03:27:37 -05:00 committed by GitHub
parent 6103c30830
commit 51054fe51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -224,6 +224,13 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
return; return;
} }
nuvoNetSrcMap.put("1", config.nuvoNetSrc1);
nuvoNetSrcMap.put("2", config.nuvoNetSrc2);
nuvoNetSrcMap.put("3", config.nuvoNetSrc3);
nuvoNetSrcMap.put("4", config.nuvoNetSrc4);
nuvoNetSrcMap.put("5", config.nuvoNetSrc5);
nuvoNetSrcMap.put("6", config.nuvoNetSrc6);
if (this.isMps4) { if (this.isMps4) {
logger.debug("Port set to {} configuring binding for MPS4 compatability", MPS4_PORT); logger.debug("Port set to {} configuring binding for MPS4 compatability", MPS4_PORT);
@ -234,13 +241,6 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
logger.debug("At least one source is configured as an openHAB NuvoNet source"); logger.debug("At least one source is configured as an openHAB NuvoNet source");
loadMenuConfiguration(config); loadMenuConfiguration(config);
nuvoNetSrcMap.put("1", config.nuvoNetSrc1);
nuvoNetSrcMap.put("2", config.nuvoNetSrc2);
nuvoNetSrcMap.put("3", config.nuvoNetSrc3);
nuvoNetSrcMap.put("4", config.nuvoNetSrc4);
nuvoNetSrcMap.put("5", config.nuvoNetSrc5);
nuvoNetSrcMap.put("6", config.nuvoNetSrc6);
favoriteMap.put("1", favoriteMap.put("1",
!config.favoritesSrc1.isEmpty() ? config.favoritesSrc1.split(COMMA) : new String[0]); !config.favoritesSrc1.isEmpty() ? config.favoritesSrc1.split(COMMA) : new String[0]);
favoriteMap.put("2", favoriteMap.put("2",
@ -762,72 +762,78 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} }
break; break;
case TYPE_MENU_ITEM_SELECTED: case TYPE_MENU_ITEM_SELECTED:
String[] updateDataSplit = updateData.split(COMMA); // ignore this update unless openHAB is handling this source
String zoneSource = updateDataSplit[0]; if (nuvoNetSrcMap.get(key).equals(2)) {
String menuId = updateDataSplit[1]; String[] updateDataSplit = updateData.split(COMMA);
int menuItemIdx = Integer.parseInt(updateDataSplit[2]) - 1; String zoneSource = updateDataSplit[0];
String menuId = updateDataSplit[1];
int menuItemIdx = Integer.parseInt(updateDataSplit[2]) - 1;
boolean exitMenu = false; boolean exitMenu = false;
if ("0xFFFFFFFF".equals(menuId)) { if ("0xFFFFFFFF".equals(menuId)) {
TopMenu topMenuItem = nuvoMenus.getSource().get(Integer.parseInt(key) - 1).getTopMenu() TopMenu topMenuItem = nuvoMenus.getSource().get(Integer.parseInt(key) - 1).getTopMenu()
.get(menuItemIdx); .get(menuItemIdx);
logger.debug("Top Menu item selected: Source: {} - Menu Item: {}", key, topMenuItem.getText()); logger.debug("Top Menu item selected: Source: {} - Menu Item: {}", key, topMenuItem.getText());
updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS, topMenuItem.getText()); updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS, topMenuItem.getText());
List<String> subMenuItems = topMenuItem.getItems(); List<String> subMenuItems = topMenuItem.getItems();
if (subMenuItems.isEmpty()) { if (subMenuItems.isEmpty()) {
exitMenu = true; exitMenu = true;
} else { } else {
// send submenu (maximum of 20 items) // send submenu (maximum of 20 items)
int subMenuSize = subMenuItems.size() < 20 ? subMenuItems.size() : 20; int subMenuSize = subMenuItems.size() < 20 ? subMenuItems.size() : 20;
try { try {
connector.sendCommand(zoneSource + "MENU" + (menuItemIdx + 11) + ",0,0," + subMenuSize connector.sendCommand(zoneSource + "MENU" + (menuItemIdx + 11) + ",0,0," + subMenuSize
+ ",0,0," + subMenuSize + ",\"" + topMenuItem.getText() + "\""); + ",0,0," + subMenuSize + ",\"" + topMenuItem.getText() + "\"");
Thread.sleep(SLEEP_BETWEEN_CMD_MS); Thread.sleep(SLEEP_BETWEEN_CMD_MS);
for (int i = 0; i < subMenuSize; i++) { for (int i = 0; i < subMenuSize; i++) {
connector.sendCommand( connector.sendCommand(
zoneSource + "MENUITEM" + (i + 1) + ",0,0,\"" + subMenuItems.get(i) + "\""); zoneSource + "MENUITEM" + (i + 1) + ",0,0,\"" + subMenuItems.get(i) + "\"");
}
} catch (NuvoException | InterruptedException e) {
logger.debug("Error sending sub menu for {}", zoneSource);
} }
} catch (NuvoException | InterruptedException e) {
logger.debug("Error sending sub menu for {}", zoneSource);
} }
} else {
// a sub menu item was selected
TopMenu topMenuItem = nuvoMenus.getSource().get(Integer.parseInt(key) - 1).getTopMenu()
.get(Integer.decode(menuId) - 11);
String subMenuItem = topMenuItem.getItems().get(menuItemIdx);
logger.debug("Sub Menu item selected: Source: {} - Menu Item: {}", key,
topMenuItem.getText() + "|" + subMenuItem);
updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS,
topMenuItem.getText() + "|" + subMenuItem);
exitMenu = true;
} }
} else {
// a sub menu item was selected
TopMenu topMenuItem = nuvoMenus.getSource().get(Integer.parseInt(key) - 1).getTopMenu()
.get(Integer.decode(menuId) - 11);
String subMenuItem = topMenuItem.getItems().get(menuItemIdx);
logger.debug("Sub Menu item selected: Source: {} - Menu Item: {}", key, if (exitMenu) {
topMenuItem.getText() + "|" + subMenuItem); try {
updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS, // tell the zone to exit the menu
topMenuItem.getText() + "|" + subMenuItem); connector.sendCommand(zoneSource + "MENU0,0,0,0,0,0,0,\"\"");
exitMenu = true; } catch (NuvoException e) {
} logger.debug("Error sending exit menu command for {}", zoneSource);
}
if (exitMenu) {
try {
// tell the zone to exit the menu
connector.sendCommand(zoneSource + "MENU0,0,0,0,0,0,0,\"\"");
} catch (NuvoException e) {
logger.debug("Error sending exit menu command for {}", zoneSource);
} }
} }
break; break;
case TYPE_ZONE_MENUREQ: case TYPE_ZONE_MENUREQ:
logger.debug("Menu Request: Source: {} - Value: {}", key, updateData); // ignore this update unless openHAB is handling this source
// For now we only support one level deep menus. If third field is '1', indicates go back to main menu. if (nuvoNetSrcMap.get(key).equals(2)) {
String[] menuDataSplit = updateData.split(","); logger.debug("Menu Request: Source: {} - Value: {}", key, updateData);
if (menuDataSplit.length > 3 && ONE.equals(menuDataSplit[2])) { // For now we only support one level deep menus. If third field is '1', indicates go back to main
try { // menu.
connector.sendCommand(menuDataSplit[0] + "MENU0xFFFFFFFF,0,0,0,0,0,0,\"\""); String[] menuDataSplit = updateData.split(",");
} catch (NuvoException e) { if (menuDataSplit.length > 3 && ONE.equals(menuDataSplit[2])) {
logger.debug("Error sending main menu command for {}", menuDataSplit[0]); try {
connector.sendCommand(menuDataSplit[0] + "MENU0xFFFFFFFF,0,0,0,0,0,0,\"\"");
} catch (NuvoException e) {
logger.debug("Error sending main menu command for {}", menuDataSplit[0]);
}
} }
} }
break; break;
case TYPE_ZONE_CONFIG: case TYPE_ZONE_CONFIG:
logger.debug("Zone Configuration: Zone: {} - Value: {}", key, updateData); logger.debug("Zone Configuration: Zone: {} - Value: {}", key, updateData);
@ -845,55 +851,64 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} }
break; break;
case TYPE_ALBUM_ART_REQ: case TYPE_ALBUM_ART_REQ:
logger.debug("Album Art Request for Source: {} - Data: {}", key, updateData); // ignore this update unless openHAB is handling this source
// 0x620FD879,80,80,2,0x00C0C0C0,0,0,0,0,1 if (nuvoNetSrcMap.get(key).equals(2)) {
String[] albumArtReq = updateData.split(COMMA); logger.debug("Album Art Request for Source: {} - Data: {}", key, updateData);
albumArtIds.put(SRC_KEY + key, Integer.decode(albumArtReq[0])); // 0x620FD879,80,80,2,0x00C0C0C0,0,0,0,0,1
String[] albumArtReq = updateData.split(COMMA);
albumArtIds.put(SRC_KEY + key, Integer.decode(albumArtReq[0]));
try { try {
if (albumArtMap.get(SRC_KEY + key).length > 1) { if (albumArtMap.get(SRC_KEY + key).length > 1) {
connector.sendCommand(SRC_KEY + key + ALBUM_ART_AVAILABLE + albumArtIds.get(SRC_KEY + key) connector.sendCommand(SRC_KEY + key + ALBUM_ART_AVAILABLE + albumArtIds.get(SRC_KEY + key)
+ COMMA + albumArtMap.get(SRC_KEY + key).length); + COMMA + albumArtMap.get(SRC_KEY + key).length);
} else { } else {
connector.sendCommand(SRC_KEY + key + ALBUM_ART_AVAILABLE + ZERO_COMMA); connector.sendCommand(SRC_KEY + key + ALBUM_ART_AVAILABLE + ZERO_COMMA);
}
} catch (NuvoException e) {
logger.debug("Error sending ALBUMARTAVAILABLE command for source: {}", key);
} }
} catch (NuvoException e) {
logger.debug("Error sending ALBUMARTAVAILABLE command for source: {}", key);
} }
break; break;
case TYPE_ALBUM_ART_FRAG_REQ: case TYPE_ALBUM_ART_FRAG_REQ:
logger.debug("Album Art Fragment Request for Source: {} - Data: {}", key, updateData); // ignore this update unless openHAB is handling this source
// 0x620FD879,0,750 (id, requested offset from start of image, byte length requested) if (nuvoNetSrcMap.get(key).equals(2)) {
String[] albumArtFragReq = updateData.split(COMMA); logger.debug("Album Art Fragment Request for Source: {} - Data: {}", key, updateData);
int requestedId = Integer.decode(albumArtFragReq[0]); // 0x620FD879,0,750 (id, requested offset from start of image, byte length requested)
int offset = Integer.parseInt(albumArtFragReq[1]); String[] albumArtFragReq = updateData.split(COMMA);
int length = Integer.parseInt(albumArtFragReq[2]); int requestedId = Integer.decode(albumArtFragReq[0]);
int offset = Integer.parseInt(albumArtFragReq[1]);
int length = Integer.parseInt(albumArtFragReq[2]);
if (requestedId == albumArtIds.get(SRC_KEY + key)) { if (requestedId == albumArtIds.get(SRC_KEY + key)) {
byte[] chunk = new byte[length]; byte[] chunk = new byte[length];
byte[] albumArtBytes = albumArtMap.get(SRC_KEY + key); byte[] albumArtBytes = albumArtMap.get(SRC_KEY + key);
if (albumArtBytes != null) { if (albumArtBytes != null) {
System.arraycopy(albumArtBytes, offset, chunk, 0, length); System.arraycopy(albumArtBytes, offset, chunk, 0, length);
final String frag = Base64.getEncoder().encodeToString(chunk); final String frag = Base64.getEncoder().encodeToString(chunk);
try { try {
connector.sendCommand(SRC_KEY + key + ALBUM_ART_FRAG + requestedId + COMMA + offset + COMMA connector.sendCommand(SRC_KEY + key + ALBUM_ART_FRAG + requestedId + COMMA + offset
+ frag.length() + COMMA + frag); + COMMA + frag.length() + COMMA + frag);
} catch (NuvoException e) { } catch (NuvoException e) {
logger.debug("Error sending ALBUMARTFRAG command for source: {}, artId: {}", key, logger.debug("Error sending ALBUMARTFRAG command for source: {}, artId: {}", key,
requestedId); requestedId);
}
} }
} }
} }
break; break;
case TYPE_FAVORITE_REQ: case TYPE_FAVORITE_REQ:
logger.debug("Favorite request for source: {} - favoriteId: {}", key, updateData); // ignore this update unless openHAB is handling this source
try { if (nuvoNetSrcMap.get(key).equals(2)) {
int playlistIdx = Integer.parseInt(updateData, 16) - 1000; logger.debug("Favorite request for source: {} - favoriteId: {}", key, updateData);
updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS, try {
"PLAY_MUSIC_PRESET:" + favoriteMap.get(key)[playlistIdx]); int playlistIdx = Integer.parseInt(updateData, 16) - 1000;
} catch (NumberFormatException nfe) { updateChannelState(NuvoEnum.valueOf(SOURCE + key), CHANNEL_BUTTON_PRESS,
logger.debug("Unable to parse favoriteId: {}", updateData); "PLAY_MUSIC_PRESET:" + favoriteMap.get(key)[playlistIdx]);
} catch (NumberFormatException nfe) {
logger.debug("Unable to parse favoriteId: {}", updateData);
}
} }
break; break;
default: default: