Skip to content

Commit

Permalink
[freeboxos] Reduce log level for discovery warnings to debug (openhab…
Browse files Browse the repository at this point in the history
…#17199)

* Avoid repeated discovery warnings every 10 minutes
* Discover VMs and home automation only when available

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored Aug 13, 2024
1 parent fca7cec commit 475709d
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class FreeboxOsDiscoveryService extends AbstractThingHandlerDiscoveryServ

private final Logger logger = LoggerFactory.getLogger(FreeboxOsDiscoveryService.class);

private boolean hasVm = true;
private boolean hasHomeAutomation = true;

private Optional<ScheduledFuture<?>> backgroundFuture = Optional.empty();

public FreeboxOsDiscoveryService() {
Expand Down Expand Up @@ -111,13 +114,17 @@ protected void startScan() {
discoverPlugs(bridgeUID);
discoverRepeater(bridgeUID, lanHosts);
discoverPlayer(bridgeUID, lanHosts);
discoverVM(bridgeUID, lanHosts);
discoverHome(bridgeUID);
if (hasVm) {
discoverVM(bridgeUID, lanHosts);
}
if (hasHomeAutomation) {
discoverHome(bridgeUID);
}
if (thingHandler.getConfiguration().discoverNetDevice) {
discoverHosts(bridgeUID, lanHosts);
}
} catch (FreeboxException e) {
logger.warn("Error while requesting data for things discovery: {}", e.getMessage());
logger.debug("Error while requesting data for things discovery: {}", e.getMessage());
}
}
}
Expand All @@ -128,7 +135,7 @@ private void discoverHome(ThingUID bridgeUID) {
thingHandler.getManager(HomeManager.class).getHomeNodes().forEach(
node -> builder.configure(bridgeUID, node).ifPresent(result -> thingDiscovered(result.build())));
} catch (FreeboxException e) {
logger.warn("Error discovering Home: {}", e.getMessage());
logger.debug("Error discovering Home: {}", e.getMessage());
}
}

Expand All @@ -138,7 +145,7 @@ private void discoverPlugs(ThingUID bridgeUID) {
thingHandler.getManager(FreeplugManager.class).getPlugs()
.forEach(plug -> thingDiscovered(builder.configure(bridgeUID, plug).build()));
} catch (FreeboxException e) {
logger.warn("Error discovering freeplugs: {}", e.getMessage());
logger.debug("Error discovering freeplugs: {}", e.getMessage());
}
}

Expand All @@ -149,7 +156,7 @@ private void discoverPhone(ThingUID bridgeUID) {
statuses = thingHandler.getManager(PhoneManager.class).getPhoneStatuses();
statuses.forEach(phone -> thingDiscovered(builder.configure(bridgeUID, phone).build()));
} catch (FreeboxException e) {
logger.warn("Error discovering phones: {}", e.getMessage());
logger.debug("Error discovering phones: {}", e.getMessage());
}
if (!statuses.isEmpty()) {
ThingUID thingUID = new ThingUID(THING_TYPE_CALL, bridgeUID, "landline");
Expand Down Expand Up @@ -180,7 +187,7 @@ private void discoverHosts(ThingUID bridgeUID, List<LanHost> lanHosts) {
thingDiscovered(builder.build());
});
} catch (FreeboxException e) {
logger.warn("Error discovering Hosts: {}", e.getMessage());
logger.debug("Error discovering Hosts: {}", e.getMessage());
}
}

Expand All @@ -199,7 +206,7 @@ private void discoverVM(ThingUID bridgeUID, List<LanHost> lanHosts) {
thingDiscovered(discoveryResult);
});
} catch (FreeboxException e) {
logger.warn("Error discovering VM: {}", e.getMessage());
logger.debug("Error discovering VM: {}", e.getMessage());
}
}

Expand All @@ -219,14 +226,17 @@ private void discoverRepeater(ThingUID bridgeUID, List<LanHost> lanHosts) {
thingDiscovered(discoveryResult);
});
} catch (FreeboxException e) {
logger.warn("Error discovering Repeater: {}", e.getMessage());
logger.debug("Error discovering Repeater: {}", e.getMessage());
}
}

private void discoverServer(ThingUID bridgeUID) {
try {
Config config = thingHandler.getManager(SystemManager.class).getConfig();

hasVm = config.modelInfo().hasVm();
hasHomeAutomation = config.modelInfo().hasHomeAutomation();

ThingTypeUID targetType = config.boardName().startsWith("fbxgw7") ? THING_TYPE_DELTA
: THING_TYPE_REVOLUTION;
ThingUID thingUID = new ThingUID(targetType, bridgeUID, config.serial());
Expand All @@ -237,7 +247,7 @@ private void discoverServer(ThingUID bridgeUID) {
.withProperty(Thing.PROPERTY_MAC_ADDRESS, config.mac().toColonDelimitedString()).build();
thingDiscovered(discoveryResult);
} catch (FreeboxException e) {
logger.warn("Error discovering Server: {}", e.getMessage());
logger.debug("Error discovering Server: {}", e.getMessage());
}
}

Expand All @@ -254,7 +264,7 @@ private void discoverPlayer(ThingUID bridgeUID, List<LanHost> lanHosts) {
thingDiscovered(discoveryResult);
}
} catch (FreeboxException e) {
logger.warn("Error discovering Player: {}", e.getMessage());
logger.debug("Error discovering Player: {}", e.getMessage());
}
}
}

0 comments on commit 475709d

Please sign in to comment.