Search in sources :

Example 51 with ThingStatusInfo

use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.

the class MieleApplianceHandler method onBridgeConnectionResumed.

public void onBridgeConnectionResumed() {
    Bridge bridge = getBridge();
    if (bridge != null && getMieleBridgeHandler() != null) {
        ThingStatusInfo statusInfo = bridge.getStatusInfo();
        updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
        initializeTranslationProvider(bridge);
    }
}
Also used : ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) Bridge(org.openhab.core.thing.Bridge)

Example 52 with ThingStatusInfo

use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.

the class HomieThingHandlerTests method setUp.

@BeforeEach
public void setUp() {
    final ThingStatusInfo thingStatus = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
    final Configuration config = new Configuration();
    config.put("basetopic", "homie");
    config.put("deviceid", deviceID);
    thing = ThingBuilder.create(MqttBindingConstants.HOMIE300_MQTT_THING, TEST_HOMIE_THING.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, 1000, 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<>(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();
}
Also used : DelayedBatchProcessing(org.openhab.binding.mqtt.generic.tools.DelayedBatchProcessing) Configuration(org.openhab.core.config.core.Configuration) ChildMap(org.openhab.binding.mqtt.generic.tools.ChildMap) Device(org.openhab.binding.mqtt.homie.internal.homie300.Device) DeviceAttributes(org.openhab.binding.mqtt.homie.internal.homie300.DeviceAttributes) TimeUnit(java.util.concurrent.TimeUnit) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with ThingStatusInfo

use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.

the class AbstractHomeAssistantTests method beforeEachAbstractHomeAssistantTests.

@BeforeEach
public void beforeEachAbstractHomeAssistantTests() {
    when(thingTypeRegistry.getThingType(BRIDGE_TYPE_UID)).thenReturn(ThingTypeBuilder.instance(BRIDGE_TYPE_UID, BRIDGE_TYPE_LABEL).build());
    when(thingTypeRegistry.getThingType(HA_TYPE_UID)).thenReturn(ThingTypeBuilder.instance(HA_TYPE_UID, HA_TYPE_LABEL).build());
    when(transformationServiceProvider.getTransformationService(JinjaTransformationProfile.PROFILE_TYPE_UID.getId())).thenReturn(jinjaTransformationService);
    channelTypeProvider = spy(new MqttChannelTypeProvider(thingTypeRegistry));
    setupConnection();
    // Return the mocked connection object if the bridge handler is asked for it
    when(bridgeHandler.getConnectionAsync()).thenReturn(CompletableFuture.completedFuture(bridgeConnection));
    bridgeThing.setStatusInfo(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.ONLINE.NONE, ""));
    bridgeThing.setHandler(bridgeHandler);
    haThing.setStatusInfo(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.ONLINE.NONE, ""));
}
Also used : MqttChannelTypeProvider(org.openhab.binding.mqtt.generic.MqttChannelTypeProvider) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 54 with ThingStatusInfo

use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.

the class SceneHandler method onSceneAdded.

@Override
public void onSceneAdded(InternalScene scene) {
    logger.debug("Scene {} added", scene.getID());
    if (this.bridgeHandler != null) {
        ThingStatusInfo statusInfo = this.bridgeHandler.getThing().getStatusInfo();
        updateStatus(statusInfo.getStatus(), statusInfo.getStatusDetail(), statusInfo.getDescription());
        logger.debug("Set status on {}", getThing().getStatus());
    }
    this.scene = scene;
    onSceneStateChanged(scene.isActive());
}
Also used : ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo)

Example 55 with ThingStatusInfo

use of org.openhab.core.thing.ThingStatusInfo in project openhab-addons by openhab.

the class RoombaHandlerTest method setUp.

@BeforeEach
void setUp() throws Exception {
    Logger logger = LoggerFactory.getLogger(RoombaHandler.class);
    Field logLevelField = logger.getClass().getDeclaredField("currentLogLevel");
    logLevelField.setAccessible(true);
    logLevelField.set(logger, LocationAwareLogger.TRACE_INT);
    Configuration config = new Configuration();
    config.put("ipaddress", RoombaHandlerTest.IP_ADDRESS);
    config.put("password", RoombaHandlerTest.PASSWORD);
    Mockito.when(thing.getConfiguration()).thenReturn(config);
    Mockito.lenient().when(thing.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.UNINITIALIZED, ThingStatusDetail.NONE, "mocked"));
    Mockito.lenient().when(thing.getUID()).thenReturn(new ThingUID("mocked", "irobot", "uid"));
    callback = Mockito.mock(ThingHandlerCallback.class);
    handler = new RoombaHandler(thing);
    handler.setCallback(callback);
}
Also used : Field(java.lang.reflect.Field) Configuration(org.openhab.core.config.core.Configuration) IRobotConfiguration(org.openhab.binding.irobot.internal.config.IRobotConfiguration) ThingUID(org.openhab.core.thing.ThingUID) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) LocationAwareLogger(org.slf4j.spi.LocationAwareLogger) Logger(org.slf4j.Logger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)102 Test (org.junit.jupiter.api.Test)59 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)34 Thing (org.openhab.core.thing.Thing)23 ThingHandler (org.openhab.core.thing.binding.ThingHandler)23 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)20 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)18 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)16 Nullable (org.eclipse.jdt.annotation.Nullable)14 Configuration (org.openhab.core.config.core.Configuration)13 ThingUID (org.openhab.core.thing.ThingUID)13 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Bridge (org.openhab.core.thing.Bridge)12 JavaTest (org.openhab.core.test.java.JavaTest)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DiscoveryResult (org.openhab.core.config.discovery.DiscoveryResult)5 BaseThingHandler (org.openhab.core.thing.binding.BaseThingHandler)5 ArrayList (java.util.ArrayList)4 ThingStatus (org.openhab.core.thing.ThingStatus)4