2 * Copyright (c) 2010-2024 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.rotel.internal;
15 import static org.openhab.binding.rotel.internal.RotelBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
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;
36 * The {@link RotelHandlerFactory} is responsible for creating things and thing
39 * @author Laurent Garnier - Initial contribution
42 @Component(configurationPid = "binding.rotel", service = ThingHandlerFactory.class)
43 public class RotelHandlerFactory extends BaseThingHandlerFactory {
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()));
57 private final SerialPortManager serialPortManager;
58 private final RotelStateDescriptionOptionProvider stateDescriptionProvider;
59 private final RotelCommandDescriptionOptionProvider commandDescriptionProvider;
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;
71 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
72 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
76 protected @Nullable ThingHandler createHandler(Thing thing) {
77 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
79 if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
80 return new RotelHandler(thing, stateDescriptionProvider, commandDescriptionProvider, serialPortManager);