org.eclipse.smarthome.core.thing.ThingStatusDetail Java Examples

The following examples show how to use org.eclipse.smarthome.core.thing.ThingStatusDetail. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void doRegisterHandler(final Thing thing, final ThingHandlerFactory thingHandlerFactory) {
    logger.debug("Calling '{}.registerHandler()' for thing '{}'.", thingHandlerFactory.getClass().getSimpleName(),
            thing.getUID());
    try {
        ThingHandler thingHandler = thingHandlerFactory.registerHandler(thing);
        thingHandler.setCallback(ThingManagerImpl.this.thingHandlerCallback);
        thing.setHandler(thingHandler);
        thingHandlers.put(thing.getUID(), thingHandler);
        synchronized (thingHandlersByFactory) {
            thingHandlersByFactory.computeIfAbsent(thingHandlerFactory, unused -> new HashSet<>())
                    .add(thingHandler);
        }
    } catch (Exception ex) {
        ThingStatusInfo statusInfo = buildStatusInfo(ThingStatus.UNINITIALIZED,
                ThingStatusDetail.HANDLER_REGISTERING_ERROR,
                ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
        setThingStatus(thing, statusInfo);
        logger.error("Exception occurred while calling thing handler factory '{}': {}", thingHandlerFactory,
                ex.getMessage(), ex);
    }
}
 
Example #2
Source File: ThingStatusInfoI18nLocalizationServiceOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingStatusInfoLocalizedForOfflineStatusWithoutArgument() {
    setThingStatusInfo(thing,
            new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/offline.without-param"));

    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing,
            null);
    assertThat(thingStatusInfo,
            is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Thing is offline.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.GERMAN);
    assertThat(thingStatusInfo,
            is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Thing ist offline.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.ENGLISH);
    assertThat(thingStatusInfo,
            is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Thing is offline.")));
}
 
Example #3
Source File: ThingStatusInfoI18nLocalizationServiceOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingStatusInfoLocalizedForOfflineStatusWithOneArgument() {
    setThingStatusInfo(thing, new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "@text/offline.with-one-param [\"5\"]"));

    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing,
            null);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing is offline because of 5 failed logins.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.GERMAN);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing ist nach 5 fehlgeschlagenen Anmeldeversuchen offline.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.ENGLISH);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing is offline because of 5 failed logins.")));
}
 
Example #4
Source File: ThingStatusInfoI18nLocalizationServiceOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingStatusInfoLocalizedForMalformedArguments() {
    setThingStatusInfo(thing, new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "@text/offline.with-two-params   [   \"@text/communication-problems\", ,      \"120\"  ]"));

    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing,
            null);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing is offline because of communication problems. Pls try again after 120 seconds.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.GERMAN);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing ist wegen Kommunikationsprobleme offline. Bitte versuchen Sie es in 120 Sekunden erneut.")));

    thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, Locale.ENGLISH);
    assertThat(thingStatusInfo, is(new ThingStatusInfo(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
            "Thing is offline because of communication problems. Pls try again after 120 seconds.")));
}
 
Example #5
Source File: HueSensorHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void initializeThing(@Nullable ThingStatus bridgeStatus) {
    logger.debug("initializeThing thing {} bridge status {}", getThing().getUID(), bridgeStatus);
    final String configSensorId = (String) getConfig().get(SENSOR_ID);
    if (configSensorId != null) {
        sensorId = configSensorId;
        // note: this call implicitly registers our handler as a listener on the bridge
        if (getHueClient() != null) {
            if (bridgeStatus == ThingStatus.ONLINE) {
                initializeProperties();
                updateStatus(ThingStatus.ONLINE);
            } else {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
            }
        } else {
            updateStatus(ThingStatus.OFFLINE);
        }
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                "@text/offline.conf-error-no-sensor-id");
    }
}
 
