]> git.basschouten.com Git - openhab-addons.git/blob
bf4919610c9fef998f7bfc65b774397151d98f4c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.homeconnect.internal.factory;
14
15 import static org.openhab.binding.homeconnect.internal.HomeConnectBindingConstants.*;
16
17 import javax.ws.rs.client.ClientBuilder;
18
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;
46
47 /**
48  * The {@link HomeConnectHandlerFactory} is responsible for creating things and thing
49  * handlers.
50  *
51  * @author Jonas BrĂ¼stel - Initial contribution
52  */
53 @NonNullByDefault
54 @Component(configurationPid = "binding.homeconnect", service = ThingHandlerFactory.class)
55 public class HomeConnectHandlerFactory extends BaseThingHandlerFactory {
56
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;
63
64     @Activate
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;
76     }
77
78     @Override
79     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
80         return SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID);
81     }
82
83     @Override
84     protected @Nullable ThingHandler createHandler(Thing thing) {
85         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
86
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);
108         }
109
110         return null;
111     }
112 }