]> git.basschouten.com Git - openhab-addons.git/blob
c2926ea680fb197b2a48fbecfd3c9fadd9f215d6
[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.homematic.internal.converter;
14
15 import org.openhab.binding.homematic.internal.model.HmDatapoint;
16
17 /**
18  * Holds device specific infos for state invertion.
19  *
20  * @author Gerhard Riegler - Initial contribution
21  */
22 public class StateInvertInfo {
23     private String deviceType;
24     private int minChannel;
25     private int maxChannel;
26
27     /**
28      * Creates a StateInvertInfo with the specified deviceType.
29      */
30     public StateInvertInfo(String deviceType) {
31         this(deviceType, -1, -1);
32     }
33
34     /**
35      * Creates a StateInvertInfo with the specified deviceType and a channel range.
36      */
37     public StateInvertInfo(String deviceType, int minChannel, int maxChannel) {
38         this.deviceType = deviceType;
39         this.minChannel = minChannel;
40         this.maxChannel = maxChannel;
41     }
42
43     /**
44      * Validates if the state of a datapoint must be inverted.
45      */
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;
52         } else {
53             return dpDeviceType.startsWith(deviceType);
54         }
55     }
56 }