Skip to content

Commit

Permalink
[HEOS] Update handling of groups (openhab#8348)
Browse files Browse the repository at this point in the history
- remove group-mapping when marking group OFFLINE
- bail out in group-handler if the pid matches but the members do not match.

Signed-off-by: Martin van Wingerden <[email protected]>
  • Loading branch information
martinvw authored and andrewfg committed Aug 31, 2020
1 parent e2ae2fb commit 6f8e21a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,17 @@ void resetPlayerList(ChannelUID channelUID) {
* Sets the HEOS Thing offline
*/
@SuppressWarnings("null")
public void setGroupOffline(String hashValue) {
HeosGroupHandler groupHandler = groupHandlerMap.get(hashValue);
public void setGroupOffline(String groupMemberHash) {
HeosGroupHandler groupHandler = groupHandlerMap.get(groupMemberHash);
if (groupHandler != null) {
groupHandler.setStatusOffline();
}
hashToGidMap.remove(groupMemberHash);
}

/**
* Sets the HEOS Thing online. Also updates the link between
* the groupMemberHash value with the actual gid of this group *
* the groupMemberHash value with the actual gid of this group
*/
public void setGroupOnline(String groupMemberHash, String groupId) {
hashToGidMap.put(groupMemberHash, groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ private void delayedInitialize() {
throw new IllegalStateException("Invalid group response received");
}

assertSameGroup(group);

gid = groupId;
updateConfiguration(groupId, group);
updateStatus(ThingStatus.ONLINE);
Expand All @@ -291,6 +293,20 @@ private void delayedInitialize() {
}
}

/**
* Make sure the given group is group which this handler represents
*
* @param group retrieved from HEOS system
*/
private void assertSameGroup(Group group) {
String storedGroupHash = HeosGroup.calculateGroupMemberHash(configuration.members);
String retrievedGroupHash = HeosGroup.calculateGroupMemberHash(group);

if (!retrievedGroupHash.equals(storedGroupHash)) {
throw new IllegalStateException("Invalid group received, members / hash do not match.");
}
}

@Override
void refreshPlayState(String id) throws IOException, ReadException {
super.refreshPlayState(id);
Expand Down

0 comments on commit 6f8e21a

Please sign in to comment.