Java Code Examples for org.eclipse.smarthome.core.thing.ThingStatus#ONLINE

The following examples show how to use org.eclipse.smarthome.core.thing.ThingStatus#ONLINE . 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: 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 2
Source File: WemoLightHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void initialize() {
    // initialize() is only called if the required parameter 'deviceID' is available
    wemoLightID = (String) getConfig().get(DEVICE_ID);

    if (getBridge() != null) {
        logger.debug("Initializing WemoLightHandler for LightID '{}'", wemoLightID);
        if (getBridge().getStatus() == ThingStatus.ONLINE) {
            updateStatus(ThingStatus.ONLINE);
            onSubscription();
            onUpdate();
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.BRIDGE_OFFLINE);
        }
    } else {
        updateStatus(ThingStatus.OFFLINE);
    }
}
 
Example 3
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 4
Source File: HueLightHandler.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 configLightId = (String) getConfig().get(LIGHT_ID);
    if (configLightId != null) {
        lightId = configLightId;
        // 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-light-id");
    }
}
 
Example 5
Source File: LIRCRemoteHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void initialize() {
    logger.debug("Initializing thing {}", getThing().getUID());
    config = getConfigAs(LIRCRemoteConfiguration.class);
    remoteName = config.getRemote();
    if (remoteName == null) {
        logger.error("Remote name is not set in {}", getThing().getUID());
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Remote name is not set");
    } else {
        bridgeHandler = (LIRCBridgeHandler) getBridge().getHandler();
        bridgeHandler.registerMessageListener(this);
        if (getBridge().getStatus() == ThingStatus.ONLINE) {
            updateStatus(ThingStatus.ONLINE);
        } else {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
        }
    }
}
 
Example 6
Source File: TradfriThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
    super.bridgeStatusChanged(bridgeStatusInfo);
    // the status might have changed because the bridge is completely reconfigured - so we need to re-establish
    // our CoAP connection as well
    if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
        dispose();
    } else if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE) {
        initialize();
    }
}
 
Example 7
Source File: DmxOverEthernetHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void sendDmxData() {
    if (getThing().getStatus() == ThingStatus.ONLINE) {
        boolean needsSending = false;
        long now = System.currentTimeMillis();
        universe.calculateBuffer(now);
        if ((universe.getLastBufferChanged() > lastSend) || refreshAlways) {
            needsSending = true;
            repeatCounter = 0;
        } else if (now - lastSend > 800) {
            needsSending = true;
        } else if (repeatCounter < 3) {
            needsSending = true;
            repeatCounter++;
        }
        if (needsSending) {
            packetTemplate.setPayload(universe.getBuffer(), universe.getBufferSize());
            packetTemplate.setSequence(sequenceNo);
            DatagramPacket sendPacket = new DatagramPacket(packetTemplate.getRawPacket(),
                    packetTemplate.getPacketLength());
            for (IpNode receiverNode : receiverNodes) {
                sendPacket.setAddress(receiverNode.getAddress());
                sendPacket.setPort(receiverNode.getPort());
                logger.trace("sending packet with length {} to {}", packetTemplate.getPacketLength(),
                        receiverNode.toString());
                try {
                    socket.send(sendPacket);
                } 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");
                }
            }
            lastSend = now;
            sequenceNo = (sequenceNo + 1) % 256;
        }
    } else {
        openConnection();
    }
}
 
Example 8
Source File: HomematicDeviceDiscoveryService.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Will set controller in <i>installMode==true</i>, but only if the bridge
 * is ONLINE (e.g. not during INITIALIZATION).
 */
private void enableInstallMode() {
    try {
        HomematicGateway gateway = bridgeHandler.getGateway();
        ThingStatus bridgeStatus = null;

        if (bridgeHandler != null) {
            Thing bridge = bridgeHandler.getThing();
            bridgeStatus = bridge.getStatus();
            updateInstallModeDuration(bridge);
        }
        if (ThingStatus.ONLINE == bridgeStatus) {
            gateway.setInstallMode(true, installModeDuration);

            int remaining = gateway.getInstallMode();
            if (remaining > 0) {
                setIsInInstallMode();
                logger.debug("Successfully put controller in install mode. Remaining time: {} seconds", remaining);
            } else {
                logger.warn("Controller did not accept requested install mode");
            }
        } else {
            logger.debug("Will not attempt to set controller in install mode, because bridge is not ONLINE.");
        }
    } catch (Exception ex) {
        logger.warn("Failed to set Homematic controller in install mode", ex);
    }
}
 
Example 9
Source File: HomematicThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates the thing status based on device status.
 */