Example #6
Source File: TradfriGatewayHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void establishConnection() {
    TradfriGatewayConfig configuration = getConfigAs(TradfriGatewayConfig.class);

    this.gatewayURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + DEVICES;
    this.gatewayInfoURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + GATEWAY + "/"
            + GATEWAY_DETAILS;
    try {
        URI uri = new URI(gatewayURI);
        deviceClient = new TradfriCoapClient(uri);
    } catch (URISyntaxException e) {
        logger.error("Illegal gateway URI '{}': {}", gatewayURI, e.getMessage());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        return;
    }

    DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
    builder.setPskStore(new StaticPskStore(configuration.identity, configuration.preSharedKey.getBytes()));
    dtlsConnector = new DTLSConnector(builder.build(), new InMemoryConnectionStore(100, 60));
    endPoint = new TradfriCoapEndpoint(dtlsConnector, NetworkConfig.getStandard());
    deviceClient.setEndpoint(endPoint);
    updateStatus(ThingStatus.UNKNOWN);

    // schedule a new scan every minute
    scanJob = scheduler.scheduleWithFixedDelay(this::startScan, 0, 1, TimeUnit.MINUTES);
}
 
Example #7
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void thingManagerHandlesThingStatusUpdateUninitializedWithAnExceptionCorrectly() {
    String exceptionMessage = "Some runtime exception occurred!";

    ThingHandler thingHandler = mock(ThingHandler.class);
    when(thingHandler.getThing()).thenReturn(thing);

    ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class);
    when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true);
    when(thingHandlerFactory.registerHandler(any(Thing.class))).thenThrow(new RuntimeException(exceptionMessage));

    registerService(thingHandlerFactory);

    managedThingProvider.add(thing);

    ThingStatusInfo statusInfo = ThingStatusInfoBuilder
            .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_REGISTERING_ERROR)
            .withDescription(exceptionMessage).build();
    assertThat(thing.getStatusInfo(), is(statusInfo));
}
 
Example #8
Source File: DeviceHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public synchronized void onDeviceRemoved(GeneralDeviceInformation device) {
    if (device instanceof Device) {
        this.device = null;
        if (this.getThing().getStatus().equals(ThingStatus.ONLINE)) {
            if (!((Device) device).isPresent()) {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                        "Device is not present in the digitalSTROM-System.");
            } else {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
                        "Device is not avaible in the digitalSTROM-System.");
            }

        }
        logger.debug("Set status to {}", getThing().getStatus());
    }
}
 
Example #9
Source File: MeteoBlueBridgeHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Initialize the bridge.
 */
@Override
public void initialize() {
    logger.debug("Initializing meteoblue bridge");

    MeteoBlueBridgeConfig config = getConfigAs(MeteoBlueBridgeConfig.class);
    String apiKeyTemp = config.getApiKey();
    if (StringUtils.isBlank(apiKeyTemp)) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                "Cannot initialize meteoblue bridge. No apiKey provided.");
        return;
    }

    apiKey = apiKeyTemp;

    healthCheck();
}
 
Example #10
Source File: DigitalIOThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void refresh(OwBaseBridgeHandler bridgeHandler, long now) {
    try {
        Boolean forcedRefresh = lastRefresh == 0;

        if (now >= (lastRefresh + refreshInterval)) {
            logger.trace("refreshing {}", this.thing.getUID());
            lastRefresh = now;

            if (!sensors.get(0).checkPresence(bridgeHandler)) {
                return;
            }

            sensors.get(0).refresh(bridgeHandler, forcedRefresh);
        }
    } catch (OwException e) {
        logger.debug("{}: refresh exception {}", this.thing.getUID(), e.getMessage());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "refresh exception");
        return;
    }
}
 
Example #11
Source File: HomieThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void initializeNoStateReceived() throws InterruptedException {
    // A completed future is returned for a subscribe call to the attributes
    doReturn(future).when(thingHandler.device.attributes).subscribeAndReceive(any(), any(), anyString(), any(),
            anyInt());
    doReturn(future).when(thingHandler.device.attributes).unsubscribe();

    // Prevent a call to accept, that would update our thing.
    doNothing().when(thingHandler).accept(any());

    thingHandler.initialize();
    assertThat(thingHandler.device.isInitialized(), is(true));

    verify(callback).statusUpdated(eq(thing), argThat((arg) -> arg.getStatus().equals(ThingStatus.OFFLINE)
            && arg.getStatusDetail().equals(ThingStatusDetail.GONE)));
}
 
Example #12
Source File: OwBaseThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * add this sensor to the property update list of the bridge handler
 *
 */
