mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[kodi] Reduce polling by checking linkage first (#8912)
* Reduce polling by checking linkage first Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
15312d33f2
commit
4de9e0f204
@ -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<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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
@ -1117,8 +1117,8 @@ public class KodiConnection implements KodiClientSocketEventListener {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
listener.updateMuted(false);
|
||||
listener.updateVolume(100);
|
||||
listener.updateMuted(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user