use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class FSInternetRadioHandlerJavaTest method verifyCommunicationError.
private void verifyCommunicationError(String exceptionMessage) {
ArgumentCaptor<ThingStatusInfo> captor = ArgumentCaptor.forClass(ThingStatusInfo.class);
verify(callback, atLeast(1)).statusUpdated(isA(Thing.class), captor.capture());
ThingStatusInfo status = captor.getValue();
assertThat(status.getStatus(), is(ThingStatus.OFFLINE));
assertThat(status.getStatusDetail(), is(ThingStatusDetail.COMMUNICATION_ERROR));
assertThat(status.getDescription().contains(exceptionMessage), is(true));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class SmartherModuleHandler method poll.
/**
* Polls to update this Chronothermostat status.
*
* @return {@code true} if the method completes without errors, {@code false} otherwise
*/
private synchronized boolean poll() {
try {
final Bridge bridge = getBridge();
if (bridge != null) {
final ThingStatusInfo bridgeStatusInfo = bridge.getStatusInfo();
if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
ModuleStatus moduleStatus = getBridgeHandler().getModuleStatus(config.getPlantId(), config.getModuleId());
final Chronothermostat statusChrono = moduleStatus.toChronothermostat();
if (statusChrono != null) {
if ((this.chronothermostat == null) || config.isSettingsAutoupdate()) {
final ModuleSettings localModuleSettings = this.moduleSettings;
if (localModuleSettings != null) {
localModuleSettings.updateFromChronothermostat(statusChrono);
}
}
this.chronothermostat = statusChrono;
logger.debug("Module[{}] Status: [{}]", thing.getUID(), this.chronothermostat);
} else {
throw new SmartherGatewayException("No chronothermostat data found");
}
// Refresh the programs list for "automatic" mode
refreshProgramsList();
updateModuleStatus();
getBridgeHandler().registerNotification(config.getPlantId());
// Everything is ok > set the Thing state to Online
updateStatus(ThingStatus.ONLINE);
return true;
} else if (thing.getStatus() != ThingStatus.OFFLINE) {
logger.debug("Module[{}] Switched {} as Bridge is not online", thing.getUID(), bridgeStatusInfo.getStatus());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Smarther Bridge Offline");
}
}
return false;
} catch (SmartherIllegalPropertyValueException e) {
logger.debug("Module[{}] Illegal property value error during polling: {}", thing.getUID(), e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, e.getMessage());
} catch (SmartherSubscriptionAlreadyExistsException e) {
logger.debug("Module[{}] Subscription error during polling: {}", thing.getUID(), e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, e.getMessage());
} catch (SmartherGatewayException e) {
logger.warn("Module[{}] API Gateway error during polling: {}", thing.getUID(), e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (RuntimeException e) {
// All other exceptions apart from Subscription and Gateway issues
logger.warn("Module[{}] Unexpected error during polling, please report if this keeps occurring: ", thing.getUID(), e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, e.getMessage());
}
schedulePoll();
return false;
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class HomematicDeviceDiscoveryServiceTest method testInstallModeIsActiveDuringSubsequentDiscovery.
@Test
public void testInstallModeIsActiveDuringSubsequentDiscovery() throws IOException {
homematicBridgeHandler.getThing().setStatusInfo(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, ""));
startScanAndWaitForLoadedDevices();
verify(homematicBridgeHandler.getGateway()).setInstallMode(true, 60);
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class HomematicDeviceDiscoveryServiceTest method testStoppingDiscoveryDisablesInstallMode.
@Test
public void testStoppingDiscoveryDisablesInstallMode() throws IOException {
homematicBridgeHandler.getThing().setStatusInfo(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, ""));
homematicDeviceDiscoveryService.startScan();
homematicDeviceDiscoveryService.stopScan();
verify(homematicBridgeHandler.getGateway()).setInstallMode(false, 0);
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.
the class AccountOverviewServletTest method whenAccountOverviewServletIsCalledAndBridgesArePresentThenThePageDisplaysInformationAboutThem.
@Test
public void whenAccountOverviewServletIsCalledAndBridgesArePresentThenThePageDisplaysInformationAboutThem() throws Exception {
// given:
Configuration configuration1 = mock(Configuration.class);
when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("de");
when(configuration1.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("openhab@openhab.org");
Bridge bridge1 = mock(Bridge.class);
when(bridge1.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
when(bridge1.getUID()).thenReturn(MieleCloudBindingIntegrationTestConstants.BRIDGE_THING_UID);
when(bridge1.getStatus()).thenReturn(ThingStatus.ONLINE);
when(bridge1.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
when(bridge1.getConfiguration()).thenReturn(configuration1);
Configuration configuration2 = mock(Configuration.class);
when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_LOCALE)).thenReturn("en");
when(configuration2.get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL)).thenReturn("everyone@openhab.org");
Bridge bridge2 = mock(Bridge.class);
when(bridge2.getThingTypeUID()).thenReturn(MieleCloudBindingConstants.THING_TYPE_BRIDGE);
when(bridge2.getUID()).thenReturn(new ThingUID(MieleCloudBindingConstants.THING_TYPE_BRIDGE, "test"));
when(bridge2.getStatus()).thenReturn(ThingStatus.OFFLINE);
when(bridge2.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Error message"));
when(bridge2.getConfiguration()).thenReturn(configuration2);
ThingRegistry thingRegistry = mock(ThingRegistry.class);
when(thingRegistry.stream()).thenAnswer(invocation -> Stream.of(bridge1, bridge2));
ReflectionUtil.setPrivate(getAccountOverviewServlet(), "thingRegistry", thingRegistry);
// when:
Website accountOverviewSite = getCrawler().doGetRelative("/mielecloud");
// then:
assertTrue(accountOverviewSite.contains("The following bridges are paired"));
assertTrue(accountOverviewSite.contains("openhab@openhab.org"));
assertTrue(accountOverviewSite.contains("mielecloud:account:genesis"));
assertTrue(accountOverviewSite.contains("<span class=\"status online\">"));
assertTrue(accountOverviewSite.contains("everyone@openhab.org"));
assertTrue(accountOverviewSite.contains("mielecloud:account:test"));
assertTrue(accountOverviewSite.contains("<span class=\"status offline\">"));
}
Aggregations