]> git.basschouten.com Git - openhab-addons.git/blob
283ac646c304be60bc4b03947534c4ccfba22e2b
[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.rotel.internal;
14
15 import static org.openhab.binding.rotel.internal.RotelBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.rotel.internal.handler.RotelHandler;
25 import org.openhab.core.io.transport.serial.SerialPortManager;
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.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
34
35 /**
36  * The {@link RotelHandlerFactory} is responsible for creating things and thing
37  * handlers.
38  *
39  * @author Laurent Garnier - Initial contribution
40  */
41 @NonNullByDefault
42 @Component(configurationPid = "binding.rotel", service = ThingHandlerFactory.class)
43 public class RotelHandlerFactory extends BaseThingHandlerFactory {
44
45     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(Stream
46             .of(THING_TYPE_RSP1066, THING_TYPE_RSP1068, THING_TYPE_RSP1069, THING_TYPE_RSP1098, THING_TYPE_RSP1570,
47                     THING_TYPE_RSP1572, THING_TYPE_RSX1055, THING_TYPE_RSX1056, THING_TYPE_RSX1057, THING_TYPE_RSX1058,
48                     THING_TYPE_RSX1065, THING_TYPE_RSX1067, THING_TYPE_RSX1550, THING_TYPE_RSX1560, THING_TYPE_RSX1562,
49                     THING_TYPE_A11, THING_TYPE_A12, THING_TYPE_A14, THING_TYPE_CD11, THING_TYPE_CD14, THING_TYPE_RA11,
50                     THING_TYPE_RA12, THING_TYPE_RA1570, THING_TYPE_RA1572, THING_TYPE_RA1592, THING_TYPE_RAP1580,
51                     THING_TYPE_RC1570, THING_TYPE_RC1572, THING_TYPE_RC1590, THING_TYPE_RCD1570, THING_TYPE_RCD1572,
52                     THING_TYPE_RCX1500, THING_TYPE_RDD1580, THING_TYPE_RDG1520, THING_TYPE_RSP1576, THING_TYPE_RSP1582,
53                     THING_TYPE_RT09, THING_TYPE_RT11, THING_TYPE_RT1570, THING_TYPE_T11, THING_TYPE_T14, THING_TYPE_C8,
54                     THING_TYPE_M8, THING_TYPE_P5, THING_TYPE_S5, THING_TYPE_X3, THING_TYPE_X5)
55             .collect(Collectors.toSet()));
56
57     private final SerialPortManager serialPortManager;
58     private final RotelStateDescriptionOptionProvider stateDescriptionProvider;
59     private final RotelCommandDescriptionOptionProvider commandDescriptionProvider;
60
61     @Activate
62     public RotelHandlerFactory(final @Reference SerialPortManager serialPortManager,
63             final @Reference RotelStateDescriptionOptionProvider stateDescriptionProvider,
64             final @Reference RotelCommandDescriptionOptionProvider commandDescriptionProvider) {
65         this.serialPortManager = serialPortManager;
66         this.stateDescriptionProvider = stateDescriptionProvider;
67         this.commandDescriptionProvider = commandDescriptionProvider;
68     }
69
70     @Override
71     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
72         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
73     }
74
75     @Override
76     protected @Nullable ThingHandler createHandler(Thing thing) {
77         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
78
79         if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
80             return new RotelHandler(thing, stateDescriptionProvider, commandDescriptionProvider, serialPortManager);
81         }
82
83         return null;
84     }
85 }