]> git.basschouten.com Git - openhab-addons.git/blob
98d8a206b1641f262a32b0445740e6095076deb9
[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.nest.internal.sdm;
14
15 import static org.openhab.binding.nest.internal.sdm.SDMBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.nest.internal.sdm.handler.SDMAccountHandler;
20 import org.openhab.binding.nest.internal.sdm.handler.SDMCameraHandler;
21 import org.openhab.binding.nest.internal.sdm.handler.SDMThermostatHandler;
22 import org.openhab.core.auth.client.oauth2.OAuthFactory;
23 import org.openhab.core.i18n.TimeZoneProvider;
24 import org.openhab.core.io.net.http.HttpClientFactory;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
34
35 /**
36  * The {@link SDMThingHandlerFactory} is responsible for creating SDM thing handlers.
37  *
38  * @author Brian Higginbotham - Initial contribution
39  * @author Wouter Born - Initial contribution
40  */
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.nest")
42 @NonNullByDefault
43 public class SDMThingHandlerFactory extends BaseThingHandlerFactory {
44
45     private HttpClientFactory httpClientFactory;
46     private OAuthFactory oAuthFactory;
47     private final TimeZoneProvider timeZoneProvider;
48
49     @Activate
50     public SDMThingHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
51             final @Reference OAuthFactory oAuthFactory, final @Reference TimeZoneProvider timeZoneProvider) {
52         this.httpClientFactory = httpClientFactory;
53         this.oAuthFactory = oAuthFactory;
54         this.timeZoneProvider = timeZoneProvider;
55     }
56
57     @Override
58     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
59         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
60     }
61
62     @Override
63     protected @Nullable ThingHandler createHandler(Thing thing) {
64         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
65
66         if (thingTypeUID.equals(THING_TYPE_ACCOUNT)) {
67             return new SDMAccountHandler((Bridge) thing, httpClientFactory, oAuthFactory);
68         } else if (thingTypeUID.equals(THING_TYPE_CAMERA)) {
69             return new SDMCameraHandler(thing, timeZoneProvider);
70         } else if (thingTypeUID.equals(THING_TYPE_DISPLAY)) {
71             return new SDMCameraHandler(thing, timeZoneProvider);
72         } else if (thingTypeUID.equals(THING_TYPE_DOORBELL)) {
73             return new SDMCameraHandler(thing, timeZoneProvider);
74         } else if (thingTypeUID.equals(THING_TYPE_THERMOSTAT)) {
75             return new SDMThermostatHandler(thing, timeZoneProvider);
76         }
77
78         return null;
79     }
80 }