]> git.basschouten.com Git - openhab-addons.git/blob
fc510b582121a471476f416fc104744b2f2238da
[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      * @throws SVDRPParseResponseException thrown if response data is not parseable
37      */
38     public static SVDRPTimerList parse(String message) {
39         SVDRPTimerList timers = new SVDRPTimerList();
40         List<String> lines = new ArrayList<String>();
41
42         StringTokenizer st = new StringTokenizer(message, System.lineSeparator());
43         while (st.hasMoreTokens()) {
44             String timer = st.nextToken();
45             lines.add(timer);
46         }
47         timers.setTimers(lines);
48         return timers;
49     }
50
51     /**
52      * Is there currently an active Recording on SVDRP Client
53      *
54      * @return returns true if there is an active recording
55      */
56     public boolean isRecordingActive() {
57         for (String line : timers) {
58             String timerContent = line.substring(line.indexOf(" ") + 1);
59             String timerStatus = timerContent.substring(0, timerContent.indexOf(":"));
60             byte b = Byte.parseByte(timerStatus);
61             if (((b >> 3) & 0x0001) == 1) {
62                 return true;
63             }
64         }
65         return false;
66     }
67
68     /**
69      * Set timers object of SVDRPTimerList
70      *
71      * @param timers timers to set
72      */
73     private void setTimers(List<String> timers) {
74         this.timers = timers;
75     }
76 }