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.tacmi.internal;
15 import static org.openhab.binding.tacmi.internal.TACmiBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
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;
40 * The {@link TACmiHandlerFactory} is responsible for creating things and thing
43 * @author Christian Niessner - Initial contribution
46 @Component(configurationPid = "binding.tacmi", service = ThingHandlerFactory.class)
47 public class TACmiHandlerFactory extends BaseThingHandlerFactory {
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()));
52 private final HttpClient httpClient;
53 private final TACmiChannelTypeProvider channelTypeProvider;
56 public TACmiHandlerFactory(@Reference HttpClientFactory httpClientFactory,
57 @Reference TACmiChannelTypeProvider channelTypeProvider) {
58 this.httpClient = httpClientFactory.getCommonHttpClient();
59 this.channelTypeProvider = channelTypeProvider;
63 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68 protected @Nullable ThingHandler createHandler(Thing thing) {
69 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);