protected void updateSensorProperties() {
    Bridge bridge = getBridge();
    if (bridge == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "bridge not found");
        return;
    }

    OwBaseBridgeHandler bridgeHandler = (OwBaseBridgeHandler) bridge.getHandler();
    if (bridgeHandler == null) {
        logger.debug("bridgehandler for {} not available for scheduling property update, retrying in 5s",
                thing.getUID());
        scheduler.schedule(() -> {
            updateSensorProperties();
        }, 5000, TimeUnit.MILLISECONDS);
        return;
    }

    bridgeHandler.scheduleForPropertiesUpdate(thing);
}
 
Example #13
Source File: GenericThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void initialize() {
    thingHandler.initialize();
    verify(thingHandler).bridgeStatusChanged(any());
    verify(thingHandler).start(any());
    assertThat(thingHandler.connection, is(connection));

    ChannelState channelConfig = thingHandler.channelStateByChannelUID.get(textChannelUID);
    assertThat(channelConfig.getStateTopic(), is("test/state"));
    assertThat(channelConfig.getCommandTopic(), is("test/command"));

    verify(connection).subscribe(eq(channelConfig.getStateTopic()), eq(channelConfig));

    verify(callback).statusUpdated(eq(thing), argThat((arg) -> arg.getStatus().equals(ThingStatus.ONLINE)
            && arg.getStatusDetail().equals(ThingStatusDetail.NONE)));
}
 
Example #14
Source File: MagicFirmwareUpdateThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void updateFirmware(Firmware firmware, ProgressCallback progressCallback) {
    progressCallback.defineSequence(ProgressStep.DOWNLOADING, ProgressStep.TRANSFERRING, ProgressStep.UPDATING,
            ProgressStep.REBOOTING, ProgressStep.WAITING);

    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.FIRMWARE_UPDATING, "Firmware is updating");

    progressCallback.next();
    for (int percent = 1; percent < 100; percent++) {
        try {
            Thread.sleep(STEP_DELAY);
        } catch (InterruptedException e) {
            progressCallback.failed("Magic firmware update progress callback interrupted while sleeping", e);
        }
        progressCallback.update(percent);
        if (percent % 20 == 0) {
            progressCallback.next();
        }
    }

    getThing().setProperty(Thing.PROPERTY_FIRMWARE_VERSION, firmware.getVersion());

    progressCallback.success();

    updateStatus(ThingStatus.ONLINE);
}
 
Example #15
Source File: HueBridgeHandlerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertCorrectStatusIfAuthenticationFailedForOldUser() {
    Configuration configuration = new Configuration();
    configuration.put(HOST, DUMMY_HOST);
    configuration.put(USER_NAME, "notAuthenticatedUser");
    configuration.put(PROPERTY_SERIAL_NUMBER, "testSerialNumber");
    Bridge bridge = createBridgeThing(configuration);

    HueBridgeHandler hueBridgeHandler = getThingHandler(bridge, HueBridgeHandler.class);
    hueBridgeHandler.thingUpdated(bridge);

    injectBridge(hueBridgeHandler, new HueBridge(DUMMY_HOST, scheduler) {
        @Override
        public void authenticate(String userName) throws IOException, ApiException {
            throw new UnauthorizedException();
        };
    });

    hueBridgeHandler.onNotAuthenticated();

    assertEquals("notAuthenticatedUser", bridge.getConfiguration().get(USER_NAME));
    assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
    assertEquals(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, bridge.getStatusInfo().getStatusDetail());
}
 
Example #16
Source File: MagicChattyThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void initialize() {
    Configuration config = getConfig();
    interval = (BigDecimal) config.get(PARAM_INTERVAL);

    if (interval == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Interval not set");
        return;
    }

    // do not start the chatting job if interval is 0, just set the thing to ONLINE
    if (interval.intValue() > 0) {
        backgroundJob = scheduler.scheduleWithFixedDelay(chatRunnable, START_DELAY, interval.intValue(),
                TimeUnit.SECONDS);
    }

    updateStatus(ThingStatus.ONLINE);
}
 
