]> git.basschouten.com Git - openhab-addons.git/blob
dd2db9f1f1531c335d26764e35822cbad4aab51f
[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.easee.internal;
14
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.openhab.binding.easee.internal.handler.EaseeChargerHandler;
21 import org.openhab.binding.easee.internal.handler.EaseeMasterChargerHandler;
22 import org.openhab.binding.easee.internal.handler.EaseeSiteHandler;
23 import org.openhab.core.io.net.http.HttpClientFactory;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Activate;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Reference;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * The {@link EaseeHandlerFactory} is responsible for creating things and thing
38  * handlers.
39  *
40  * @author Alexander Friese - Initial contribution
41  */
42 @NonNullByDefault
43 @Component(configurationPid = "binding.easee", service = ThingHandlerFactory.class)
44 public class EaseeHandlerFactory extends BaseThingHandlerFactory {
45
46     private final Logger logger = LoggerFactory.getLogger(EaseeHandlerFactory.class);
47
48     /**
49      * the shared http client
50      */
51     private final HttpClient httpClient;
52
53     @Activate
54     public EaseeHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
55         this.httpClient = httpClientFactory.getCommonHttpClient();
56     }
57
58     @Override
59     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
60         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
61     }
62
63     @Override
64     protected @Nullable ThingHandler createHandler(Thing thing) {
65         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
66
67         if (THING_TYPE_SITE.equals(thingTypeUID)) {
68             return new EaseeSiteHandler((Bridge) thing, httpClient);
69         } else if (THING_TYPE_MASTER_CHARGER.equals(thingTypeUID)) {
70             return new EaseeMasterChargerHandler(thing);
71         } else if (THING_TYPE_CHARGER.equals(thingTypeUID)) {
72             return new EaseeChargerHandler(thing);
73         } else {
74             logger.warn("Unsupported Thing-Type: {}", thingTypeUID.getAsString());
75         }
76
77         return null;
78     }
79 }