Skip to content

Commit

Permalink
mielecloud
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <github@klug.nrw>
  • Loading branch information
J-N-K committed Dec 30, 2023
1 parent 51d4b19 commit 1d1553e
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants.*;
import static org.openhab.binding.mielecloud.internal.handler.MieleHandlerFactory.SUPPORTED_THING_TYPES;

import java.util.Objects;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand All @@ -26,6 +26,7 @@
import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
Expand Down Expand Up @@ -72,12 +73,12 @@ protected void startScan() {

@Override
public void activate() {
startBackgroundDiscovery();
super.activate(Map.of(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, true));
}

@Override
public void deactivate() {
stopBackgroundDiscovery();
public void dispose() {
super.dispose();
removeOlderResults(System.currentTimeMillis(), getBridgeUid());
}

Expand All @@ -98,16 +99,11 @@ public void onDeviceStateUpdated(DeviceState deviceState) {
}

private void createDiscoveryResult(DeviceState deviceState, ThingTypeUID thingTypeUid) {
MieleBridgeHandler bridgeHandler = this.thingHandler;
if (bridgeHandler == null) {
return;
}

ThingUID thingUid = new ThingUID(thingTypeUid, bridgeHandler.getThing().getUID(),
ThingUID thingUid = new ThingUID(thingTypeUid, thingHandler.getThing().getUID(),
deviceState.getDeviceIdentifier());

DiscoveryResultBuilder discoveryResultBuilder = DiscoveryResultBuilder.create(thingUid)
.withBridge(bridgeHandler.getThing().getUID()).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER)
.withBridge(thingHandler.getThing().getUID()).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER)
.withLabel(getLabel(deviceState));

ThingInformationExtractor.extractProperties(thingTypeUid, deviceState).entrySet()
Expand Down Expand Up @@ -198,6 +194,7 @@ private String getLabel(DeviceState deviceState) {

@Override
public void initialize() {
Objects.requireNonNull(thingHandler).setDiscoveryService(this);
thingHandler.setDiscoveryService(this);
super.initialize();
}
}

0 comments on commit 1d1553e

Please sign in to comment.