]> git.basschouten.com Git - openhab-addons.git/blob
dd73844bbc342940000ed25af495955f91dc35ba
[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.lutron.internal.radiora.protocol;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Feedback for when a device was changed locally (not through Master Control)
21  * <p>
22  * <b>Syntax:</b>
23  *
24  * <pre>
25  * {@code
26  * LZC,<Zone Number>,<State>
27  * }
28  * </pre>
29  *
30  * <b>Examples:</b>
31  * <p>
32  * Dimmer 1 changed from 100% to 50%
33  *
34  * <pre>
35  * LZC,01,CHG
36  * </pre>
37  *
38  * Dimmer 4 changed from OFF to 25%
39  *
40  * <pre>
41  * LZC,04,ON
42  * </pre>
43  *
44  * In a bridged system, a system parameter S1 or S2 will be appended.
45  *
46  * <pre>
47  * LZC,04,ON,S2
48  * </pre>
49  *
50  * @author Jeff Lauterbach - Initial Contribution
51  *
52  */
53 @NonNullByDefault
54 public class LocalZoneChangeFeedback extends RadioRAFeedback {
55     private final Logger logger = LoggerFactory.getLogger(LocalZoneChangeFeedback.class);
56
57     private int zoneNumber; // 1 to 32
58     private State state; // ON, OFF, CHG
59     private int system; // 1 or 2, or 0 for none
60
61     public enum State {
62         ON,
63         OFF,
64         CHG
65     }
66
67     public LocalZoneChangeFeedback(String msg) {
68         String[] params = parse(msg, 2);
69
70         zoneNumber = Integer.parseInt(params[1].trim());
71         state = State.valueOf(params[2].trim().toUpperCase());
72
73         system = 0;
74         if (params.length > 3) {
75             String sysParam = params[3].trim().toUpperCase();
76             if ("S1".equals(sysParam)) {
77                 system = 1;
78             } else if ("S2".equals(sysParam)) {
79                 system = 2;
80             } else {
81                 logger.debug("Invalid 3rd parameter {} in LZC message. Should be S1 or S2.", sysParam);
82             }
83         }
84     }
85
86     public State getState() {
87         return state;
88     }
89
90     public int getZoneNumber() {
91         return zoneNumber;
92     }
93
94     public int getSystem() {
95         return system;
96     }
97 }