]> git.basschouten.com Git - openhab-addons.git/blob
cbf13592f35679d0cd937e51e3fc2dc698d9cafa
[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.gardena.internal.handler;
14
15 import static org.openhab.binding.gardena.internal.GardenaBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.i18n.TimeZoneProvider;
20 import org.openhab.core.io.net.http.HttpClientFactory;
21 import org.openhab.core.io.net.http.WebSocketFactory;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.ThingHandlerFactory;
28 import org.osgi.service.component.annotations.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31
32 /**
33  * The {@link GardenaHandlerFactory} is responsible for creating Gardena things and thing handlers.
34  *
35  * @author Gerhard Riegler - Initial contribution
36  */
37 @NonNullByDefault
38 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.gardena")
39 public class GardenaHandlerFactory extends BaseThingHandlerFactory {
40     private HttpClientFactory httpClientFactory;
41     private WebSocketFactory webSocketFactory;
42     private TimeZoneProvider timeZoneProvider;
43
44     @Activate
45     public GardenaHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
46             final @Reference WebSocketFactory webSocketFactory, final @Reference TimeZoneProvider timeZoneProvider) {
47         this.httpClientFactory = httpClientFactory;
48         this.webSocketFactory = webSocketFactory;
49         this.timeZoneProvider = timeZoneProvider;
50     }
51
52     @Override
53     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
54         return BINDING_ID.equals(thingTypeUID.getBindingId());
55     }
56
57     @Override
58     protected @Nullable ThingHandler createHandler(Thing thing) {
59         if (THING_TYPE_ACCOUNT.equals(thing.getThingTypeUID())) {
60             return new GardenaAccountHandler((Bridge) thing, httpClientFactory, webSocketFactory, timeZoneProvider);
61         } else {
62             return new GardenaThingHandler(thing, timeZoneProvider);
63         }
64     }
65 }