]> git.basschouten.com Git - openhab-addons.git/blob
b758b4692c34e72fb8ae6dc24fbfc9e01df3742c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.BINDING_ID;
16 import static org.openhab.binding.gardena.internal.GardenaBindingConstants.THING_TYPE_ACCOUNT;
17
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;
32
33 /**
34  * The {@link GardenaHandlerFactory} is responsible for creating Gardena things and thing handlers.
35  *
36  * @author Gerhard Riegler - Initial contribution
37  */
38 @NonNullByDefault
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;
44
45     @Activate
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;
51     }
52
53     @Override
54     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55         return BINDING_ID.equals(thingTypeUID.getBindingId());
56     }
57
58     @Override
59     protected @Nullable ThingHandler createHandler(Thing thing) {
60         if (THING_TYPE_ACCOUNT.equals(thing.getThingTypeUID())) {
61             return new GardenaAccountHandler((Bridge) thing, httpClientFactory, webSocketFactory);
62         } else {
63             return new GardenaThingHandler(thing, timeZoneProvider);
64         }
65     }
66 }