Skip to content

Commit

Permalink
[freeboxos] Avoid useless API requests (phone) (openhab#17310)
Browse files Browse the repository at this point in the history
Avoids API requests when channels are unlinked.

Signed-off-by: Laurent Garnier <[email protected]>
Signed-off-by: Ciprian Pascu <[email protected]>
  • Loading branch information
lolodomo authored and Ciprian Pascu committed Jan 2, 2025
1 parent f9bb540 commit 5e84f65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public DectHandler(Thing thing) {
super(thing);
}

@Override
protected void internalPoll() throws FreeboxException {
if (isLinked(TELEPHONY_SERVICE) || isLinked(DECT_ACTIVE) || isLinked(ALTERNATE_RING)) {
Config config = getManager(PhoneManager.class).getConfig();
updateConfigChannels(config);
}

if (isLinked(ONHOOK) || isLinked(RINGING) || isLinked(HARDWARE_STATUS) || isLinked(GAIN_RX)
|| isLinked(GAIN_TX)) {
getManager(PhoneManager.class).getStatus(getClientId()).ifPresent(this::updateStatusChannels);
}
}

@Override
protected void updateConfigChannels(Config config) {
super.updateConfigChannels(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.openhab.binding.freeboxos.internal.api.rest.PhoneManager.Status;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -52,10 +51,14 @@ void initializeProperties(Map<String, String> properties) throws FreeboxExceptio
protected void internalPoll() throws FreeboxException {
logger.debug("Polling landline status...");

Config config = getManager(PhoneManager.class).getConfig();
updateConfigChannels(config);
if (isLinked(TELEPHONY_SERVICE)) {
Config config = getManager(PhoneManager.class).getConfig();
updateConfigChannels(config);
}

getManager(PhoneManager.class).getStatus(getClientId()).ifPresent(this::updateStatusChannels);
if (isLinked(ONHOOK) || isLinked(RINGING) || isLinked(HARDWARE_STATUS)) {
getManager(PhoneManager.class).getStatus(getClientId()).ifPresent(this::updateStatusChannels);
}
}

protected void updateConfigChannels(Config config) {
Expand All @@ -66,7 +69,6 @@ protected void updateStatusChannels(Status status) {
updateChannelOnOff(ONHOOK, status.onHook());
updateChannelOnOff(RINGING, status.isRinging());
updateChannelString(HARDWARE_STATUS, status.hardwareDefect() ? "KO" : "OK");
updateStatus(ThingStatus.ONLINE);
}

@Override
Expand Down

0 comments on commit 5e84f65

Please sign in to comment.