]> git.basschouten.com Git - openhab-addons.git/blob
a15cdf5359b32e911a08003551a94b7859132dae
[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.somfymylink.internal;
14
15 import static org.openhab.binding.somfymylink.internal.SomfyMyLinkBindingConstants.*;
16
17 import java.util.Arrays;
18 import java.util.HashSet;
19 import java.util.Set;
20
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;
35
36 /**
37  * @author Chris Johnson - Initial contribution
38  */
39 @NonNullByDefault
40 @Component(configurationPid = "binding.somfymylink", service = ThingHandlerFactory.class)
41 public class SomfyMyLinkHandlerFactory extends BaseThingHandlerFactory {
42
43     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>(
44             Arrays.asList(THING_TYPE_MYLINK, THING_TYPE_SHADE, THING_TYPE_SCENE));
45
46     public static final Set<ThingTypeUID> DISCOVERABLE_DEVICE_TYPES_UIDS = new HashSet<>(
47             Arrays.asList(THING_TYPE_SHADE, THING_TYPE_SCENE));
48
49     private @Nullable SomfyMyLinkStateDescriptionOptionsProvider stateDescriptionProvider;
50
51     @Override
52     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
53         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
54     }
55
56     @Override
57     protected @Nullable ThingHandler createHandler(Thing thing) {
58         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
59
60         if (thingTypeUID.equals(THING_TYPE_MYLINK)) {
61             return new SomfyMyLinkBridgeHandler((Bridge) thing, stateDescriptionProvider);
62         }
63         if (THING_TYPE_SHADE.equals(thingTypeUID)) {
64             return new SomfyShadeHandler(thing);
65         }
66         if (THING_TYPE_SCENE.equals(thingTypeUID)) {
67             return new SomfySceneHandler(thing);
68         }
69
70         return null;
71     }
72
73     @Reference
74     protected void setDynamicStateDescriptionProvider(SomfyMyLinkStateDescriptionOptionsProvider provider) {
75         this.stateDescriptionProvider = provider;
76     }
77
78     protected void unsetDynamicStateDescriptionProvider(SomfyMyLinkStateDescriptionOptionsProvider provider) {
79         this.stateDescriptionProvider = null;
80     }
81 }