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;
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);
}
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:
case CHANNEL_PROFILE:
if (command instanceof StringType) {
connection.profile(command.toString());
+ } else if (RefreshType.REFRESH == command) {
+ connection.updateCurrentProfile();
}
break;
case CHANNEL_ARTIST:
}
private void updateFavoriteChannelStateDescription() {
- if (isLinked(CHANNEL_PLAYFAVORITE)) {
+ if (isLinked(favoriteChannelUID)) {
List<StateOption> 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);
}
}
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);
}
@Override
public void updateVolume(int volume) {
- updateState(CHANNEL_VOLUME, new PercentType(volume));
+ updateState(volumeChannelUID, new PercentType(volume));
}
@Override
@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
@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