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.samsungtv.internal;
15 import static org.openhab.binding.samsungtv.internal.SamsungTvBindingConstants.SAMSUNG_TV_THING_TYPE;
17 import java.util.Collections;
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;
35 * The {@link SamsungTvHandlerFactory} is responsible for creating things and
38 * @author Pauli Anttila - Initial contribution
39 * @author Arjan Mels - Added Component annotation
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.samsungtv")
43 public class SamsungTvHandlerFactory extends BaseThingHandlerFactory {
45 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(SAMSUNG_TV_THING_TYPE);
47 private @NonNullByDefault({}) UpnpIOService upnpIOService;
48 private @NonNullByDefault({}) UpnpService upnpService;
51 private @NonNullByDefault({}) WebSocketFactory webSocketFactory;
54 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
55 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
59 protected @Nullable ThingHandler createHandler(Thing thing) {
60 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
62 if (thingTypeUID.equals(SAMSUNG_TV_THING_TYPE)) {
63 return new SamsungTvHandler(thing, upnpIOService, upnpService, webSocketFactory);
70 protected void setUpnpIOService(UpnpIOService upnpIOService) {
71 this.upnpIOService = upnpIOService;
74 protected void unsetUpnpIOService(UpnpIOService upnpIOService) {
75 this.upnpIOService = null;
79 protected void setUpnpService(UpnpService upnpService) {
80 this.upnpService = upnpService;
83 protected void unsetUpnpService(UpnpService upnpService) {
84 this.upnpService = null;