]> git.basschouten.com Git - openhab-addons.git/blob
d6ef681a77e534cb4eb40588dd6427a94317cd1b
[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.tivo.internal.service;
14
15 import java.util.Date;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * TivoStatusData class stores the data from the last status query from the TiVo and any other errors / status
21  * codes.
22  *
23  * @author Jayson Kubilis (DigitalBytes) - Initial contribution
24  * @author Andrew Black (AndyXMB) - minor updates, removal of unused functions.
25  * @author Michael Lobstein - Updated for OH3
26  */
27
28 @NonNullByDefault
29 public class TivoStatusData {
30     private boolean cmdOk = false;
31     private Date time = new Date();
32     private int channelNum = -1;
33     private int subChannelNum = -1;
34     private boolean isRecording = false;
35     private String msg = "NO STATUS QUERIED YET";
36     private boolean pubToUI = true;
37     private ConnectionStatus connectionStatus = ConnectionStatus.INIT;
38
39     public TivoStatusData() {
40     }
41
42     /*
43      * {@link TivoStatusData} class stores the data from the last status query from the TiVo and any other errors /
44      * status codes.
45      *
46      * @param cmdOk boolean true = last command executed correctly, false = last command failed with error message
47      * 
48      * @param channelNum int = channel number, -1 indicates no channel received. Valid channel range 1-9999.
49      * 
50      * @param subChannelNum int = sub-channel number, -1 indicates no sub-channel received. Valid sub-channel range
51      * 1-9999.
52      * 
53      * @param isRecording boolean true = indicates the current channel is recording
54      * 
55      * @param msg string status message from the TiVo socket
56      * 
57      * @param pubToUI boolean true = this status needs to be published to the UI / Thing, false = do not publish (or it
58      * already has been)
59      * 
60      * @param connectionStatus ConnectionStatus enum UNKNOWN= test not run/default, OFFLINE = offline, STANDBY = TiVo is
61      * in standby, ONLINE = Online
62      *
63      */
64     public TivoStatusData(boolean cmdOk, int channelNum, int subChannelNum, boolean isRecording, String msg,
65             boolean pubToUI, ConnectionStatus connectionStatus) {
66         this.cmdOk = cmdOk;
67         this.time = new Date();
68         this.channelNum = channelNum;
69         this.subChannelNum = subChannelNum;
70         this.isRecording = isRecording;
71         this.msg = msg;
72         this.pubToUI = pubToUI;
73         this.connectionStatus = connectionStatus;
74     }
75
76     public enum ConnectionStatus {
77         INIT,
78         UNKNOWN,
79         OFFLINE,
80         STANDBY,
81         ONLINE
82     }
83
84     /**
85      * {@link TivoStatusData} class stores the data from the last status query from the TiVo and any other errors /
86      * status codes.
87      *
88      * @param cmdOk boolean true = last command executed correctly, false = last command failed with error message
89      * @param channelNum int = channel number, -1 indicates no channel received. Valid channel range 1-9999.
90      * @param msg string status message from the TiVo socket
91      * @param pubToUI boolean true = this status needs to be published to the UI, false = do not publish (or it
92      *            already has been)
93      * @param connectionStatus enum UNKNOWN= test not run/default, OFFLINE = offline, STANDBY = TiVo is in standby
94      *            , ONLINE = Online
95      */
96     @Override
97     public String toString() {
98         return "TivoStatusData [cmdOk=" + cmdOk + ", time=" + time + ", channelNum=" + channelNum + ", subChannelNum="
99                 + subChannelNum + ", msg=" + msg + ", pubToUI=" + pubToUI + ", connectionStatus=" + connectionStatus
100                 + "]";
101     }
102
103     /**
104      * {@link #isCmdOK()} indicates if the last command executed correctly.
105      *
106      * @return cmdOk boolean true = executed correctly, false = last command failed with error message
107      */
108     public boolean isCmdOk() {
109         return cmdOk;
110     }
111
112     /**
113      * {@link} sets the value indicating if the last command executed correctly.
114      *
115      * @param cmdOk boolean true = executed correctly, false = last command failed with error message
116      */
117     public void setCmdOk(boolean cmdOk) {
118         this.cmdOk = cmdOk;
119     }
120
121     /**
122      * {@link getChannelNum} gets the channel number, -1 indicates no channel received. Valid channel range 1-9999.
123      *
124      * @return the channel number
125      */
126     public int getChannelNum() {
127         return channelNum;
128     }
129
130     /**
131      * {@link setChannelNum} sets the channel number, -1 indicates no channel received. Valid channel range 1-9999.
132      *
133      * @param channelNum the new channel number
134      */
135     public void setChannelNum(int channelNum) {
136         this.channelNum = channelNum;
137     }
138
139     /**
140      * {@link getSubChannelNum} gets the sub channel number, -1 indicates no sub channel received. Valid channel range
141      * 1-9999.
142      *
143      * @return the sub channel number
144      */
145     public int getSubChannelNum() {
146         return subChannelNum;
147     }
148
149     /**
150      * {@link setSubChannelNum} sets the sub channel number, -1 indicates no sub channel received. Valid channel range
151      * 1-9999.
152      *
153      * @param subChannelNum the new sub channel number
154      */
155     public void setSubChannelNum(int subChannelNum) {
156         this.subChannelNum = subChannelNum;
157     }
158
159     /**
160      * {@link setRecording} set to true if current channel is recording
161      *
162      * @param isRecording true = current channel is recording
163      */
164     public void setRecording(boolean isRecording) {
165         this.isRecording = isRecording;
166     }
167
168     /**
169      * {@link getPubToUI} get status indicating if current channel is recording
170      *
171      * @return isRecording true = current channel is recording
172      */
173     public boolean isRecording() {
174         return isRecording;
175     }
176
177     /**
178      * {@link getMsg} gets status message string
179      *
180      * @return msg string
181      */
182     public String getMsg() {
183         return msg;
184     }
185
186     /**
187      * {@link setPubToUI} set to true if this status needs to be published to the channel / UI / Thing, false = do not
188      * publish (or it already has been).
189      *
190      * @param pubToUI true = publish status to the channel objects
191      */
192     public void setPubToUI(boolean pubToUI) {
193         this.pubToUI = pubToUI;
194     }
195
196     /**
197      * {@link getPubToUI} get status indicating that the event needs to be published to the channel / UI / Thing, false
198      * = do not publish (or it already has been).
199      *
200      * @return pubToUI true = publish status to the channel objects
201      */
202     public boolean getPubToUI() {
203         return pubToUI;
204     }
205
206     /**
207      * {@link setConnectionStatus} indicates the state of the connection / connection tests. Drives online/offline state
208      * of the
209      * Thing and connection process.
210      *
211      * @param connectionStatus enum UNKNOWN= test not run/default, OFFLINE = offline, STANDBY = TiVo is in standby,
212      *            ONLINE = Online
213      */
214     public void setConnectionStatus(ConnectionStatus connectionStatus) {
215         this.connectionStatus = connectionStatus;
216     }
217
218     /**
219      * {@link getConnectionStatus} returns the state of the connection / connection tests. Drives online/offline state
220      * of the
221      * Thing and connection process.
222      *
223      * @return ConnectionStatus enum UNKNOWN= test not run/default, OFFLINE = offline, STANDBY = TiVo is in standby,
224      *         ONLINE = Online
225      */
226     public ConnectionStatus getConnectionStatus() {
227         return connectionStatus;
228     }
229 }