private void updateStatus(HmDevice device) throws GatewayNotAvailableException, IOException {
    loadHomematicChannelValues(device.getChannel(0));

    ThingStatus oldStatus = thing.getStatus();
    ThingStatus newStatus = ThingStatus.ONLINE;
    ThingStatusDetail newDetail = ThingStatusDetail.NONE;

    if (getBridge().getStatus() == ThingStatus.OFFLINE) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.BRIDGE_OFFLINE;
    } else if (device.isFirmwareUpdating()) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.FIRMWARE_UPDATING;
    } else if (device.isUnreach()) {
        newStatus = ThingStatus.OFFLINE;
        newDetail = ThingStatusDetail.COMMUNICATION_ERROR;
    } else if (device.isConfigPending() || device.isUpdatePending()) {
        newDetail = ThingStatusDetail.CONFIGURATION_PENDING;
    }

    if (thing.getStatus() != newStatus || thing.getStatusInfo().getStatusDetail() != newDetail) {
        updateStatus(newStatus, newDetail);
    }
    if (oldStatus == ThingStatus.OFFLINE && newStatus == ThingStatus.ONLINE) {
        initialize();
    }
}
 
Example 10
Source File: HomematicThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates the state of the given channel.
 */
protected void handleRefresh(ChannelUID channelUID) {
    try {
        if (thing.getStatus() == ThingStatus.ONLINE) {
            logger.debug("Updating channel '{}' from thing id '{}'", channelUID, getThing().getUID().getId());
            updateChannelState(channelUID);
        }
    } catch (Exception ex) {
        logger.warn("{}", ex.getMessage());
    }
}
 
Example 11
Source File: MagicBridgedThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void initialize() {
    Bridge bridge = getBridge();
    if (bridge == null || bridge.getStatus() == ThingStatus.UNINITIALIZED) {
        updateStatus(ThingStatus.UNKNOWN, ThingStatusDetail.BRIDGE_UNINITIALIZED);
    } else if (bridge.getStatus() == ThingStatus.OFFLINE) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    } else if (bridge.getStatus() == ThingStatus.ONLINE) {
        updateStatus(ThingStatus.ONLINE);
    } else {
        updateStatus(ThingStatus.UNKNOWN);
    }
}
 
Example 12
Source File: ZonePlayerHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onStatusChanged(boolean status) {
    if (status) {
        if (getThing().getStatus() != ThingStatus.ONLINE) {
            updateStatus(ThingStatus.ONLINE);
            scheduler.execute(pollingRunnable);
        }
    } else {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR);
    }
}
 
Example 13
Source File: OpenWeatherMapAPIHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private void updateThings() {
    ThingStatus status = ThingStatus.OFFLINE;
    for (Thing thing : getThing().getThings()) {
        if (ThingStatus.ONLINE.equals(updateThing((AbstractOpenWeatherMapHandler) thing.getHandler(), thing))) {
            status = ThingStatus.ONLINE;
        }
    }
    updateStatus(status);
}
 
Example 14
Source File: GenericThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    ThingStatusInfo thingStatus = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);

    MockitoAnnotations.initMocks(this);
    // Mock the thing: We need the thingUID and the bridgeUID
    when(thing.getUID()).thenReturn(testGenericThing);
    when(thing.getChannels()).thenReturn(thingChannelList);
    when(thing.getStatusInfo()).thenReturn(thingStatus);
    when(thing.getConfiguration()).thenReturn(new Configuration());

    // Return the mocked connection object if the bridge handler is asked for it
    when(bridgeHandler.getConnectionAsync()).thenReturn(CompletableFuture.completedFuture(connection));

    CompletableFuture<Void> voidFutureComplete = new CompletableFuture<Void>();
    voidFutureComplete.complete(null);
    doReturn(voidFutureComplete).when(connection).unsubscribeAll();
    doReturn(CompletableFuture.completedFuture(true)).when(connection).subscribe(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribe(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).publish(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).publish(any(), any(), anyInt(),
            anyBoolean());

    thingHandler = spy(new GenericThingHandler(thing, mock(MqttChannelStateDescriptionProvider.class),
            mock(TransformationServiceProvider.class), 1500));
    thingHandler.setCallback(callback);

    // Return the bridge handler if the thing handler asks for it
    doReturn(bridgeHandler).when(thingHandler).getBridgeHandler();

    // The broker connection bridge is by default online
    doReturn(thingStatus).when(thingHandler).getBridgeStatus();
}
 
