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);
}
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);
}
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);
}
}
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();
}
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));
}
}
Aggregations