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.lcn.internal.common;
15 import java.util.function.BiFunction;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lcn.internal.LcnModuleHandler;
19 import org.openhab.binding.lcn.internal.connection.ModInfo;
20 import org.openhab.binding.lcn.internal.subhandler.AbstractLcnModuleSubHandler;
21 import org.openhab.binding.lcn.internal.subhandler.LcnModuleBinarySensorSubHandler;
22 import org.openhab.binding.lcn.internal.subhandler.LcnModuleCodeSubHandler;
23 import org.openhab.binding.lcn.internal.subhandler.LcnModuleHostCommandSubHandler;
24 import org.openhab.binding.lcn.internal.subhandler.LcnModuleKeyLockTableSubHandler;
25 import org.openhab.binding.lcn.internal.subhandler.LcnModuleLedSubHandler;
26 import org.openhab.binding.lcn.internal.subhandler.LcnModuleLogicSubHandler;
27 import org.openhab.binding.lcn.internal.subhandler.LcnModuleOperatingHoursCounterSubHandler;
28 import org.openhab.binding.lcn.internal.subhandler.LcnModuleOutputSubHandler;
29 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRelaySubHandler;
30 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRollershutterOutputSubHandler;
31 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRollershutterRelayPositionSubHandler;
32 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRollershutterRelaySlatAngleSubHandler;
33 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRvarLockSubHandler;
34 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRvarModeSubHandler;
35 import org.openhab.binding.lcn.internal.subhandler.LcnModuleRvarSetpointSubHandler;
36 import org.openhab.binding.lcn.internal.subhandler.LcnModuleS0CounterSubHandler;
37 import org.openhab.binding.lcn.internal.subhandler.LcnModuleThresholdSubHandler;
38 import org.openhab.binding.lcn.internal.subhandler.LcnModuleVariableSubHandler;
41 * Defines the supported channels of an LCN module handler.
43 * @author Fabian Wolter - Initial contribution
46 public enum LcnChannelGroup {
47 OUTPUT(4, LcnModuleOutputSubHandler::new),
48 ROLLERSHUTTEROUTPUT(1, LcnModuleRollershutterOutputSubHandler::new),
49 RELAY(8, LcnModuleRelaySubHandler::new),
50 ROLLERSHUTTERRELAY(4, LcnModuleRollershutterRelayPositionSubHandler::new),
51 ROLLERSHUTTERRELAYSLAT(4, LcnModuleRollershutterRelaySlatAngleSubHandler::new),
52 LED(12, LcnModuleLedSubHandler::new),
53 LOGIC(4, LcnModuleLogicSubHandler::new),
54 BINARYSENSOR(8, LcnModuleBinarySensorSubHandler::new),
55 VARIABLE(12, LcnModuleVariableSubHandler::new),
56 RVARSETPOINT(2, LcnModuleRvarSetpointSubHandler::new),
57 RVARMODE(2, LcnModuleRvarModeSubHandler::new),
58 RVARLOCK(2, LcnModuleRvarLockSubHandler::new),
59 THRESHOLDREGISTER1(5, LcnModuleThresholdSubHandler::new),
60 THRESHOLDREGISTER2(4, LcnModuleThresholdSubHandler::new),
61 THRESHOLDREGISTER3(4, LcnModuleThresholdSubHandler::new),
62 THRESHOLDREGISTER4(4, LcnModuleThresholdSubHandler::new),
63 S0INPUT(4, LcnModuleS0CounterSubHandler::new),
64 KEYLOCKTABLEA(8, LcnModuleKeyLockTableSubHandler::new),
65 KEYLOCKTABLEB(8, LcnModuleKeyLockTableSubHandler::new),
66 KEYLOCKTABLEC(8, LcnModuleKeyLockTableSubHandler::new),
67 KEYLOCKTABLED(8, LcnModuleKeyLockTableSubHandler::new),
68 CODE(0, LcnModuleCodeSubHandler::new),
69 OPERATINGHOURS(0, LcnModuleOperatingHoursCounterSubHandler::new),
70 HOSTCOMMAND(0, LcnModuleHostCommandSubHandler::new);
73 private BiFunction<LcnModuleHandler, ModInfo, ? extends AbstractLcnModuleSubHandler> handlerFactory;
75 private LcnChannelGroup(int count,
76 BiFunction<LcnModuleHandler, ModInfo, ? extends AbstractLcnModuleSubHandler> handlerFactory) {
78 this.handlerFactory = handlerFactory;
82 * Gets the number of Channels within the channel group.
84 * @return the Channel count
86 public int getCount() {
91 * Checks the given Channel id against the max. Channel count in this Channel group.
93 * @param number the number to check
94 * @return true, if the number is in the range
96 public boolean isValidId(int number) {
97 return number >= 0 && number < count;
101 * Gets the sub handler class to handle this Channel group.
103 * @return the sub handler class
105 public AbstractLcnModuleSubHandler createSubHandler(LcnModuleHandler handler, ModInfo info) {
106 return handlerFactory.apply(handler, info);
110 * Converts a given table ID into the corresponding Channel group.
112 * @param tableId to convert
113 * @return the channel group
114 * @throws LcnException when the ID is out of range
116 public static LcnChannelGroup fromTableId(int tableId) throws LcnException {
119 return KEYLOCKTABLEA;
121 return KEYLOCKTABLEB;
123 return KEYLOCKTABLEC;
125 return KEYLOCKTABLED;
127 throw new LcnException("Unknown key table ID: " + tableId);