2 * Copyright (c) 2010-2022 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.nest.internal.sdm;
15 import static org.openhab.binding.nest.internal.sdm.SDMBindingConstants.*;
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;
36 * The {@link SDMThingHandlerFactory} is responsible for creating SDM thing handlers.
38 * @author Brian Higginbotham - Initial contribution
39 * @author Wouter Born - Initial contribution
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.nest")
43 public class SDMThingHandlerFactory extends BaseThingHandlerFactory {
45 private HttpClientFactory httpClientFactory;
46 private OAuthFactory oAuthFactory;
47 private final TimeZoneProvider timeZoneProvider;
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;
58 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
59 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
63 protected @Nullable ThingHandler createHandler(Thing thing) {
64 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);