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.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;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.eclipse.jetty.client.HttpClient;
23 import org.eclipse.jetty.websocket.client.WebSocketClient;
24 import org.openhab.binding.orbitbhyve.internal.handler.OrbitBhyveBridgeHandler;
25 import org.openhab.binding.orbitbhyve.internal.handler.OrbitBhyveSprinklerHandler;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.openhab.core.io.net.http.WebSocketFactory;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.ThingHandlerFactory;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
39 * The {@link OrbitBhyveHandlerFactory} is responsible for creating things and thing
42 * @author Ondrej Pecta - Initial contribution
45 @Component(configurationPid = "binding.orbitbhyve", service = ThingHandlerFactory.class)
46 public class OrbitBhyveHandlerFactory extends BaseThingHandlerFactory {
48 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BRIDGE, THING_TYPE_SPRINKLER);
51 * the shared http client
53 private HttpClient httpClient;
56 * the shared web socket client
58 private WebSocketClient webSocketClient;
61 public OrbitBhyveHandlerFactory(@Reference HttpClientFactory httpClientFactory,
62 @Reference WebSocketFactory webSocketFactory) {
63 this.httpClient = httpClientFactory.getCommonHttpClient();
64 this.webSocketClient = webSocketFactory.getCommonWebSocketClient();
68 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
69 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
73 protected @Nullable ThingHandler createHandler(Thing thing) {
74 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
76 if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
77 return new OrbitBhyveBridgeHandler((Bridge) thing, httpClient, webSocketClient);
79 if (THING_TYPE_SPRINKLER.equals(thingTypeUID)) {
80 return new OrbitBhyveSprinklerHandler(thing);