2 * Copyright (c) 2010-2024 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.airquality.internal;
15 import static org.openhab.binding.airquality.internal.AirQualityBindingConstants.*;
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;
36 * The {@link AirQualityHandlerFactory} is responsible for creating thing and thing
39 * @author Gaƫl L'hopital - Initial contribution
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.airquality")
43 public class AirQualityHandlerFactory extends BaseThingHandlerFactory {
44 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(BRIDGE_TYPE_API, THING_TYPE_STATION);
46 private final TimeZoneProvider timeZoneProvider;
47 private final LocationProvider locationProvider;
50 public AirQualityHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider,
51 final @Reference LocationProvider locationProvider) {
52 this.timeZoneProvider = timeZoneProvider;
53 this.locationProvider = locationProvider;
57 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
58 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
62 protected @Nullable ThingHandler createHandler(Thing thing) {
63 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
65 return THING_TYPE_STATION.equals(thingTypeUID)
66 ? new AirQualityStationHandler(thing, timeZoneProvider, locationProvider)
67 : BRIDGE_TYPE_API.equals(thingTypeUID) ? new AirQualityBridgeHandler((Bridge) thing, locationProvider)