]> git.basschouten.com Git - openhab-addons.git/blob
518a29c2bc1380595f1787435105e5d984ac2d9a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.airquality.internal;
14
15 import static org.openhab.binding.airquality.internal.AirQualityBindingConstants.*;
16
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.airquality.internal.handler.AirQualityBridgeHandler;
22 import org.openhab.binding.airquality.internal.handler.AirQualityStationHandler;
23 import org.openhab.core.i18n.LocationProvider;
24 import org.openhab.core.i18n.TimeZoneProvider;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
34
35 /**
36  * The {@link AirQualityHandlerFactory} is responsible for creating thing and thing
37  * handler.
38  *
39  * @author GaĆ«l L'hopital - Initial contribution
40  */
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.airquality")
42 @NonNullByDefault
43 public class AirQualityHandlerFactory extends BaseThingHandlerFactory {
44     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(BRIDGE_TYPE_API, THING_TYPE_STATION);
45
46     private final TimeZoneProvider timeZoneProvider;
47     private final LocationProvider locationProvider;
48
49     @Activate
50     public AirQualityHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider,
51             final @Reference LocationProvider locationProvider) {
52         this.timeZoneProvider = timeZoneProvider;
53         this.locationProvider = locationProvider;
54     }
55
56     @Override
57     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
58         return SUPPORTED_THING_TYPES.contains(thingTypeUID);
59     }
60
61     @Override
62     protected @Nullable ThingHandler createHandler(Thing thing) {
63         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
64
65         return THING_TYPE_STATION.equals(thingTypeUID)
66                 ? new AirQualityStationHandler(thing, timeZoneProvider, locationProvider)
67                 : BRIDGE_TYPE_API.equals(thingTypeUID) ? new AirQualityBridgeHandler((Bridge) thing, locationProvider)
68                         : null;
69     }
70 }