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.somfymylink.internal;
15 import static org.openhab.binding.somfymylink.internal.SomfyMyLinkBindingConstants.*;
17 import java.util.Arrays;
18 import java.util.HashSet;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.somfymylink.internal.handler.SomfyMyLinkBridgeHandler;
24 import org.openhab.binding.somfymylink.internal.handler.SomfyMyLinkStateDescriptionOptionsProvider;
25 import org.openhab.binding.somfymylink.internal.handler.SomfySceneHandler;
26 import org.openhab.binding.somfymylink.internal.handler.SomfyShadeHandler;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
37 * @author Chris Johnson - Initial contribution
40 @Component(configurationPid = "binding.somfymylink", service = ThingHandlerFactory.class)
41 public class SomfyMyLinkHandlerFactory extends BaseThingHandlerFactory {
43 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>(
44 Arrays.asList(THING_TYPE_MYLINK, THING_TYPE_SHADE, THING_TYPE_SCENE));
46 public static final Set<ThingTypeUID> DISCOVERABLE_DEVICE_TYPES_UIDS = new HashSet<>(
47 Arrays.asList(THING_TYPE_SHADE, THING_TYPE_SCENE));
49 private @Nullable SomfyMyLinkStateDescriptionOptionsProvider stateDescriptionProvider;
52 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
53 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60 if (thingTypeUID.equals(THING_TYPE_MYLINK)) {
61 return new SomfyMyLinkBridgeHandler((Bridge) thing, stateDescriptionProvider);
63 if (THING_TYPE_SHADE.equals(thingTypeUID)) {
64 return new SomfyShadeHandler(thing);
66 if (THING_TYPE_SCENE.equals(thingTypeUID)) {
67 return new SomfySceneHandler(thing);
74 protected void setDynamicStateDescriptionProvider(SomfyMyLinkStateDescriptionOptionsProvider provider) {
75 this.stateDescriptionProvider = provider;
78 protected void unsetDynamicStateDescriptionProvider(SomfyMyLinkStateDescriptionOptionsProvider provider) {
79 this.stateDescriptionProvider = null;