[daikin] Add the ability to disable background discovery (#12300)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2022-02-20 06:50:12 +10:00 committed by GitHub
parent 2e72ac78fd
commit 6000bc75fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 25 deletions

View File

@ -13,6 +13,14 @@ This may work with the older KRP series of wired adapters, but has not been test
This add-on will broadcast messages on your local network looking for Daikin air conditioning units and adding them to the queue of new items discovered. This add-on will broadcast messages on your local network looking for Daikin air conditioning units and adding them to the queue of new items discovered.
You can also manually add a new item if you know the IP address. You can also manually add a new item if you know the IP address.
Background discovery polls the network every minute for devices.
Background discovery is **enabled** by default.
To **disable** background discovery, add the following line to the *conf/services/runtime.cfg* file:
```text
discovery.daikin:background=false
```
### BRP072C42 adapter discovery ### BRP072C42 adapter discovery
A BRP072C42 adapter requires a registered UUID to authenticate. Upon discovery, a UUID will be generated but the adapter's key must be entered in the Thing configuration to complete the UUID registration. A BRP072C42 adapter requires a registered UUID to authenticate. Upon discovery, a UUID will be generated but the adapter's key must be entered in the Thing configuration to complete the UUID registration.

View File

@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory;
* @author Paul Smedley <paul@smedley.id.au> - Modifications to support Airbase Controllers * @author Paul Smedley <paul@smedley.id.au> - Modifications to support Airbase Controllers
* *
*/ */
@Component(service = DiscoveryService.class) @Component(service = DiscoveryService.class, configurationPid = "discovery.daikin")
@NonNullByDefault @NonNullByDefault
public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService { public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
private static final String UDP_PACKET_CONTENTS = "DAIKIN_UDP/common/basic_info"; private static final String UDP_PACKET_CONTENTS = "DAIKIN_UDP/common/basic_info";
@ -62,17 +62,15 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
private Logger logger = LoggerFactory.getLogger(DaikinACUnitDiscoveryService.class); private Logger logger = LoggerFactory.getLogger(DaikinACUnitDiscoveryService.class);
private @Nullable HttpClient httpClient; private @Nullable HttpClient httpClient;
private final Runnable scanner;
private @Nullable ScheduledFuture<?> backgroundFuture; private @Nullable ScheduledFuture<?> backgroundFuture;
public DaikinACUnitDiscoveryService() { public DaikinACUnitDiscoveryService() {
super(Collections.singleton(DaikinBindingConstants.THING_TYPE_AC_UNIT), 600, true); super(Collections.singleton(DaikinBindingConstants.THING_TYPE_AC_UNIT), 600, true);
scanner = createScanner();
} }
@Override @Override
protected void startScan() { protected void startScan() {
scheduler.execute(scanner); scheduler.execute(this::scanner);
} }
@Override @Override
@ -83,7 +81,7 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
backgroundFuture.cancel(true); backgroundFuture.cancel(true);
backgroundFuture = null; backgroundFuture = null;
} }
backgroundFuture = scheduler.scheduleWithFixedDelay(scanner, 0, 60, TimeUnit.SECONDS); backgroundFuture = scheduler.scheduleWithFixedDelay(this::scanner, 0, 60, TimeUnit.SECONDS);
} }
@Override @Override
@ -96,8 +94,7 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
super.stopBackgroundDiscovery(); super.stopBackgroundDiscovery();
} }
private Runnable createScanner() { private void scanner() {
return () -> {
long timestampOfLastScan = getTimestampOfLastScan(); long timestampOfLastScan = getTimestampOfLastScan();
for (InetAddress broadcastAddress : getBroadcastAddresses()) { for (InetAddress broadcastAddress : getBroadcastAddresses()) {
logger.trace("Starting broadcast for {}", broadcastAddress.toString()); logger.trace("Starting broadcast for {}", broadcastAddress.toString());
@ -121,7 +118,6 @@ public class DaikinACUnitDiscoveryService extends AbstractDiscoveryService {
} }
removeOlderResults(timestampOfLastScan); removeOlderResults(timestampOfLastScan);
};
} }
private boolean receivePacketAndDiscover(DatagramSocket socket) { private boolean receivePacketAndDiscover(DatagramSocket socket) {