Example #17
Source File: HueBridgeHandlerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void verifyStatusIfNewUserCannotBeCreated() {
    Configuration configuration = new Configuration();
    configuration.put(HOST, DUMMY_HOST);
    configuration.put(PROPERTY_SERIAL_NUMBER, "testSerialNumber");
    Bridge bridge = createBridgeThing(configuration);

    HueBridgeHandler hueBridgeHandler = getThingHandler(bridge, HueBridgeHandler.class);
    hueBridgeHandler.thingUpdated(bridge);

    injectBridge(hueBridgeHandler, new HueBridge(DUMMY_HOST, scheduler) {
        @Override
        public String link(String deviceType) throws IOException, ApiException {
            throw new ApiException();
        };
    });

    hueBridgeHandler.onNotAuthenticated();

    assertNull(bridge.getConfiguration().get(USER_NAME));
    assertEquals(ThingStatus.OFFLINE, bridge.getStatus());
    assertEquals(ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR, bridge.getStatusInfo().getStatusDetail());
}
 
Example #18
Source File: AutomaticInboxProcessorTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThingWhenNoRepresentationPropertySet() {
    inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).build());
    List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
            .collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));

    when(thing.getProperties()).thenReturn(Collections.emptyMap());
    when(thingStatusInfoChangedEvent.getStatusInfo())
            .thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID);
    automaticInboxProcessor.receive(thingStatusInfoChangedEvent);

    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
    assertThat(results.size(), is(0));
}
 
Example #19
Source File: AutomaticInboxProcessorTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testThingWentOnline() {
    inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID)
            .withRepresentationProperty(DEVICE_ID_KEY).build());

    List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW))
            .collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));

    when(thingRegistry.get(THING_UID)).thenReturn(thing);
    when(thingStatusInfoChangedEvent.getStatusInfo())
            .thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID);
    automaticInboxProcessor.receive(thingStatusInfoChangedEvent);

    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
    assertThat(results.size(), is(0));
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID)));
}
 
Example #20
Source File: Lib485BridgeHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void sendDmxData() {
    if (getThing().getStatus() == ThingStatus.ONLINE) {
        long now = System.currentTimeMillis();
        universe.calculateBuffer(now);
        for (IpNode receiverNode : receiverNodes.keySet()) {
            Socket socket = receiverNodes.get(receiverNode);
            if (socket.isConnected()) {
                try {
                    socket.getOutputStream().write(universe.getBuffer());
                } catch (IOException e) {
                    logger.debug("Could not send to {} in {}: {}", receiverNode, this.thing.getUID(),
                            e.getMessage());
                    closeConnection(ThingStatusDetail.COMMUNICATION_ERROR, "could not send DMX data");
                    return;
                }
            } else {
                closeConnection(ThingStatusDetail.NONE, "reconnect");
                return;
            }
        }
    } else {
        openConnection();
    }
}
 
Example #21
Source File: ZoneTemperatureControlHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void initialize() {
    logger.debug("Initializing DeviceHandler.");
    if (getConfig().get(DigitalSTROMBindingConstants.ZONE_ID) != null) {
        final Bridge bridge = getBridge();
        if (bridge != null) {
            bridgeStatusChanged(bridge.getStatusInfo());
        } else {
            // Set status to OFFLINE, if no bridge is available e.g. because the bridge has been removed and the
            // Thing was reinitialized.
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Bridge is missing!");
        }
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "zoneID is missing");
    }
}
 
Example #22
Source File: HomieThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void readyStateChanged(ReadyState state) {
    switch (state) {
        case alert:
            updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_ERROR);
            break;
        case disconnected:
            updateStatus(ThingStatus.OFFLINE);
            break;
        case init:
            updateStatus(ThingStatus.ONLINE, ThingStatusDetail.CONFIGURATION_PENDING);
            break;
        case lost:
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.GONE, "Device did not send heartbeat in time");
            break;
        case ready:
            updateStatus(ThingStatus.ONLINE);
            break;
        case sleeping:
            updateStatus(ThingStatus.ONLINE, ThingStatusDetail.DUTY_CYCLE);
            break;
        case unknown:
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.GONE, "Device did not publish a ready state");
            break;
        default:
            break;
    }
}
 
