use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingManagerImpl method doRegisterHandler.
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);
}
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingStatusInfoI18nLocalizationService method getLocalizedThingStatusInfo.
/**
* Localizes the {@link ThingStatusInfo} for the given thing.
*
* @param thing the thing whose thing status info is to be localized (must not be null)
* @param locale the locale to be used (can be null)
* @return the localized thing status or the original thing status if
* <ul>
* <li>there is nothing to be localized</li>
* <li>the thing does not have a handler</li>
* </ul>
* @throws IllegalArgumentException if given thing is null
*/
public ThingStatusInfo getLocalizedThingStatusInfo(Thing thing, Locale locale) {
if (thing == null) {
throw new IllegalArgumentException("Thing must not be null.");
}
ThingHandler thingHandler = thing.getHandler();
if (thingHandler == null) {
return thing.getStatusInfo();
}
String description = thing.getStatusInfo().getDescription();
if (description == null || !I18nUtil.isConstant(description)) {
return thing.getStatusInfo();
}
String translatedDescription = translateDescription(description, locale, thingHandler);
return new ThingStatusInfo(thing.getStatus(), thing.getStatusInfo().getStatusDetail(), translatedDescription);
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
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));
}
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingStatusInfoBuilderTest method testThingStatusInfoBuilderStatus.
@Test
public void testThingStatusInfoBuilderStatus() {
ThingStatusInfo thingStatusInfo = builder.build();
assertThat(thingStatusInfo.getStatus(), is(ThingStatus.ONLINE));
assertThat(thingStatusInfo.getStatusDetail(), is(ThingStatusDetail.NONE));
assertThat(thingStatusInfo.getDescription(), is(nullValue()));
}
use of org.openhab.core.thing.ThingStatusInfo in project openhab-core by openhab.
the class ThingStatusInfoBuilderTest method testThingStatusInfoBuilderStatusDetails.
@Test
public void testThingStatusInfoBuilderStatusDetails() {
ThingStatusInfo thingStatusInfo = builder.withStatusDetail(ThingStatusDetail.DISABLED).build();
assertThat(thingStatusInfo.getStatus(), is(ThingStatus.ONLINE));
assertThat(thingStatusInfo.getStatusDetail(), is(ThingStatusDetail.DISABLED));
assertThat(thingStatusInfo.getDescription(), is(nullValue()));
}
Aggregations