Skip to content

Commit

Permalink
fixed an issue with handling the favorites
Browse files Browse the repository at this point in the history
This fix corrects the handling of the favorite and player channels which
are generated during runtime.
It was not possible to play the favorites because the channels where not
recognized by the channel handler

Signed-off-by: Johannes Einig <[email protected]>
  • Loading branch information
Wire82 committed Jan 5, 2020
1 parent 6cb5ac1 commit a1bc698
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder;
import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.openhab.binding.heos.internal.HeosChannelHandlerFactory;
Expand Down Expand Up @@ -94,7 +95,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
return;
}
HeosChannelHandler channelHandler = channelHandlerFactory.getChannelHandler(channelUID);
ChannelTypeUID channelTypeUID = null; // Needed to detect the player channels on the bridge
Channel channel = this.getThing().getChannel(channelUID.getId());
if (channel != null) {
channelTypeUID = channel.getChannelTypeUID();
} else {
logger.debug("No valid channel found");
return;
}
HeosChannelHandler channelHandler = channelHandlerFactory.getChannelHandler(channelUID, channelTypeUID);
if (channelHandler != null) {
channelHandler.handleCommand(command, this, channelUID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.openhab.binding.heos.HeosBindingConstants.*;
//import static org.openhab.binding.heos.internal.resources.HeosConstants.*;
import static org.openhab.binding.heos.internal.resources.HeosConstants.*;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -34,6 +35,7 @@
import org.eclipse.smarthome.core.thing.ThingStatusInfo;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.io.net.http.HttpUtil;
import org.openhab.binding.heos.internal.HeosChannelHandlerFactory;
Expand Down Expand Up @@ -80,7 +82,15 @@ public HeosThingBaseHandler(Thing thing, HeosSystem heos, HeosFacade api) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
HeosChannelHandler channelHandler = channelHandlerFactory.getChannelHandler(channelUID);
ChannelTypeUID channelTypeUID = null; // Needed to detect the favorite channels
Channel channel = this.getThing().getChannel(channelUID.getId());
if (channel != null) {
channelTypeUID = channel.getChannelTypeUID();
} else {
logger.debug("No valid channel found");
return;
}
HeosChannelHandler channelHandler = channelHandlerFactory.getChannelHandler(channelUID, channelTypeUID);
if (channelHandler != null) {
channelHandler.handleCommand(command, id, this, channelUID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.HashMap;
import java.util.Map;

import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
import org.openhab.binding.heos.handler.HeosBridgeHandler;
Expand Down Expand Up @@ -65,24 +64,17 @@ public HeosChannelHandlerFactory(HeosBridgeHandler bridge, HeosFacade api) {
this.api = api;
}

public HeosChannelHandler getChannelHandler(ChannelUID channelUID) {
public HeosChannelHandler getChannelHandler(ChannelUID channelUID, ChannelTypeUID channelTypeUID) {
if (handlerStorageMap.containsKey(channelUID)) {
return handlerStorageMap.get(channelUID);
} else {
HeosChannelHandler createdChannelHandler = createNewChannelHandler(channelUID);
HeosChannelHandler createdChannelHandler = createNewChannelHandler(channelUID, channelTypeUID);
handlerStorageMap.put(channelUID, createdChannelHandler);
return createdChannelHandler;
}
}

private HeosChannelHandler createNewChannelHandler(ChannelUID channelUID) {
ChannelTypeUID channelTypeUID;
Channel channel = bridge.getThing().getChannel(channelUID.getId());
if (channel == null) {
channelTypeUID = null;
} else {
channelTypeUID = channel.getChannelTypeUID();
}
private HeosChannelHandler createNewChannelHandler(ChannelUID channelUID, ChannelTypeUID channelTypeUID) {
switch (channelUID.getId()) {
case CH_ID_CONTROL:
return new HeosChannelHandlerControl(bridge, api);
Expand Down

0 comments on commit a1bc698

Please sign in to comment.