]> git.basschouten.com Git - openhab-addons.git/blob
aa86722389435be939e776ec4d4bd85b1d002419
[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 that gives the state of all zones
21  * <p>
22  * <b>Syntax:</b>
23  *
24  * <pre>
25  * {@code
26  * ZMP,<Zone States>
27  * }
28  * </pre>
29  *
30  * <b>Example:</b>
31  * <p>
32  * Zones 2 and 9 are ON, all others are OFF, and Zones 31 and 32 are unassigned.
33  * In a bridged system, a system parameter S1 or S2 will be appended.
34  *
35  * <pre>
36  * ZMP,010000001000000000000000000000XX
37  * ZMP,00100000010000000000000000000000,S2
38  * </pre>
39  *
40  * @author Jeff Lauterbach - Initial Contribution
41  *
42  */
43 @NonNullByDefault
44 public class ZoneMapFeedback extends RadioRAFeedback {
45     private final Logger logger = LoggerFactory.getLogger(ZoneMapFeedback.class);
46
47     private String zoneStates; // 32 bit String of (0,1,X)
48     private int system; // 1 or 2, or 0 for none
49
50     public ZoneMapFeedback(String msg) {
51         String[] params = parse(msg, 1);
52
53         zoneStates = params[1];
54
55         system = 0;
56         if (params.length > 2) {
57             String sysParam = params[2].trim().toUpperCase();
58             if ("S1".equals(sysParam)) {
59                 system = 1;
60             } else if ("S2".equals(sysParam)) {
61                 system = 2;
62             } else {
63                 logger.debug("Invalid 2nd parameter {} in ZMP message. Should be S1 or S2.", sysParam);
64             }
65         }
66     }
67
68     public String getZoneStates() {
69         return zoneStates;
70     }
71
72     public char getZoneValue(int zone) {
73         if (zone < 1 || zone > zoneStates.length()) {
74             return 'X';
75         }
76
77         return zoneStates.charAt(zone - 1);
78     }
79
80     public int getSystem() {
81         return system;
82     }
83 }