Example 15
Source File: ChannelStateTransformationTests.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws ConfigurationException, MqttException {
    initMocks(this);

    ThingStatusInfo thingStatus = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);

    // Mock the thing: We need the thingUID and the bridgeUID
    when(thing.getUID()).thenReturn(testGenericThing);
    when(thing.getChannels()).thenReturn(thingChannelListWithJson);
    when(thing.getStatusInfo()).thenReturn(thingStatus);
    when(thing.getConfiguration()).thenReturn(new Configuration());

    // Return the mocked connection object if the bridge handler is asked for it
    when(bridgeHandler.getConnectionAsync()).thenReturn(CompletableFuture.completedFuture(connection));

    CompletableFuture<Void> voidFutureComplete = new CompletableFuture<Void>();
    voidFutureComplete.complete(null);
    doReturn(voidFutureComplete).when(connection).unsubscribeAll();
    doReturn(CompletableFuture.completedFuture(true)).when(connection).subscribe(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribe(any(), any());

    thingHandler = spy(new GenericThingHandler(thing, mock(MqttChannelStateDescriptionProvider.class),
            transformationServiceProvider, 1500));
    when(transformationServiceProvider.getTransformationService(anyString())).thenReturn(jsonPathService);

    thingHandler.setCallback(callback);
    // Return the bridge handler if the thing handler asks for it
    doReturn(bridgeHandler).when(thingHandler).getBridgeHandler();

    // We are by default online
    doReturn(thingStatus).when(thingHandler).getBridgeStatus();
}
 
Example 16
Source File: BaseThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
    if (bridgeStatusInfo.getStatus() == ThingStatus.ONLINE
            && getThing().getStatusInfo().getStatusDetail() == ThingStatusDetail.BRIDGE_OFFLINE) {
        updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
    } else if (bridgeStatusInfo.getStatus() == ThingStatus.OFFLINE) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
    }
}
 
Example 17
Source File: ThingStatusInfoI18nLocalizationServiceOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void thingStatusInfoNotChangedForNonI18nConstantDescription() {
    ThingStatusInfo expected = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, "The description.");
    setThingStatusInfo(thing, expected);

    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing,
            null);
    assertThat(thingStatusInfo, is(expected));
}
 
Example 18
Source File: MagicDelayedOnlineHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (channelUID.getId().equals("number")) {
        if (command instanceof DecimalType) {
            DecimalType cmd = (DecimalType) command;
            int cmdInt = cmd.intValue();
            ThingStatus status = cmdInt > 0 ? ThingStatus.ONLINE : ThingStatus.OFFLINE;
            int waitTime = Math.abs(cmd.intValue());
            scheduler.schedule(() -> updateStatus(status), waitTime, TimeUnit.SECONDS);
        }
    }
}
 
Example 19
Source File: LifxLightHandler.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isOnline() {
    return thing.getStatus() == ThingStatus.ONLINE;
}
 
Example 20
Source File: HomieThingHandlerTests.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    final ThingStatusInfo thingStatus = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);

    MockitoAnnotations.initMocks(this);

    final Configuration config = new Configuration();
    config.put("basetopic", "homie");
    config.put("deviceid", deviceID);

    thing = ThingBuilder.create(MqttBindingConstants.HOMIE300_MQTT_THING, testHomieThing.getId())
            .withConfiguration(config).build();
    thing.setStatusInfo(thingStatus);

    // Return the mocked connection object if the bridge handler is asked for it
    when(bridgeHandler.getConnectionAsync()).thenReturn(CompletableFuture.completedFuture(connection));

    doReturn(CompletableFuture.completedFuture(true)).when(connection).subscribe(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribe(any(), any());
    doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribeAll();
    doReturn(CompletableFuture.completedFuture(true)).when(connection).publish(any(), any(), anyInt(),
            anyBoolean());

    doReturn(false).when(scheduledFuture).isDone();
    doReturn(scheduledFuture).when(scheduler).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));

    final HomieThingHandler handler = new HomieThingHandler(thing, channelTypeProvider, 30, 5);
    thingHandler = spy(handler);
    thingHandler.setCallback(callback);
    final Device device = new Device(thing.getUID(), thingHandler, spy(new DeviceAttributes()),
            spy(new ChildMap<>()));
    thingHandler.setInternalObjects(spy(device),
            spy(new DelayedBatchProcessing<Object>(500, thingHandler, scheduler)));

    // Return the bridge handler if the thing handler asks for it
    doReturn(bridgeHandler).when(thingHandler).getBridgeHandler();

    // We are by default online
    doReturn(thingStatus).when(thingHandler).getBridgeStatus();

}