]> git.basschouten.com Git - openhab-addons.git/blob
10cc18c409074444bdb8cad5c04db43c32d3ef40
[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.nest.internal.wwn;
14
15 import static org.openhab.binding.nest.internal.wwn.WWNBindingConstants.*;
16
17 import javax.ws.rs.client.ClientBuilder;
18
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;
36
37 /**
38  * The {@link WWNThingHandlerFactory} is responsible for creating WWN thing handlers.
39  *
40  * @author David Bennett - Initial contribution
41  */
42 @NonNullByDefault
43 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.nest")
44 public class WWNThingHandlerFactory extends BaseThingHandlerFactory {
45
46     private final ClientBuilder clientBuilder;
47     private final SseEventSourceFactory eventSourceFactory;
48
49     @Activate
50     public WWNThingHandlerFactory(@Reference ClientBuilder clientBuilder,
51             @Reference SseEventSourceFactory eventSourceFactory) {
52         this.clientBuilder = clientBuilder;
53         this.eventSourceFactory = eventSourceFactory;
54     }
55
56     /**
57      * The things this factory supports creating.
58      */
59     @Override
60     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
62     }
63
64     /**
65      * Creates a handler for the specific thing. This also creates the discovery service when the bridge is created.
66      */
67     @Override
68     protected @Nullable ThingHandler createHandler(Thing thing) {
69         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
70
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);
81         }
82
83         return null;
84     }
85 }