]> git.basschouten.com Git - openhab-addons.git/blob
82e7c0d0c5977bb532b685cbd138a63b2bd91e08
[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.plclogo.internal.config;
14
15 import static org.openhab.binding.plclogo.internal.PLCLogoBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * The {@link PLCMemoryConfiguration} is a class for configuration
21  * of Siemens LOGO! PLC memory input/outputs blocks.
22  *
23  * @author Alexander Falkenstern - Initial contribution
24  */
25 @NonNullByDefault
26 public class PLCMemoryConfiguration extends PLCCommonConfiguration {
27
28     private String block = "";
29     private Integer threshold = 0;
30
31     /**
32      * Get configured Siemens LOGO! memory block name.
33      *
34      * @return Configured Siemens LOGO! memory block name
35      */
36     public String getBlockName() {
37         return block;
38     }
39
40     /**
41      * Set Siemens LOGO! memory block name.
42      *
43      * @param name Siemens LOGO! memory block name
44      */
45     public void setBlockName(final String name) {
46         this.block = name.trim();
47     }
48
49     /**
50      * Get Siemens LOGO! blocks update threshold.
51      *
52      * @return Configured Siemens LOGO! update threshold
53      */
54     public Integer getThreshold() {
55         return threshold;
56     }
57
58     /**
59      * Set Siemens LOGO! blocks update threshold.
60      *
61      * @param force Force update of Siemens LOGO! blocks
62      */
63     public void setThreshold(final Integer threshold) {
64         this.threshold = threshold;
65     }
66
67     @Override
68     public String getChannelType() {
69         final String kind = getBlockKind();
70         return kind.equalsIgnoreCase(MEMORY_BYTE) && block.contains(".") ? DIGITAL_OUTPUT_ITEM : ANALOG_ITEM;
71     }
72
73     @Override
74     public String getBlockKind() {
75         return getBlockKind(block);
76     }
77
78     protected static String getBlockKind(final String name) {
79         String kind = "Unknown";
80         if (Character.isDigit(name.charAt(1))) {
81             kind = name.substring(0, 1);
82         } else if (Character.isDigit(name.charAt(2))) {
83             kind = name.substring(0, 2);
84         } else if (Character.isDigit(name.charAt(3))) {
85             kind = name.substring(0, 3);
86         }
87         return kind;
88     }
89 }