2 * Copyright (c) 2010-2021 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.orbitbhyve.internal;
15 import static org.openhab.binding.orbitbhyve.internal.OrbitBhyveBindingConstants.THING_TYPE_BRIDGE;
16 import static org.openhab.binding.orbitbhyve.internal.OrbitBhyveBindingConstants.THING_TYPE_SPRINKLER;
18 import java.util.HashSet;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.eclipse.jetty.client.HttpClient;
24 import org.eclipse.jetty.websocket.client.WebSocketClient;
25 import org.openhab.binding.orbitbhyve.internal.handler.OrbitBhyveBridgeHandler;
26 import org.openhab.binding.orbitbhyve.internal.handler.OrbitBhyveSprinklerHandler;
27 import org.openhab.core.io.net.http.HttpClientFactory;
28 import org.openhab.core.io.net.http.WebSocketFactory;
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 OrbitBhyveHandlerFactory} is responsible for creating things and thing
43 * @author Ondrej Pecta - Initial contribution
46 @Component(configurationPid = "binding.orbitbhyve", service = ThingHandlerFactory.class)
47 public class OrbitBhyveHandlerFactory extends BaseThingHandlerFactory {
49 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BRIDGE, THING_TYPE_SPRINKLER);
52 * the shared http client
54 private HttpClient httpClient;
57 * the shared web socket client
59 private WebSocketClient webSocketClient;
62 public OrbitBhyveHandlerFactory(@Reference HttpClientFactory httpClientFactory,
63 @Reference WebSocketFactory webSocketFactory) {
64 this.httpClient = httpClientFactory.getCommonHttpClient();
65 this.webSocketClient = webSocketFactory.getCommonWebSocketClient();
69 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
70 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
74 protected @Nullable ThingHandler createHandler(Thing thing) {
75 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
77 if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
78 return new OrbitBhyveBridgeHandler((Bridge) thing, httpClient, webSocketClient);
80 if (THING_TYPE_SPRINKLER.equals(thingTypeUID)) {
81 return new OrbitBhyveSprinklerHandler(thing);