2 * Copyright (c) 2010-2020 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.remoteopenhab.internal;
15 import static org.openhab.binding.remoteopenhab.internal.RemoteopenhabBindingConstants.*;
17 import javax.ws.rs.client.ClientBuilder;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.remoteopenhab.internal.handler.RemoteopenhabBridgeHandler;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.ThingHandlerFactory;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
33 import com.google.gson.FieldNamingPolicy;
34 import com.google.gson.Gson;
35 import com.google.gson.GsonBuilder;
38 * The {@link RemoteopenhabHandlerFactory} is responsible for creating things and thing
41 * @author Laurent Garnier - Initial contribution
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.remoteopenhab")
45 public class RemoteopenhabHandlerFactory extends BaseThingHandlerFactory {
47 private final ClientBuilder clientBuilder;
48 private final SseEventSourceFactory eventSourceFactory;
49 private final RemoteopenhabChannelTypeProvider channelTypeProvider;
50 private final RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider;
51 private final Gson jsonParser;
54 public RemoteopenhabHandlerFactory(final @Reference ClientBuilder clientBuilder,
55 final @Reference SseEventSourceFactory eventSourceFactory,
56 final @Reference RemoteopenhabChannelTypeProvider channelTypeProvider,
57 final @Reference RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider) {
58 this.clientBuilder = clientBuilder;
59 this.eventSourceFactory = eventSourceFactory;
60 this.channelTypeProvider = channelTypeProvider;
61 this.stateDescriptionProvider = stateDescriptionProvider;
62 jsonParser = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create();
66 * The things this factory supports creating.
69 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
70 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
74 * Creates a handler for the specific thing.
77 protected @Nullable ThingHandler createHandler(Thing thing) {
78 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
80 return BRIDGE_TYPE_SERVER.equals(thingTypeUID)
81 ? new RemoteopenhabBridgeHandler((Bridge) thing, clientBuilder, eventSourceFactory, channelTypeProvider,
82 stateDescriptionProvider, jsonParser)