Activating discovery service

Signed-off-by: Gaël L'hopital <gael@lhopital.org>
This commit is contained in:
Gaël L'hopital 2024-11-19 14:25:38 +01:00
parent 58ef294232
commit 815de298a2
2 changed files with 13 additions and 5 deletions

View File

@ -12,9 +12,10 @@
*/
package org.openhab.binding.airparif.internal.discovery;
import static org.openhab.binding.airparif.internal.AirParifBindingConstants.*;
import static org.openhab.binding.airparif.internal.AirParifBindingConstants.LOCATION_THING_TYPE;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.airparif.internal.config.LocationConfiguration;
@ -43,13 +44,12 @@ public class AirParifDiscoveryService extends AbstractThingHandlerDiscoveryServi
private static final int DISCOVER_TIMEOUT_SECONDS = 2;
private final Logger logger = LoggerFactory.getLogger(AirParifDiscoveryService.class);
private final DepartmentDbService dbService;
private final DepartmentDbService dbService = new DepartmentDbService();
private @NonNullByDefault({}) LocationProvider locationProvider;
public AirParifDiscoveryService() {
super(AirParifBridgeHandler.class, SUPPORTED_THING_TYPES_UIDS, DISCOVER_TIMEOUT_SECONDS);
dbService = new DepartmentDbService();
super(AirParifBridgeHandler.class, Set.of(LOCATION_THING_TYPE), DISCOVER_TIMEOUT_SECONDS);
}
@Reference(unbind = "-")
@ -77,7 +77,7 @@ public class AirParifDiscoveryService extends AbstractThingHandlerDiscoveryServi
if (!candidates.isEmpty()) {
candidates.forEach(dep -> thingDiscovered(
DiscoveryResultBuilder.create(new ThingUID(LOCATION_THING_TYPE, bridgeUID, dep.id()))//
.withLabel("Location Report: %s".formatted(dep.name())) //
.withLabel("Air Quality Report: %s".formatted(dep.name())) //
.withProperty(LocationConfiguration.DEPARTMENT, dep.id()) //
.withProperty(LocationConfiguration.LOCATION, serverLocation.toFullString())//
.withRepresentationProperty(LocationConfiguration.DEPARTMENT) //

View File

@ -24,6 +24,7 @@ import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@ -60,6 +61,7 @@ import org.openhab.binding.airparif.internal.api.PollenAlertLevel;
import org.openhab.binding.airparif.internal.api.Pollutant;
import org.openhab.binding.airparif.internal.config.BridgeConfiguration;
import org.openhab.binding.airparif.internal.deserialization.AirParifDeserializer;
import org.openhab.binding.airparif.internal.discovery.AirParifDiscoveryService;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Bridge;
@ -70,6 +72,7 @@ import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.types.Command;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
@ -330,4 +333,9 @@ public class AirParifBridgeHandler extends BaseBridgeHandler implements HandlerU
public Map<String, ScheduledFuture<?>> getJobs() {
return jobs;
}
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Set.of(AirParifDiscoveryService.class);
}
}