diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosBridgeHandler.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosBridgeHandler.java index f931c547f34cd..ccf57b807afb2 100644 --- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosBridgeHandler.java +++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosBridgeHandler.java @@ -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; @@ -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); } diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosThingBaseHandler.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosThingBaseHandler.java index b6d67caf9d2d3..0d4628f09c488 100644 --- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosThingBaseHandler.java +++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/handler/HeosThingBaseHandler.java @@ -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; @@ -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; @@ -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); } diff --git a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/HeosChannelHandlerFactory.java b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/HeosChannelHandlerFactory.java index bbca4678fed31..3e50764e361a6 100644 --- a/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/HeosChannelHandlerFactory.java +++ b/bundles/org.openhab.binding.heos/src/main/java/org/openhab/binding/heos/internal/HeosChannelHandlerFactory.java @@ -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; @@ -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);