]> git.basschouten.com Git - openhab-addons.git/blob
e1156711012ff61ad3001dc9d14c4834f61ecc62
[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 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The {@link PLCPulseConfiguration} is a class for configuration
22  * of Siemens LOGO! PLC memory input/outputs blocks.
23  *
24  * @author Alexander Falkenstern - Initial contribution
25  */
26 @NonNullByDefault
27 public class PLCPulseConfiguration extends PLCMemoryConfiguration {
28
29     private @Nullable String observe;
30     private Integer pulse = 150;
31
32     /**
33      * Get observed Siemens LOGO! block name or memory address.
34      *
35      * @return Observed Siemens LOGO! block name or memory address
36      */
37     public String getObservedBlock() {
38         String result = observe;
39         if (result == null) {
40             result = getBlockName();
41             observe = result;
42         }
43         return result;
44     }
45
46     /**
47      * Set Siemens LOGO! block name or memory address to observe.
48      *
49      * @param name Siemens LOGO! memory block name or memory address
50      */
51     public void setObservedBlock(final String name) {
52         this.observe = name;
53     }
54
55     public String getObservedChannelType() {
56         String kind = getObservedBlockKind();
57         boolean isInput = kind.equalsIgnoreCase(I_DIGITAL) || kind.equalsIgnoreCase(NI_DIGITAL);
58         return isInput ? DIGITAL_INPUT_ITEM : DIGITAL_OUTPUT_ITEM;
59     }
60
61     public String getObservedBlockKind() {
62         String result = observe;
63         if (result == null) {
64             result = getBlockName();
65             observe = result;
66         }
67         return getBlockKind(result);
68     }
69
70     public Integer getPulseLength() {
71         return pulse;
72     }
73
74     public void setPulseLength(Integer pulse) {
75         this.pulse = pulse;
76     }
77 }