]> git.basschouten.com Git - openhab-addons.git/blob
fb8f190b0d981bbb9759ced8859fa57d25536585
[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.tacmi.internal;
14
15 import static org.openhab.binding.tacmi.internal.TACmiBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jetty.client.HttpClient;
25 import org.openhab.binding.tacmi.internal.coe.TACmiCoEBridgeHandler;
26 import org.openhab.binding.tacmi.internal.coe.TACmiHandler;
27 import org.openhab.binding.tacmi.internal.schema.TACmiSchemaHandler;
28 import org.openhab.core.io.net.http.HttpClientFactory;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
33 import org.openhab.core.thing.binding.ThingHandler;
34 import org.openhab.core.thing.binding.ThingHandlerFactory;
35 import org.osgi.service.component.annotations.Activate;
36 import org.osgi.service.component.annotations.Component;
37 import org.osgi.service.component.annotations.Reference;
38
39 /**
40  * The {@link TACmiHandlerFactory} is responsible for creating things and thing
41  * handlers.
42  *
43  * @author Christian Niessner - Initial contribution
44  */
45 @NonNullByDefault
46 @Component(configurationPid = "binding.tacmi", service = ThingHandlerFactory.class)
47 public class TACmiHandlerFactory extends BaseThingHandlerFactory {
48
49     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
50             Stream.of(THING_TYPE_CMI, THING_TYPE_COE_BRIDGE, THING_TYPE_CMI_SCHEMA).collect(Collectors.toSet()));
51
52     private final HttpClient httpClient;
53     private final TACmiChannelTypeProvider channelTypeProvider;
54
55     @Activate
56     public TACmiHandlerFactory(@Reference HttpClientFactory httpClientFactory,
57             @Reference TACmiChannelTypeProvider channelTypeProvider) {
58         this.httpClient = httpClientFactory.getCommonHttpClient();
59         this.channelTypeProvider = channelTypeProvider;
60     }
61
62     @Override
63     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
65     }
66
67     @Override
68     protected @Nullable ThingHandler createHandler(Thing thing) {
69         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
70
71         if (THING_TYPE_CMI.equals(thingTypeUID)) {
72             return new TACmiHandler(thing);
73         } else if (THING_TYPE_COE_BRIDGE.equals(thingTypeUID)) {
74             return new TACmiCoEBridgeHandler((Bridge) thing);
75         } else if (THING_TYPE_CMI_SCHEMA.equals(thingTypeUID)) {
76             return new TACmiSchemaHandler(thing, httpClient, channelTypeProvider);
77         }
78
79         return null;
80     }
81 }