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
1 changed files with 111 additions and 96 deletions

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,6 +762,8 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} }
break; break;
case TYPE_MENU_ITEM_SELECTED: case TYPE_MENU_ITEM_SELECTED:
// ignore this update unless openHAB is handling this source
if (nuvoNetSrcMap.get(key).equals(2)) {
String[] updateDataSplit = updateData.split(COMMA); String[] updateDataSplit = updateData.split(COMMA);
String zoneSource = updateDataSplit[0]; String zoneSource = updateDataSplit[0];
String menuId = updateDataSplit[1]; String menuId = updateDataSplit[1];
@ -815,10 +817,14 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
logger.debug("Error sending exit menu command for {}", zoneSource); logger.debug("Error sending exit menu command for {}", zoneSource);
} }
} }
}
break; break;
case TYPE_ZONE_MENUREQ: case TYPE_ZONE_MENUREQ:
// ignore this update unless openHAB is handling this source
if (nuvoNetSrcMap.get(key).equals(2)) {
logger.debug("Menu Request: Source: {} - Value: {}", key, updateData); logger.debug("Menu Request: Source: {} - Value: {}", key, updateData);
// For now we only support one level deep menus. If third field is '1', indicates go back to main menu. // For now we only support one level deep menus. If third field is '1', indicates go back to main
// menu.
String[] menuDataSplit = updateData.split(","); String[] menuDataSplit = updateData.split(",");
if (menuDataSplit.length > 3 && ONE.equals(menuDataSplit[2])) { if (menuDataSplit.length > 3 && ONE.equals(menuDataSplit[2])) {
try { try {
@ -827,7 +833,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
logger.debug("Error sending main menu command for {}", menuDataSplit[0]); 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,6 +851,8 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} }
break; break;
case TYPE_ALBUM_ART_REQ: case TYPE_ALBUM_ART_REQ:
// ignore this update unless openHAB is handling this source
if (nuvoNetSrcMap.get(key).equals(2)) {
logger.debug("Album Art Request for Source: {} - Data: {}", key, updateData); logger.debug("Album Art Request for Source: {} - Data: {}", key, updateData);
// 0x620FD879,80,80,2,0x00C0C0C0,0,0,0,0,1 // 0x620FD879,80,80,2,0x00C0C0C0,0,0,0,0,1
String[] albumArtReq = updateData.split(COMMA); String[] albumArtReq = updateData.split(COMMA);
@ -860,8 +868,11 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} catch (NuvoException e) { } catch (NuvoException e) {
logger.debug("Error sending ALBUMARTAVAILABLE command for source: {}", key); logger.debug("Error sending ALBUMARTAVAILABLE command for source: {}", key);
} }
}
break; break;
case TYPE_ALBUM_ART_FRAG_REQ: case TYPE_ALBUM_ART_FRAG_REQ:
// ignore this update unless openHAB is handling this source
if (nuvoNetSrcMap.get(key).equals(2)) {
logger.debug("Album Art Fragment Request for Source: {} - Data: {}", key, updateData); logger.debug("Album Art Fragment Request for Source: {} - Data: {}", key, updateData);
// 0x620FD879,0,750 (id, requested offset from start of image, byte length requested) // 0x620FD879,0,750 (id, requested offset from start of image, byte length requested)
String[] albumArtFragReq = updateData.split(COMMA); String[] albumArtFragReq = updateData.split(COMMA);
@ -877,16 +888,19 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
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:
// ignore this update unless openHAB is handling this source
if (nuvoNetSrcMap.get(key).equals(2)) {
logger.debug("Favorite request for source: {} - favoriteId: {}", key, updateData); logger.debug("Favorite request for source: {} - favoriteId: {}", key, updateData);
try { try {
int playlistIdx = Integer.parseInt(updateData, 16) - 1000; int playlistIdx = Integer.parseInt(updateData, 16) - 1000;
@ -895,6 +909,7 @@ public class NuvoHandler extends BaseThingHandler implements NuvoMessageEventLis
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
logger.debug("Unable to parse favoriteId: {}", updateData); logger.debug("Unable to parse favoriteId: {}", updateData);
} }
}
break; break;
default: default:
logger.debug("onNewMessageEvent: unhandled key {}", key); logger.debug("onNewMessageEvent: unhandled key {}", key);