openhab-addons icon indicating copy to clipboard operation
openhab-addons copied to clipboard

Use `var` for timestampOfLastScan to support upcoming Instant-based API

Open jlaur opened this issue 10 months ago • 0 comments

This is a non-breaking change for future-proofing in case openhab/openhab-core#4866 will be accepted. It will make sure that the new overload removeOlderResults(Instant) is automatically selected when getTimestampOfLastScan() is changed to return an Instant rather than long.

There are two variants of the getTimestampOfLastScan() usages.

This one will already work:

removeOlderResults(getTimestampOfLastScan());

whereas this one will currently not:

long lastScan = getTimestampOfLastScan();
removeOlderResults(lastScan);

This PR can be merged before any of the other related PR's.

Using var when the type is not obvious is somewhat controversial, but it will ease the migration. I will provide another PR for finally changing to Instant when core PR is merged. So longvarInstant.

Based on search:

$ grep -R "getTimestampOfLastScan()" . | grep -v "removeOlderResults"
./bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryService.java:        // Results newer than `getTimestampOfLastScan()` will also be notified again but do not lead to duplicates.
./bundles/org.openhab.binding.broadlinkthermostat/src/main/java/org/openhab/binding/broadlinkthermostat/internal/discovery/BroadlinkDiscoveryService.java:        long timestampOfLastScan = getTimestampOfLastScan();
./bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/discovery/DaikinACUnitDiscoveryService.java:        long timestampOfLastScan = getTimestampOfLastScan();
./bundles/org.openhab.binding.irobot/src/main/java/org/openhab/binding/irobot/internal/discovery/IRobotDiscoveryService.java:            long timestampOfLastScan = getTimestampOfLastScan();
./bundles/org.openhab.binding.ecovacs/src/main/java/org/openhab/binding/ecovacs/internal/discovery/EcovacsDeviceDiscoveryService.java:            long timestampOfLastScan = getTimestampOfLastScan();

Related to #18838

jlaur avatar Jun 23 '25 21:06 jlaur