]> git.basschouten.com Git - openhab-addons.git/blob
42ff36adca5ecab00da17a1c876393959e111d2f
[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.luftdateninfo.internal;
14
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;
32
33 /**
34  * The {@link LuftdatenInfoHandlerFactory} is responsible for creating things and thing
35  * handlers.
36  *
37  * @author Bernd Weymann - Initial contribution
38  */
39 @NonNullByDefault
40 @Component(configurationPid = "binding.luftdateninfo", service = ThingHandlerFactory.class)
41 public class LuftdatenInfoHandlerFactory extends BaseThingHandlerFactory {
42     protected final Logger logger = LoggerFactory.getLogger(LuftdatenInfoHandlerFactory.class);
43
44     @Activate
45     public LuftdatenInfoHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
46         HTTPHandler.init(httpClientFactory.getCommonHttpClient());
47     }
48
49     @Override
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));
54     }
55
56     @Override
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);
64         }
65         logger.info("Handler for {} not found", thing.getThingTypeUID());
66         return null;
67     }
68 }