]> git.basschouten.com Git - openhab-addons.git/blob
376f9dad181d9c8af4100712887b2dbed8b09f52
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.i18n.LocaleProvider;
26 import org.openhab.core.i18n.TranslationProvider;
27 import org.openhab.core.io.transport.serial.SerialPortManager;
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.Activate;
34 import org.osgi.service.component.annotations.Component;
35 import org.osgi.service.component.annotations.Reference;
36
37 /**
38  * The {@link RotelHandlerFactory} is responsible for creating things and thing
39  * handlers.
40  *
41  * @author Laurent Garnier - Initial contribution
42  */
43 @NonNullByDefault
44 @Component(configurationPid = "binding.rotel", service = ThingHandlerFactory.class)
45 public class RotelHandlerFactory extends BaseThingHandlerFactory {
46
47     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(Stream
48             .of(THING_TYPE_RSP1066, THING_TYPE_RSP1068, THING_TYPE_RSP1069, THING_TYPE_RSP1098, THING_TYPE_RSP1570,
49                     THING_TYPE_RSP1572, THING_TYPE_RSX1055, THING_TYPE_RSX1056, THING_TYPE_RSX1057, THING_TYPE_RSX1058,
50                     THING_TYPE_RSX1065, THING_TYPE_RSX1067, THING_TYPE_RSX1550, THING_TYPE_RSX1560, THING_TYPE_RSX1562,
51                     THING_TYPE_A11, THING_TYPE_A12, THING_TYPE_A14, THING_TYPE_CD11, THING_TYPE_CD14, THING_TYPE_RA11,
52                     THING_TYPE_RA12, THING_TYPE_RA1570, THING_TYPE_RA1572, THING_TYPE_RA1592, THING_TYPE_RAP1580,
53                     THING_TYPE_RC1570, THING_TYPE_RC1572, THING_TYPE_RC1590, THING_TYPE_RCD1570, THING_TYPE_RCD1572,
54                     THING_TYPE_RCX1500, THING_TYPE_RDD1580, THING_TYPE_RDG1520, THING_TYPE_RSP1576, THING_TYPE_RSP1582,
55                     THING_TYPE_RT09, THING_TYPE_RT11, THING_TYPE_RT1570, THING_TYPE_T11, THING_TYPE_T14)
56             .collect(Collectors.toSet()));
57
58     private final SerialPortManager serialPortManager;
59     private final RotelStateDescriptionOptionProvider stateDescriptionProvider;
60     private final TranslationProvider i18nProvider;
61     private final LocaleProvider localeProvider;
62
63     @Activate
64     public RotelHandlerFactory(final @Reference SerialPortManager serialPortManager,
65             final @Reference RotelStateDescriptionOptionProvider stateDescriptionProvider,
66             final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider) {
67         this.serialPortManager = serialPortManager;
68         this.stateDescriptionProvider = stateDescriptionProvider;
69         this.i18nProvider = i18nProvider;
70         this.localeProvider = localeProvider;
71     }
72
73     @Override
74     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
75         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
76     }
77
78     @Override
79     protected @Nullable ThingHandler createHandler(Thing thing) {
80         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
81
82         if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
83             return new RotelHandler(thing, stateDescriptionProvider, serialPortManager, i18nProvider, localeProvider);
84         }
85
86         return null;
87     }
88 }