26
26
import org .eclipse .jetty .client .HttpClient ;
27
27
import org .openhab .binding .roku .internal .RokuConfiguration ;
28
28
import org .openhab .binding .roku .internal .RokuHttpException ;
29
+ import org .openhab .binding .roku .internal .RokuLimitedModeException ;
29
30
import org .openhab .binding .roku .internal .RokuStateDescriptionOptionProvider ;
30
31
import org .openhab .binding .roku .internal .communication .RokuCommunicator ;
31
32
import org .openhab .binding .roku .internal .dto .Apps .App ;
@@ -73,6 +74,7 @@ public class RokuHandler extends BaseThingHandler {
73
74
private DeviceInfo deviceInfo = new DeviceInfo ();
74
75
private int refreshInterval = DEFAULT_REFRESH_PERIOD_SEC ;
75
76
private boolean tvActive = false ;
77
+ private int limitedMode = -1 ;
76
78
private Map <String , String > appMap = new HashMap <>();
77
79
78
80
private Object sequenceLock = new Object ();
@@ -175,18 +177,20 @@ private void refreshPlayerState() {
175
177
}
176
178
tvActive = false ;
177
179
}
178
- updateStatus (ThingStatus .ONLINE );
179
180
} catch (RokuHttpException e ) {
180
181
logger .debug ("Unable to retrieve Roku active-app info. Exception: {}" , e .getMessage (), e );
181
182
updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR );
183
+ return ;
182
184
}
183
185
184
186
// On the home app and when using the TV or TV inputs, do not update the play mode or time channels
185
- if (!ROKU_HOME_ID .equals (activeAppId ) && !activeAppId .contains (TV_INPUT )) {
187
+ // if in limitedMode, keep checking getPlayerInfo to see if the error goes away
188
+ if ((!ROKU_HOME_ID .equals (activeAppId ) && !activeAppId .contains (TV_INPUT )) || limitedMode != 0 ) {
186
189
try {
187
190
Player playerInfo = communicator .getPlayerInfo ();
191
+ limitedMode = 0 ;
188
192
// When nothing playing, 'close' is reported, replace with 'stop'
189
- updateState (PLAY_MODE , new StringType (playerInfo .getState ().replaceAll (CLOSE , STOP )));
193
+ updateState (PLAY_MODE , new StringType (playerInfo .getState ().replace (CLOSE , STOP )));
190
194
updateState (CONTROL ,
191
195
PLAY .equalsIgnoreCase (playerInfo .getState ()) ? PlayPauseType .PLAY : PlayPauseType .PAUSE );
192
196
@@ -208,9 +212,13 @@ private void refreshPlayerState() {
208
212
}
209
213
} catch (NumberFormatException e ) {
210
214
logger .debug ("Unable to parse playerInfo integer value. Exception: {}" , e .getMessage ());
215
+ } catch (RokuLimitedModeException e ) {
216
+ logger .debug ("RokuLimitedModeException: {}" , e .getMessage ());
217
+ limitedMode = 1 ;
211
218
} catch (RokuHttpException e ) {
212
219
logger .debug ("Unable to retrieve Roku media-player info. Exception: {}" , e .getMessage (), e );
213
220
updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR );
221
+ return ;
214
222
}
215
223
} else {
216
224
updateState (PLAY_MODE , UnDefType .UNDEF );
@@ -221,6 +229,7 @@ private void refreshPlayerState() {
221
229
if (thingTypeUID .equals (THING_TYPE_ROKU_TV ) && tvActive ) {
222
230
try {
223
231
TvChannel tvChannel = communicator .getActiveTvChannel ();
232
+ limitedMode = 0 ;
224
233
updateState (ACTIVE_CHANNEL , new StringType (tvChannel .getChannel ().getNumber ()));
225
234
updateState (SIGNAL_MODE , new StringType (tvChannel .getChannel ().getSignalMode ()));
226
235
updateState (SIGNAL_QUALITY ,
@@ -229,10 +238,21 @@ private void refreshPlayerState() {
229
238
updateState (PROGRAM_TITLE , new StringType (tvChannel .getChannel ().getProgramTitle ()));
230
239
updateState (PROGRAM_DESCRIPTION , new StringType (tvChannel .getChannel ().getProgramDescription ()));
231
240
updateState (PROGRAM_RATING , new StringType (tvChannel .getChannel ().getProgramRatings ()));
241
+ } catch (RokuLimitedModeException e ) {
242
+ logger .debug ("RokuLimitedModeException: {}" , e .getMessage ());
243
+ limitedMode = 1 ;
232
244
} catch (RokuHttpException e ) {
233
245
logger .debug ("Unable to retrieve Roku tv-active-channel info. Exception: {}" , e .getMessage (), e );
246
+ updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .COMMUNICATION_ERROR );
247
+ return ;
234
248
}
235
249
}
250
+
251
+ if (limitedMode < 1 ) {
252
+ updateStatus (ThingStatus .ONLINE );
253
+ } else {
254
+ updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR , "@text/error.limited" );
255
+ }
236
256
}
237
257
}
238
258
0 commit comments