2 * Copyright (c) 2010-2021 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.gardena.internal.handler;
15 import static org.openhab.binding.gardena.internal.GardenaBindingConstants.BINDING_ID;
16 import static org.openhab.binding.gardena.internal.GardenaBindingConstants.THING_TYPE_ACCOUNT;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.i18n.TimeZoneProvider;
21 import org.openhab.core.io.net.http.HttpClientFactory;
22 import org.openhab.core.io.net.http.WebSocketFactory;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
34 * The {@link GardenaHandlerFactory} is responsible for creating Gardena things and thing handlers.
36 * @author Gerhard Riegler - Initial contribution
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.gardena")
40 public class GardenaHandlerFactory extends BaseThingHandlerFactory {
41 private HttpClientFactory httpClientFactory;
42 private WebSocketFactory webSocketFactory;
43 private TimeZoneProvider timeZoneProvider;
46 public GardenaHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
47 final @Reference WebSocketFactory webSocketFactory, final @Reference TimeZoneProvider timeZoneProvider) {
48 this.httpClientFactory = httpClientFactory;
49 this.webSocketFactory = webSocketFactory;
50 this.timeZoneProvider = timeZoneProvider;
54 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55 return BINDING_ID.equals(thingTypeUID.getBindingId());
59 protected @Nullable ThingHandler createHandler(Thing thing) {
60 if (THING_TYPE_ACCOUNT.equals(thing.getThingTypeUID())) {
61 return new GardenaAccountHandler((Bridge) thing, httpClientFactory, webSocketFactory);
63 return new GardenaThingHandler(thing, timeZoneProvider);