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.homematic.internal.converter;
15 import org.openhab.binding.homematic.internal.model.HmDatapoint;
18 * Holds device specific infos for state invertion.
20 * @author Gerhard Riegler - Initial contribution
22 public class StateInvertInfo {
23 private String deviceType;
24 private int minChannel;
25 private int maxChannel;
28 * Creates a StateInvertInfo with the specified deviceType.
30 public StateInvertInfo(String deviceType) {
31 this(deviceType, -1, -1);
35 * Creates a StateInvertInfo with the specified deviceType and a channel range.
37 public StateInvertInfo(String deviceType, int minChannel, int maxChannel) {
38 this.deviceType = deviceType;
39 this.minChannel = minChannel;
40 this.maxChannel = maxChannel;
44 * Validates if the state of a datapoint must be inverted.
46 public boolean isToInvert(HmDatapoint dp) {
47 String dpDeviceType = dp.getChannel().getDevice().getType();
48 if (minChannel != -1) {
49 int dpChannelNumber = dp.getChannel().getNumber();
50 return dpDeviceType.startsWith(deviceType) && dpChannelNumber >= minChannel
51 && dpChannelNumber <= maxChannel;
53 return dpDeviceType.startsWith(deviceType);