2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.synopanalyzer.internal;
15 import static org.openhab.binding.synopanalyzer.internal.SynopAnalyzerBindingConstants.THING_SYNOP;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.synopanalyzer.internal.handler.SynopAnalyzerHandler;
22 import org.openhab.binding.synopanalyzer.internal.stationdb.Station;
23 import org.openhab.binding.synopanalyzer.internal.stationdb.StationDbService;
24 import org.openhab.core.i18n.LocationProvider;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Activate;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Reference;
35 * The {@link SynopAnalyzerHandlerFactory} is responsible for creating things and thing handlers.
37 * @author Gaƫl L'hopital - Initial contribution
40 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.synopanalyzer")
42 public class SynopAnalyzerHandlerFactory extends BaseThingHandlerFactory {
43 private final LocationProvider locationProvider;
44 private final List<Station> stationDB;
47 public SynopAnalyzerHandlerFactory(@Reference StationDbService stationDBService,
48 @Reference LocationProvider locationProvider) {
49 this.locationProvider = locationProvider;
50 this.stationDB = stationDBService.getStations();
54 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55 return THING_SYNOP.equals(thingTypeUID);
59 protected @Nullable ThingHandler createHandler(Thing thing) {
60 return supportsThingType(thing.getThingTypeUID()) ? new SynopAnalyzerHandler(thing, locationProvider, stationDB)