]> git.basschouten.com Git - openhab-addons.git/blob
3e647a0f4515b82dbc9db7893492646e4763c828
[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.vdr.internal.svdrp;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.StringTokenizer;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * The {@link SVDRPTimerList} contains SVDRP Response Data for a Timer list
23  *
24  * @author Matthias Klocke - Initial contribution
25  */
26 @NonNullByDefault
27 public class SVDRPTimerList {
28
29     private List<String> timers = new ArrayList<String>();
30
31     /**
32      * parse object from SVDRP Client Response
33      *
34      * @param message SVDRP Client Response
35      * @return Timer List Object
36      */
37     public static SVDRPTimerList parse(String message) {
38         SVDRPTimerList timers = new SVDRPTimerList();
39         List<String> lines = new ArrayList<String>();
40
41         StringTokenizer st = new StringTokenizer(message, System.lineSeparator());
42         while (st.hasMoreTokens()) {
43             String timer = st.nextToken();
44             lines.add(timer);
45         }
46         timers.setTimers(lines);
47         return timers;
48     }
49
50     /**
51      * Is there currently an active Recording on SVDRP Client
52      *
53      * @return returns true if there is an active recording
54      */
55     public boolean isRecordingActive() {
56         for (String line : timers) {
57             String timerContent = line.substring(line.indexOf(" ") + 1);
58             String timerStatus = timerContent.substring(0, timerContent.indexOf(":"));
59             byte b = Byte.parseByte(timerStatus);
60             if (((b >> 3) & 0x0001) == 1) {
61                 return true;
62             }
63         }
64         return false;
65     }
66
67     /**
68      * Set timers object of SVDRPTimerList
69      *
70      * @param timers timers to set
71      */
72     private void setTimers(List<String> timers) {
73         this.timers = timers;
74     }
75 }