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.luftdateninfo.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.luftdateninfo.internal.handler.ConditionHandler;
18 import org.openhab.binding.luftdateninfo.internal.handler.HTTPHandler;
19 import org.openhab.binding.luftdateninfo.internal.handler.NoiseHandler;
20 import org.openhab.binding.luftdateninfo.internal.handler.PMHandler;
21 import org.openhab.core.io.net.http.HttpClientFactory;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.ThingTypeUID;
24 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.thing.binding.ThingHandlerFactory;
27 import org.osgi.service.component.annotations.Activate;
28 import org.osgi.service.component.annotations.Component;
29 import org.osgi.service.component.annotations.Reference;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link LuftdatenInfoHandlerFactory} is responsible for creating things and thing
37 * @author Bernd Weymann - Initial contribution
40 @Component(configurationPid = "binding.luftdateninfo", service = ThingHandlerFactory.class)
41 public class LuftdatenInfoHandlerFactory extends BaseThingHandlerFactory {
42 protected final Logger logger = LoggerFactory.getLogger(LuftdatenInfoHandlerFactory.class);
45 public LuftdatenInfoHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
46 HTTPHandler.init(httpClientFactory.getCommonHttpClient());
50 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51 return (thingTypeUID.equals(LuftdatenInfoBindingConstants.THING_TYPE_PARTICULATE)
52 || thingTypeUID.equals(LuftdatenInfoBindingConstants.THING_TYPE_CONDITIONS)
53 || thingTypeUID.equals(LuftdatenInfoBindingConstants.THING_TYPE_NOISE));
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 if (thing.getThingTypeUID().equals(LuftdatenInfoBindingConstants.THING_TYPE_PARTICULATE)) {
59 return new PMHandler(thing);
60 } else if (thing.getThingTypeUID().equals(LuftdatenInfoBindingConstants.THING_TYPE_CONDITIONS)) {
61 return new ConditionHandler(thing);
62 } else if (thing.getThingTypeUID().equals(LuftdatenInfoBindingConstants.THING_TYPE_NOISE)) {
63 return new NoiseHandler(thing);
65 logger.info("Handler for {} not found", thing.getThingTypeUID());