Example #23
Source File: TradfriThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setStatus(ThingStatus status, ThingStatusDetail statusDetail) {
    if (active && getBridge().getStatus() != ThingStatus.OFFLINE && status != ThingStatus.ONLINE) {
        updateStatus(status, statusDetail);
        // we are offline and lost our observe relation - let's try to establish the connection in 10 seconds again
        scheduler.schedule(() -> {
            if (observeRelation != null) {
                observeRelation.reactiveCancel();
                observeRelation = null;
            }
            observeRelation = coapClient.startObserve(this);
        }, 10, TimeUnit.SECONDS);
    }
}
 
Example #24
Source File: SystemBrokerHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void brokerRemoved(String connectionName, MqttBrokerConnection removedConnection) {
    final MqttBrokerConnection connection = this.connection;
    if (removedConnection == connection) {
        connection.removeConnectionObserver(this);
        this.connection = null;
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/offline.sharedremoved");
        return;
    }
}
 
Example #25
Source File: TradfriCoapHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onError() {
    logger.debug("CoAP onError");
    if (callback != null) {
        callback.setStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
    }
    if (future != null) {
        future.completeExceptionally(new RuntimeException("CoAP GET resulted in an error."));
    }
}
 
Example #26
Source File: WemoLightHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        if (!isUpnpDeviceRegistered()) {
            logger.debug("WeMo UPnP device {} not yet registered", getUDN());
        }

        getDeviceState();
        onSubscription();
    } catch (Exception e) {
        logger.debug("Exception during poll : {}", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
    }
}
 
Example #27
Source File: WemoHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        if (!isUpnpDeviceRegistered()) {
            logger.debug("WeMo UPnP device {} not yet registered", getUDN());
        }

        updateWemoState();
        onSubscription();
    } catch (Exception e) {
        logger.debug("Exception during poll : {}", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
    }
}
 
Example #28
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void doDisposeHandler(final ThingHandler thingHandler) {
    logger.debug("Calling dispose handler for thing '{}' at '{}'.", thingHandler.getThing().getUID(), thingHandler);
    setThingStatus(thingHandler.getThing(), buildStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.NONE));
    safeCaller.create(thingHandler, ThingHandler.class).onTimeout(() -> {
        logger.warn("Disposing handler for thing '{}' takes more than {}ms.", thingHandler.getThing().getUID(),
                SafeCaller.DEFAULT_TIMEOUT);
    }).onException(e -> {
        logger.error("Exception occurred while disposing handler of thing '{}': {}",
                thingHandler.getThing().getUID(), e.getMessage(), e);
    }).build().dispose();
}
 
Example #29
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void doInitializeHandler(final ThingHandler thingHandler) {
    logger.debug("Calling initialize handler for thing '{}' at '{}'.", thingHandler.getThing().getUID(),
            thingHandler);
    safeCaller.create(thingHandler, ThingHandler.class).onTimeout(() -> {
        logger.warn("Initializing handler for thing '{}' takes more than {}ms.", thingHandler.getThing().getUID(),
                SafeCaller.DEFAULT_TIMEOUT);
    }).onException(e -> {
        ThingStatusInfo statusInfo = buildStatusInfo(ThingStatus.UNINITIALIZED,
                ThingStatusDetail.HANDLER_INITIALIZING_ERROR, e.getMessage());
        setThingStatus(thingHandler.getThing(), statusInfo);
        logger.error("Exception occurred while initializing handler of thing '{}': {}",
                thingHandler.getThing().getUID(), e.getMessage(), e);
    }).build().initialize();
}
 
Example #30
Source File: DigitalIOThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void initialize() {
    Configuration configuration = getConfig();

    if (!super.configure()) {
        return;
    }

    if (this.thing.getThingTypeUID().equals(THING_TYPE_DIGITALIO)) {
        sensors.add(new DS2405(sensorId, this));
    } else if (this.thing.getThingTypeUID().equals(THING_TYPE_DIGITALIO2)) {
        sensors.add(new DS2406_DS2413(sensorId, this));
    } else if (this.thing.getThingTypeUID().equals(THING_TYPE_DIGITALIO8)) {
        sensors.add(new DS2408(sensorId, this));
    }

    // sensor configuration
    try {
        sensors.get(0).configureChannels();
    } catch (OwException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
        return;
    }

    validConfig = true;

    if (configuration.get(CONFIG_REFRESH) == null) {
        // override default of 300s from base thing handler if no user-defined value is present
        refreshInterval = 10 * 1000;
    }

    updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.NONE);
}