Search in sources :

Example 1 with ReadyTracker

use of org.openhab.core.service.ReadyService.ReadyTracker in project openhab-core by openhab.

the class ReadyServiceImplTest method testTrackersAreInformedInitially.

@Test
public void testTrackersAreInformedInitially() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.markReady(new ReadyMarker("test", "id"));
    rs.registerTracker(tracker);
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 2 with ReadyTracker

use of org.openhab.core.service.ReadyService.ReadyTracker in project openhab-core by openhab.

the class ReadyServiceImplTest method testUnregisterTracker.

@Test
public void testUnregisterTracker() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.markReady(new ReadyMarker("foo", "id"));
    rs.registerTracker(tracker, new ReadyMarkerFilter());
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    rs.unregisterTracker(tracker);
    verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 3 with ReadyTracker

use of org.openhab.core.service.ReadyService.ReadyTracker in project openhab-core by openhab.

the class ReadyServiceImplTest method testTrackersAreInformedOnlyOnMatch.

@Test
public void testTrackersAreInformedOnlyOnMatch() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.registerTracker(tracker, new ReadyMarkerFilter().withType("test"));
    rs.markReady(new ReadyMarker("foo", "id"));
    verifyNoMoreInteractions(tracker);
    rs.markReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 4 with ReadyTracker

use of org.openhab.core.service.ReadyService.ReadyTracker in project openhab-core by openhab.

the class ReadyServiceImplTest method testTrackersAreInformedOnChange.

@Test
public void testTrackersAreInformedOnChange() {
    ReadyTracker tracker = mock(ReadyTracker.class);
    ReadyServiceImpl rs = new ReadyServiceImpl();
    rs.registerTracker(tracker);
    rs.markReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerAdded(isA(ReadyMarker.class));
    rs.unmarkReady(new ReadyMarker("test", "id"));
    verify(tracker).onReadyMarkerRemoved(isA(ReadyMarker.class));
    verifyNoMoreInteractions(tracker);
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Test(org.junit.jupiter.api.Test)

Example 5 with ReadyTracker

use of org.openhab.core.service.ReadyService.ReadyTracker in project openhab-core by openhab.

the class ThingManagerImpl method initializeStartLevelSetter.

private void initializeStartLevelSetter() {
    readyService.registerTracker(new ReadyTracker() {

        @Override
        public void onReadyMarkerRemoved(ReadyMarker readyMarker) {
        }

        @Override
        public void onReadyMarkerAdded(ReadyMarker readyMarker) {
            startLevelSetterJob = scheduler.scheduleWithFixedDelay(() -> {
                for (Thing t : things) {
                    if (!ThingHandlerHelper.isHandlerInitialized(t) && t.isEnabled()) {
                        return;
                    }
                }
                readyService.markReady(marker);
                if (startLevelSetterJob != null) {
                    startLevelSetterJob.cancel(false);
                }
                readyService.unregisterTracker(this);
            }, 2, 2, TimeUnit.SECONDS);
        }
    }, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE).withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_MODEL)));
}
Also used : ReadyMarker(org.openhab.core.service.ReadyMarker) ReadyMarkerFilter(org.openhab.core.service.ReadyMarkerFilter) ReadyTracker(org.openhab.core.service.ReadyService.ReadyTracker) Thing(org.openhab.core.thing.Thing)

Aggregations

ReadyTracker (org.openhab.core.service.ReadyService.ReadyTracker)6 ReadyMarker (org.openhab.core.service.ReadyMarker)5 Test (org.junit.jupiter.api.Test)4 ReadyMarkerFilter (org.openhab.core.service.ReadyMarkerFilter)3 Thing (org.openhab.core.thing.Thing)1