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.easee.internal;
15 import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
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;
37 * The {@link EaseeHandlerFactory} is responsible for creating things and thing
40 * @author Alexander Friese - Initial contribution
43 @Component(configurationPid = "binding.easee", service = ThingHandlerFactory.class)
44 public class EaseeHandlerFactory extends BaseThingHandlerFactory {
46 private final Logger logger = LoggerFactory.getLogger(EaseeHandlerFactory.class);
49 * the shared http client
51 private final HttpClient httpClient;
54 public EaseeHandlerFactory(final @Reference HttpClientFactory httpClientFactory) {
55 this.httpClient = httpClientFactory.getCommonHttpClient();
59 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
60 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
64 protected @Nullable ThingHandler createHandler(Thing thing) {
65 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);
74 logger.warn("Unsupported Thing-Type: {}", thingTypeUID.getAsString());