]> git.basschouten.com Git - openhab-addons.git/blob
10af78e810ddca53182e8fd3dce30519937e4dc4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.synopanalyzer.internal;
14
15 import static org.openhab.binding.synopanalyzer.internal.SynopAnalyzerBindingConstants.THING_SYNOP;
16
17 import java.util.List;
18
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;
33
34 /**
35  * The {@link SynopAnalyzerHandlerFactory} is responsible for creating things and thing handlers.
36  *
37  * @author GaĆ«l L'hopital - Initial contribution
38  */
39
40 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.synopanalyzer")
41 @NonNullByDefault
42 public class SynopAnalyzerHandlerFactory extends BaseThingHandlerFactory {
43     private final LocationProvider locationProvider;
44     private final List<Station> stationDB;
45
46     @Activate
47     public SynopAnalyzerHandlerFactory(@Reference StationDbService stationDBService,
48             @Reference LocationProvider locationProvider) {
49         this.locationProvider = locationProvider;
50         this.stationDB = stationDBService.getStations();
51     }
52
53     @Override
54     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55         return THING_SYNOP.equals(thingTypeUID);
56     }
57
58     @Override
59     protected @Nullable ThingHandler createHandler(Thing thing) {
60         return supportsThingType(thing.getThingTypeUID()) ? new SynopAnalyzerHandler(thing, locationProvider, stationDB)
61                 : null;
62     }
63 }