]> git.basschouten.com Git - openhab-addons.git/blob
59f98aedf1bc832a230d7421d4d1f83741a6f323
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.samsungtv.internal;
14
15 import static org.openhab.binding.samsungtv.internal.SamsungTvBindingConstants.SAMSUNG_TV_THING_TYPE;
16
17 import java.util.Collections;
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.jupnp.UpnpService;
23 import org.openhab.binding.samsungtv.internal.handler.SamsungTvHandler;
24 import org.openhab.core.config.discovery.DiscoveryServiceRegistry;
25 import org.openhab.core.io.net.http.WebSocketFactory;
26 import org.openhab.core.io.transport.upnp.UpnpIOService;
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.Component;
33 import org.osgi.service.component.annotations.Reference;
34
35 /**
36  * The {@link SamsungTvHandlerFactory} is responsible for creating things and
37  * thing handlers.
38  *
39  * @author Pauli Anttila - Initial contribution
40  * @author Arjan Mels - Added Component annotation
41  */
42 @NonNullByDefault
43 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.samsungtv")
44 public class SamsungTvHandlerFactory extends BaseThingHandlerFactory {
45
46     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SAMSUNG_TV_THING_TYPE);
47
48     private @NonNullByDefault({}) UpnpIOService upnpIOService;
49     private @NonNullByDefault({}) DiscoveryServiceRegistry discoveryServiceRegistry;
50     private @NonNullByDefault({}) UpnpService upnpService;
51
52     @Reference
53     private @NonNullByDefault({}) WebSocketFactory webSocketFactory;
54
55     @Override
56     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
58     }
59
60     @Override
61     protected @Nullable ThingHandler createHandler(Thing thing) {
62         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
63
64         if (thingTypeUID.equals(SAMSUNG_TV_THING_TYPE)) {
65             return new SamsungTvHandler(thing, upnpIOService, discoveryServiceRegistry, upnpService, webSocketFactory);
66         }
67
68         return null;
69     }
70
71     @Reference
72     protected void setUpnpIOService(UpnpIOService upnpIOService) {
73         this.upnpIOService = upnpIOService;
74     }
75
76     protected void unsetUpnpIOService(UpnpIOService upnpIOService) {
77         this.upnpIOService = null;
78     }
79
80     @Reference
81     protected void setDiscoveryServiceRegistry(DiscoveryServiceRegistry discoveryServiceRegistry) {
82         this.discoveryServiceRegistry = discoveryServiceRegistry;
83     }
84
85     protected void unsetDiscoveryServiceRegistry(DiscoveryServiceRegistry discoveryServiceRegistry) {
86         this.discoveryServiceRegistry = null;
87     }
88
89     @Reference
90     protected void setUpnpService(UpnpService upnpService) {
91         this.upnpService = upnpService;
92     }
93
94     protected void unsetUpnpService(UpnpService upnpService) {
95         this.upnpService = null;
96     }
97 }