Search in sources :

Example 1 with CronScheduler

use of org.openhab.core.scheduler.CronScheduler in project openhab-addons by openhab.

the class AstroCommandTest method testRefreshCommandUpdatesTheStateOfTheChannels.

@Test
public void testRefreshCommandUpdatesTheStateOfTheChannels() {
    ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
    ChannelUID channelUID = new ChannelUID(thingUID, DEFAULT_TEST_CHANNEL_ID);
    Channel channel = ChannelBuilder.create(channelUID, DEFAULT_IMEM_TYPE).build();
    Configuration thingConfiguration = new Configuration();
    thingConfiguration.put(GEOLOCATION_PROPERTY, GEOLOCATION_VALUE);
    thingConfiguration.put(INTERVAL_PROPERTY, INTERVAL_DEFAULT_VALUE);
    Thing thing = mock(Thing.class);
    when(thing.getConfiguration()).thenReturn(thingConfiguration);
    when(thing.getUID()).thenReturn(thingUID);
    when(thing.getChannel(DEFAULT_TEST_CHANNEL_ID)).thenReturn(channel);
    ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
    CronScheduler cronScheduler = mock(CronScheduler.class);
    TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
    when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
    AstroThingHandler sunHandler = spy(new SunHandler(thing, cronScheduler, timeZoneProvider));
    // Required from the AstroThingHandler to send the status update
    doReturn(true).when(callback).isChannelLinked(eq(channelUID));
    doReturn(new Sun()).when(sunHandler).getPlanet();
    sunHandler.setCallback(callback);
    sunHandler.handleCommand(channelUID, RefreshType.REFRESH);
    verify(callback, times(1)).stateUpdated(eq(channelUID), any(State.class));
}
Also used : CronScheduler(org.openhab.core.scheduler.CronScheduler) Configuration(org.openhab.core.config.core.Configuration) AstroThingHandler(org.openhab.binding.astro.internal.handler.AstroThingHandler) SunHandler(org.openhab.binding.astro.internal.handler.SunHandler) ChannelUID(org.openhab.core.thing.ChannelUID) State(org.openhab.core.types.State) ThingUID(org.openhab.core.thing.ThingUID) Channel(org.openhab.core.thing.Channel) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) TimeZoneProvider(org.openhab.core.i18n.TimeZoneProvider) Sun(org.openhab.binding.astro.internal.model.Sun) Thing(org.openhab.core.thing.Thing) Test(org.junit.jupiter.api.Test)

Example 2 with CronScheduler

use of org.openhab.core.scheduler.CronScheduler in project openhab-addons by openhab.

the class AstroValidConfigurationTest method assertThingStatus.

private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus, ThingStatusDetail expectedStatusDetail) {
    ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);
    Thing thing = mock(Thing.class);
    when(thing.getConfiguration()).thenReturn(configuration);
    when(thing.getUID()).thenReturn(thingUID);
    ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
    CronScheduler cronScheduler = mock(CronScheduler.class);
    TimeZoneProvider timeZoneProvider = mock(TimeZoneProvider.class);
    when(timeZoneProvider.getTimeZone()).thenReturn(ZoneId.systemDefault());
    ThingHandler sunHandler = new SunHandler(thing, cronScheduler, timeZoneProvider);
    sunHandler.setCallback(callback);
    sunHandler.initialize();
    ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, expectedStatusDetail, null);
    verify(callback, times(1)).statusUpdated(thing, expectedThingStatus);
}
Also used : CronScheduler(org.openhab.core.scheduler.CronScheduler) SunHandler(org.openhab.binding.astro.internal.handler.SunHandler) ThingUID(org.openhab.core.thing.ThingUID) ThingHandlerCallback(org.openhab.core.thing.binding.ThingHandlerCallback) ThingHandler(org.openhab.core.thing.binding.ThingHandler) AstroThingHandler(org.openhab.binding.astro.internal.handler.AstroThingHandler) ThingStatusInfo(org.openhab.core.thing.ThingStatusInfo) TimeZoneProvider(org.openhab.core.i18n.TimeZoneProvider) Thing(org.openhab.core.thing.Thing)

Aggregations

AstroThingHandler (org.openhab.binding.astro.internal.handler.AstroThingHandler)2 SunHandler (org.openhab.binding.astro.internal.handler.SunHandler)2 TimeZoneProvider (org.openhab.core.i18n.TimeZoneProvider)2 CronScheduler (org.openhab.core.scheduler.CronScheduler)2 Thing (org.openhab.core.thing.Thing)2 ThingUID (org.openhab.core.thing.ThingUID)2 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)2 Test (org.junit.jupiter.api.Test)1 Sun (org.openhab.binding.astro.internal.model.Sun)1 Configuration (org.openhab.core.config.core.Configuration)1 Channel (org.openhab.core.thing.Channel)1 ChannelUID (org.openhab.core.thing.ChannelUID)1 ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)1 ThingHandler (org.openhab.core.thing.binding.ThingHandler)1 State (org.openhab.core.types.State)1