diff --git a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/handler/KodiHandler.java b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/handler/KodiHandler.java index 5ef7b0da807..a6e7c343488 100644 --- a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/handler/KodiHandler.java +++ b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/handler/KodiHandler.java @@ -91,6 +91,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { private final KodiDynamicCommandDescriptionProvider commandDescriptionProvider; private final KodiDynamicStateDescriptionProvider stateDescriptionProvider; + private final ChannelUID volumeChannelUID; + private final ChannelUID mutedChannelUID; + private final ChannelUID favoriteChannelUID; private final ChannelUID profileChannelUID; private ScheduledFuture connectionCheckerFuture; @@ -105,6 +108,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { this.commandDescriptionProvider = commandDescriptionProvider; this.stateDescriptionProvider = stateDescriptionProvider; + volumeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_VOLUME); + mutedChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_MUTE); + favoriteChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_PLAYFAVORITE); profileChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_PROFILE); } @@ -208,9 +214,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { case CHANNEL_PLAYFAVORITE: if (command instanceof StringType) { playFavorite(command); - updateState(CHANNEL_PLAYFAVORITE, UnDefType.UNDEF); + updateState(favoriteChannelUID, UnDefType.UNDEF); } else if (RefreshType.REFRESH == command) { - updateState(CHANNEL_PLAYFAVORITE, UnDefType.UNDEF); + updateState(favoriteChannelUID, UnDefType.UNDEF); } break; case CHANNEL_PVR_OPEN_TV: @@ -267,6 +273,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { case CHANNEL_PROFILE: if (command instanceof StringType) { connection.profile(command.toString()); + } else if (RefreshType.REFRESH == command) { + connection.updateCurrentProfile(); } break; case CHANNEL_ARTIST: @@ -644,13 +652,12 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { } private void updateFavoriteChannelStateDescription() { - if (isLinked(CHANNEL_PLAYFAVORITE)) { + if (isLinked(favoriteChannelUID)) { List options = new ArrayList<>(); for (KodiFavorite favorite : connection.getFavorites()) { options.add(new StateOption(favorite.getTitle(), favorite.getTitle())); } - stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_PLAYFAVORITE), - options); + stateDescriptionProvider.setStateOptions(favoriteChannelUID, options); } } @@ -707,7 +714,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { if (connected) { updateStatus(ThingStatus.ONLINE); scheduler.schedule(() -> connection.getSystemProperties(), 1, TimeUnit.SECONDS); - scheduler.schedule(() -> connection.updateVolume(), 1, TimeUnit.SECONDS); + if (isLinked(volumeChannelUID) || isLinked(mutedChannelUID)) { + scheduler.schedule(() -> connection.updateVolume(), 1, TimeUnit.SECONDS); + } if (isLinked(profileChannelUID)) { scheduler.schedule(() -> connection.updateCurrentProfile(), 1, TimeUnit.SECONDS); } @@ -732,7 +741,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { @Override public void updateVolume(int volume) { - updateState(CHANNEL_VOLUME, new PercentType(volume)); + updateState(volumeChannelUID, new PercentType(volume)); } @Override @@ -764,11 +773,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { @Override public void updateMuted(boolean muted) { - if (muted) { - updateState(CHANNEL_MUTE, OnOffType.ON); - } else { - updateState(CHANNEL_MUTE, OnOffType.OFF); - } + updateState(mutedChannelUID, OnOffType.from(muted)); } @Override @@ -933,11 +938,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener { @Override public void updateSubtitleEnabled(boolean enabled) { - if (enabled) { - updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.ON); - } else { - updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.OFF); - } + updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.from(enabled)); } @Override diff --git a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiConnection.java b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiConnection.java index a1afeb163b3..3da014712bf 100644 --- a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiConnection.java +++ b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiConnection.java @@ -1117,8 +1117,8 @@ public class KodiConnection implements KodiClientSocketEventListener { } } } else { - listener.updateMuted(false); listener.updateVolume(100); + listener.updateMuted(false); } }