2 * Copyright (c) 2010-2023 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.wwn;
15 import static org.openhab.binding.nest.internal.wwn.WWNBindingConstants.*;
17 import javax.ws.rs.client.ClientBuilder;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.nest.internal.wwn.handler.WWNAccountHandler;
22 import org.openhab.binding.nest.internal.wwn.handler.WWNCameraHandler;
23 import org.openhab.binding.nest.internal.wwn.handler.WWNSmokeDetectorHandler;
24 import org.openhab.binding.nest.internal.wwn.handler.WWNStructureHandler;
25 import org.openhab.binding.nest.internal.wwn.handler.WWNThermostatHandler;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Activate;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
35 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
38 * The {@link WWNThingHandlerFactory} is responsible for creating WWN thing handlers.
40 * @author David Bennett - Initial contribution
43 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.nest")
44 public class WWNThingHandlerFactory extends BaseThingHandlerFactory {
46 private final ClientBuilder clientBuilder;
47 private final SseEventSourceFactory eventSourceFactory;
50 public WWNThingHandlerFactory(@Reference ClientBuilder clientBuilder,
51 @Reference SseEventSourceFactory eventSourceFactory) {
52 this.clientBuilder = clientBuilder;
53 this.eventSourceFactory = eventSourceFactory;
57 * The things this factory supports creating.
60 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
65 * Creates a handler for the specific thing. This also creates the discovery service when the bridge is created.
68 protected @Nullable ThingHandler createHandler(Thing thing) {
69 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
71 if (THING_TYPE_ACCOUNT.equals(thingTypeUID)) {
72 return new WWNAccountHandler((Bridge) thing, clientBuilder, eventSourceFactory);
73 } else if (THING_TYPE_CAMERA.equals(thingTypeUID)) {
74 return new WWNCameraHandler(thing);
75 } else if (THING_TYPE_SMOKE_DETECTOR.equals(thingTypeUID)) {
76 return new WWNSmokeDetectorHandler(thing);
77 } else if (THING_TYPE_STRUCTURE.equals(thingTypeUID)) {
78 return new WWNStructureHandler(thing);
79 } else if (THING_TYPE_THERMOSTAT.equals(thingTypeUID)) {
80 return new WWNThermostatHandler(thing);