2 * Copyright (c) 2010-2022 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.homeconnect.internal.factory;
15 import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants.*;
17 import javax.ws.rs.client.ClientBuilder;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.openhab.binding.homeconnect.internal.handler.HomeConnectBridgeHandler;
23 import org.openhab.binding.homeconnect.internal.handler.HomeConnectCoffeeMakerHandler;
24 import org.openhab.binding.homeconnect.internal.handler.HomeConnectCooktopHandler;
25 import org.openhab.binding.homeconnect.internal.handler.HomeConnectDishwasherHandler;
26 import org.openhab.binding.homeconnect.internal.handler.HomeConnectDryerHandler;
27 import org.openhab.binding.homeconnect.internal.handler.HomeConnectFridgeFreezerHandler;
28 import org.openhab.binding.homeconnect.internal.handler.HomeConnectHoodHandler;
29 import org.openhab.binding.homeconnect.internal.handler.HomeConnectOvenHandler;
30 import org.openhab.binding.homeconnect.internal.handler.HomeConnectWasherDryerHandler;
31 import org.openhab.binding.homeconnect.internal.handler.HomeConnectWasherHandler;
32 import org.openhab.binding.homeconnect.internal.servlet.HomeConnectServlet;
33 import org.openhab.binding.homeconnect.internal.type.HomeConnectDynamicStateDescriptionProvider;
34 import org.openhab.core.auth.client.oauth2.OAuthFactory;
35 import org.openhab.core.io.net.http.HttpClientFactory;
36 import org.openhab.core.thing.Bridge;
37 import org.openhab.core.thing.Thing;
38 import org.openhab.core.thing.ThingTypeUID;
39 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
40 import org.openhab.core.thing.binding.ThingHandler;
41 import org.openhab.core.thing.binding.ThingHandlerFactory;
42 import org.osgi.service.component.annotations.Activate;
43 import org.osgi.service.component.annotations.Component;
44 import org.osgi.service.component.annotations.Reference;
45 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
48 * The {@link HomeConnectHandlerFactory} is responsible for creating things and thing
51 * @author Jonas BrĂ¼stel - Initial contribution
54 @Component(configurationPid = "binding.homeconnect", service = ThingHandlerFactory.class)
55 public class HomeConnectHandlerFactory extends BaseThingHandlerFactory {
57 private final HttpClient httpClient;
58 private final ClientBuilder clientBuilder;
59 private final SseEventSourceFactory eventSourceFactory;
60 private final OAuthFactory oAuthFactory;
61 private final HomeConnectDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
62 private final HomeConnectServlet homeConnectServlet;
65 public HomeConnectHandlerFactory(@Reference HttpClientFactory httpClientFactory,
66 @Reference ClientBuilder clientBuilder, @Reference SseEventSourceFactory eventSourceFactory,
67 @Reference OAuthFactory oAuthFactory,
68 @Reference HomeConnectDynamicStateDescriptionProvider dynamicStateDescriptionProvider,
69 @Reference HomeConnectServlet homeConnectServlet) {
70 this.httpClient = httpClientFactory.getCommonHttpClient();
71 this.clientBuilder = clientBuilder;
72 this.eventSourceFactory = eventSourceFactory;
73 this.oAuthFactory = oAuthFactory;
74 this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider;
75 this.homeConnectServlet = homeConnectServlet;
79 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
80 return SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID);
84 protected @Nullable ThingHandler createHandler(Thing thing) {
85 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
87 if (THING_TYPE_API_BRIDGE.equals(thingTypeUID)) {
88 return new HomeConnectBridgeHandler((Bridge) thing, httpClient, clientBuilder, eventSourceFactory,
89 oAuthFactory, homeConnectServlet);
90 } else if (THING_TYPE_DISHWASHER.equals(thingTypeUID)) {
91 return new HomeConnectDishwasherHandler(thing, dynamicStateDescriptionProvider);
92 } else if (THING_TYPE_OVEN.equals(thingTypeUID)) {
93 return new HomeConnectOvenHandler(thing, dynamicStateDescriptionProvider);
94 } else if (THING_TYPE_WASHER.equals(thingTypeUID)) {
95 return new HomeConnectWasherHandler(thing, dynamicStateDescriptionProvider);
96 } else if (THING_TYPE_WASHER_DRYER.equals(thingTypeUID)) {
97 return new HomeConnectWasherDryerHandler(thing, dynamicStateDescriptionProvider);
98 } else if (THING_TYPE_DRYER.equals(thingTypeUID)) {
99 return new HomeConnectDryerHandler(thing, dynamicStateDescriptionProvider);
100 } else if (THING_TYPE_FRIDGE_FREEZER.equals(thingTypeUID)) {
101 return new HomeConnectFridgeFreezerHandler(thing, dynamicStateDescriptionProvider);
102 } else if (THING_TYPE_COFFEE_MAKER.equals(thingTypeUID)) {
103 return new HomeConnectCoffeeMakerHandler(thing, dynamicStateDescriptionProvider);
104 } else if (THING_TYPE_HOOD.equals(thingTypeUID)) {
105 return new HomeConnectHoodHandler(thing, dynamicStateDescriptionProvider);
106 } else if (THING_TYPE_COOKTOP.equals(thingTypeUID)) {
107 return new HomeConnectCooktopHandler(thing, dynamicStateDescriptionProvider);