]> git.basschouten.com Git - openhab-addons.git/blob
595af45fe0fcbc307cd56903744318ef4aa72c22
[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.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.io.net.http.WebSocketFactory;
25 import org.openhab.core.io.transport.upnp.UpnpIOService;
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.Component;
32 import org.osgi.service.component.annotations.Reference;
33
34 /**
35  * The {@link SamsungTvHandlerFactory} is responsible for creating things and
36  * thing handlers.
37  *
38  * @author Pauli Anttila - Initial contribution
39  * @author Arjan Mels - Added Component annotation
40  */
41 @NonNullByDefault
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.samsungtv")
43 public class SamsungTvHandlerFactory extends BaseThingHandlerFactory {
44
45     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SAMSUNG_TV_THING_TYPE);
46
47     private @NonNullByDefault({}) UpnpIOService upnpIOService;
48     private @NonNullByDefault({}) UpnpService upnpService;
49
50     @Reference
51     private @NonNullByDefault({}) WebSocketFactory webSocketFactory;
52
53     @Override
54     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
56     }
57
58     @Override
59     protected @Nullable ThingHandler createHandler(Thing thing) {
60         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
61
62         if (thingTypeUID.equals(SAMSUNG_TV_THING_TYPE)) {
63             return new SamsungTvHandler(thing, upnpIOService, upnpService, webSocketFactory);
64         }
65
66         return null;
67     }
68
69     @Reference
70     protected void setUpnpIOService(UpnpIOService upnpIOService) {
71         this.upnpIOService = upnpIOService;
72     }
73
74     protected void unsetUpnpIOService(UpnpIOService upnpIOService) {
75         this.upnpIOService = null;
76     }
77
78     @Reference
79     protected void setUpnpService(UpnpService upnpService) {
80         this.upnpService = upnpService;
81     }
82
83     protected void unsetUpnpService(UpnpService upnpService) {
84         this.upnpService = null;
85     }
86 }