Search in sources :

Example 1 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class ThingResource method getThingResponse.

/**
 * helper: create a Response holding a Thing and/or error information.
 *
 * @param status
 * @param thing
 * @param errormessage an optional error message (may be null), ignored if the status family is successful
 * @return Response
 */
private Response getThingResponse(Status status, Thing thing, Locale locale, String errormessage) {
    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, locale);
    boolean managed = managedThingProvider.get(thing.getUID()) != null;
    EnrichedThingDTO enrichedThingDTO = thing != null ? EnrichedThingDTOMapper.map(thing, thingStatusInfo, this.getThingFirmwareStatus(thing.getUID()), getLinkedItemsMap(thing), managed) : null;
    return JSONResponse.createResponse(status, enrichedThingDTO, errormessage);
}
Also used : EnrichedThingDTO(org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 2 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class ThingResource method convertToEnrichedThingDTO.

private EnrichedThingDTO convertToEnrichedThingDTO(Thing thing, Locale locale) {
    boolean managed = managedThingProvider.get(thing.getUID()) != null;
    ThingStatusInfo thingStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, locale);
    return EnrichedThingDTOMapper.map(thing, thingStatusInfo, this.getThingFirmwareStatus(thing.getUID()), getLinkedItemsMap(thing), managed);
}
Also used : ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 3 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class ThingManager method setThingStatus.

private void setThingStatus(Thing thing, ThingStatusInfo thingStatusInfo) {
    ThingStatusInfo oldStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
    thing.setStatusInfo(thingStatusInfo);
    ThingStatusInfo newStatusInfo = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
    try {
        eventPublisher.post(ThingEventFactory.createStatusInfoEvent(thing.getUID(), newStatusInfo));
        if (!oldStatusInfo.equals(newStatusInfo)) {
            eventPublisher.post(ThingEventFactory.createStatusInfoChangedEvent(thing.getUID(), newStatusInfo, oldStatusInfo));
        }
    } catch (Exception ex) {
        logger.error("Could not post 'ThingStatusInfoEvent' event: {}", ex.getMessage(), ex);
    }
}
Also used : ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

Example 4 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class ThingManager method doInitializeHandler.

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

Example 5 with ThingStatusInfo

use of org.eclipse.smarthome.core.thing.ThingStatusInfo in project smarthome by eclipse.

the class ThingConsoleCommandExtension method printThings.

private void printThings(Console console, Collection<Thing> things) {
    if (things.isEmpty()) {
        console.println("No things found.");
    }
    for (Thing thing : things) {
        String id = thing.getUID().toString();
        String thingType = thing instanceof Bridge ? "Bridge" : "Thing";
        ThingStatusInfo status = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
        ThingUID bridgeUID = thing.getBridgeUID();
        String label = thing.getLabel();
        console.println(String.format("%s (Type=%s, Status=%s, Label=%s, Bridge=%s)", id, thingType, status, label, bridgeUID));
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Thing(org.eclipse.smarthome.core.thing.Thing) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Aggregations

ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)26 Test (org.junit.Test)8 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)5 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingStatusInfoBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingStatusInfoBuilder)3 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Duration (java.time.Duration)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Circuit (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)1 Device (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device)1 AbstractHueOSGiTest (org.eclipse.smarthome.binding.hue.test.AbstractHueOSGiTest)1 Bridge (org.eclipse.smarthome.core.thing.Bridge)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 EnrichedThingDTO (org.eclipse.smarthome.io.rest.core.thing.EnrichedThingDTO)1