mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +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 KodiDynamicCommandDescriptionProvider commandDescriptionProvider;
|
||||||
private final KodiDynamicStateDescriptionProvider stateDescriptionProvider;
|
private final KodiDynamicStateDescriptionProvider stateDescriptionProvider;
|
||||||
|
|
||||||
|
private final ChannelUID volumeChannelUID;
|
||||||
|
private final ChannelUID mutedChannelUID;
|
||||||
|
private final ChannelUID favoriteChannelUID;
|
||||||
private final ChannelUID profileChannelUID;
|
private final ChannelUID profileChannelUID;
|
||||||
|
|
||||||
private ScheduledFuture<?> connectionCheckerFuture;
|
private ScheduledFuture<?> connectionCheckerFuture;
|
||||||
@ -105,6 +108,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
this.commandDescriptionProvider = commandDescriptionProvider;
|
this.commandDescriptionProvider = commandDescriptionProvider;
|
||||||
this.stateDescriptionProvider = stateDescriptionProvider;
|
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);
|
profileChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_PROFILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +214,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
case CHANNEL_PLAYFAVORITE:
|
case CHANNEL_PLAYFAVORITE:
|
||||||
if (command instanceof StringType) {
|
if (command instanceof StringType) {
|
||||||
playFavorite(command);
|
playFavorite(command);
|
||||||
updateState(CHANNEL_PLAYFAVORITE, UnDefType.UNDEF);
|
updateState(favoriteChannelUID, UnDefType.UNDEF);
|
||||||
} else if (RefreshType.REFRESH == command) {
|
} else if (RefreshType.REFRESH == command) {
|
||||||
updateState(CHANNEL_PLAYFAVORITE, UnDefType.UNDEF);
|
updateState(favoriteChannelUID, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_PVR_OPEN_TV:
|
case CHANNEL_PVR_OPEN_TV:
|
||||||
@ -267,6 +273,8 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
case CHANNEL_PROFILE:
|
case CHANNEL_PROFILE:
|
||||||
if (command instanceof StringType) {
|
if (command instanceof StringType) {
|
||||||
connection.profile(command.toString());
|
connection.profile(command.toString());
|
||||||
|
} else if (RefreshType.REFRESH == command) {
|
||||||
|
connection.updateCurrentProfile();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_ARTIST:
|
case CHANNEL_ARTIST:
|
||||||
@ -644,13 +652,12 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateFavoriteChannelStateDescription() {
|
private void updateFavoriteChannelStateDescription() {
|
||||||
if (isLinked(CHANNEL_PLAYFAVORITE)) {
|
if (isLinked(favoriteChannelUID)) {
|
||||||
List<StateOption> options = new ArrayList<>();
|
List<StateOption> options = new ArrayList<>();
|
||||||
for (KodiFavorite favorite : connection.getFavorites()) {
|
for (KodiFavorite favorite : connection.getFavorites()) {
|
||||||
options.add(new StateOption(favorite.getTitle(), favorite.getTitle()));
|
options.add(new StateOption(favorite.getTitle(), favorite.getTitle()));
|
||||||
}
|
}
|
||||||
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_PLAYFAVORITE),
|
stateDescriptionProvider.setStateOptions(favoriteChannelUID, options);
|
||||||
options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,7 +714,9 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
if (connected) {
|
if (connected) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
scheduler.schedule(() -> connection.getSystemProperties(), 1, TimeUnit.SECONDS);
|
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)) {
|
if (isLinked(profileChannelUID)) {
|
||||||
scheduler.schedule(() -> connection.updateCurrentProfile(), 1, TimeUnit.SECONDS);
|
scheduler.schedule(() -> connection.updateCurrentProfile(), 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
@ -732,7 +741,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateVolume(int volume) {
|
public void updateVolume(int volume) {
|
||||||
updateState(CHANNEL_VOLUME, new PercentType(volume));
|
updateState(volumeChannelUID, new PercentType(volume));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -764,11 +773,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMuted(boolean muted) {
|
public void updateMuted(boolean muted) {
|
||||||
if (muted) {
|
updateState(mutedChannelUID, OnOffType.from(muted));
|
||||||
updateState(CHANNEL_MUTE, OnOffType.ON);
|
|
||||||
} else {
|
|
||||||
updateState(CHANNEL_MUTE, OnOffType.OFF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -933,11 +938,7 @@ public class KodiHandler extends BaseThingHandler implements KodiEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSubtitleEnabled(boolean enabled) {
|
public void updateSubtitleEnabled(boolean enabled) {
|
||||||
if (enabled) {
|
updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.from(enabled));
|
||||||
updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.ON);
|
|
||||||
} else {
|
|
||||||
updateState(CHANNEL_SUBTITLE_ENABLED, OnOffType.OFF);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1117,8 +1117,8 @@ public class KodiConnection implements KodiClientSocketEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
listener.updateMuted(false);
|
|
||||||
listener.updateVolume(100);
|
listener.updateVolume(100);
|
||||||
|
listener.updateMuted(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user