Search in sources :

Example 56 with ThingStatusInfo

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));
}
Also used : ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Thing(org.openhab.core.thing.Thing)

Example 57 with ThingStatusInfo

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;
}
Also used : SmartherGatewayException(org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException) ModuleSettings(org.openhab.binding.bticinosmarther.internal.model.ModuleSettings) ModuleStatus(org.openhab.binding.bticinosmarther.internal.api.dto.ModuleStatus) SmartherIllegalPropertyValueException(org.openhab.binding.bticinosmarther.internal.api.exception.SmartherIllegalPropertyValueException) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) SmartherSubscriptionAlreadyExistsException(org.openhab.binding.bticinosmarther.internal.api.exception.SmartherSubscriptionAlreadyExistsException) Chronothermostat(org.openhab.binding.bticinosmarther.internal.api.dto.Chronothermostat) Bridge(org.openhab.core.thing.Bridge)

Example 58 with ThingStatusInfo

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);
}
Also used : ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 59 with ThingStatusInfo

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);
}
Also used : ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Test(org.junit.jupiter.api.Test) JavaTest(org.openhab.core.test.java.JavaTest)

Example 60 with ThingStatusInfo

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\">"));
}
Also used : Configuration(org.openhab.core.config.core.Configuration) ThingUID(org.openhab.core.thing.ThingUID) Website(org.openhab.binding.mielecloud.internal.util.Website) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Bridge(org.openhab.core.thing.Bridge) ThingRegistry(org.openhab.core.thing.ThingRegistry) AbstractConfigFlowTest(org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest) Test(org.junit.jupiter.api.Test)

Aggregations

ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)101 Test (org.junit.jupiter.api.Test)58 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)33 Thing (org.openhab.core.thing.Thing)22 ThingHandler (org.openhab.core.thing.binding.ThingHandler)22 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)20 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)17 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)15 Nullable (org.eclipse.jdt.annotation.Nullable)14 Configuration (org.openhab.core.config.core.Configuration)13 ThingUID (org.openhab.core.thing.ThingUID)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Bridge (org.openhab.core.thing.Bridge)12 JavaTest (org.openhab.core.test.java.JavaTest)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)5 BaseThingHandler (org.openhab.core.thing.binding.BaseThingHandler)5 ArrayList (java.util.ArrayList)4 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)4