Search in sources :

Example 1 with AstroThingHandler

use of org.eclipse.smarthome.binding.astro.handler.AstroThingHandler in project smarthome by eclipse.

the class EventJob method run.

@Override
public void run() {
    AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
    if (checkNull(astroHandler, "AstroThingHandler is null")) {
        return;
    }
    astroHandler.triggerEvent(channelID, event);
}
Also used : AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler)

Example 2 with AstroThingHandler

use of org.eclipse.smarthome.binding.astro.handler.AstroThingHandler in project smarthome by eclipse.

the class PublishPlanetJob method run.

@Override
public void run() {
    AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
    if (checkNull(astroHandler, "AstroThingHandler is null")) {
        return;
    }
    astroHandler.publishDailyInfo();
}
Also used : AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler)

Example 3 with AstroThingHandler

use of org.eclipse.smarthome.binding.astro.handler.AstroThingHandler in project smarthome by eclipse.

the class SunPhaseJob method run.

@Override
public void run() {
    AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
    if (checkNull(astroHandler, "AstroThingHandler is null")) {
        return;
    }
    Channel phaseNameChannel = astroHandler.getThing().getChannel(CHANNEL_ID_SUN_PHASE_NAME);
    if (checkNull(phaseNameChannel, "Phase Name Channel is null")) {
        return;
    }
    Planet planet = astroHandler.getPlanet();
    if (planet != null && planet instanceof Sun) {
        final Sun typedSun = (Sun) planet;
        typedSun.getPhase().setName(sunPhaseName);
        astroHandler.publishChannelIfLinked(phaseNameChannel.getUID());
    }
}
Also used : AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler) Channel(org.eclipse.smarthome.core.thing.Channel) Planet(org.eclipse.smarthome.binding.astro.internal.model.Planet) Sun(org.eclipse.smarthome.binding.astro.internal.model.Sun)

Example 4 with AstroThingHandler

use of org.eclipse.smarthome.binding.astro.handler.AstroThingHandler in project smarthome by eclipse.

the class AstroHandlerFactory method createHandler.

@Override
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    AstroThingHandler thingHandler = null;
    if (thingTypeUID.equals(THING_TYPE_SUN)) {
        thingHandler = new SunHandler(thing);
    } else if (thingTypeUID.equals(THING_TYPE_MOON)) {
        thingHandler = new MoonHandler(thing);
    }
    if (thingHandler != null) {
        ASTRO_THING_HANDLERS.put(thing.getUID().toString(), thingHandler);
    }
    return thingHandler;
}
Also used : AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler) SunHandler(org.eclipse.smarthome.binding.astro.handler.SunHandler) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) MoonHandler(org.eclipse.smarthome.binding.astro.handler.MoonHandler)

Example 5 with AstroThingHandler

use of org.eclipse.smarthome.binding.astro.handler.AstroThingHandler in project smarthome by eclipse.

the class Job method scheduleEvent.

/**
 * Schedules an {@link EventJob} instance
 *
 * @param thingUID the Thing UID
 * @param astroHandler the {@link ThingHandler} instance
 * @param eventAt the {@link Calendar} instance denoting scheduled instant
 * @param events the event IDs to schedule
 * @param channelId the channel ID
 */
public static void scheduleEvent(String thingUID, AstroThingHandler astroHandler, Calendar eventAt, List<String> events, String channelId, boolean configAlreadyApplied) {
    boolean thingNull = checkNull(thingUID, "Thing UID is null");
    boolean astroHandlerNull = checkNull(astroHandler, "AstroThingHandler is null");
    boolean eventAtNull = checkNull(eventAt, "Scheduled Instant is null");
    boolean eventsNull = checkNull(events, "Events list is null");
    boolean channelIdNull = checkNull(channelId, "Channel ID is null");
    if (thingNull || astroHandlerNull || eventAtNull || eventsNull || channelIdNull || events.isEmpty()) {
        return;
    }
    final Calendar instant;
    if (!configAlreadyApplied) {
        final Channel channel = astroHandler.getThing().getChannel(channelId);
        if (channel == null) {
            LOGGER.warn("Cannot find channel '{}' for thing '{}'.", channelId, astroHandler.getThing().getUID());
            return;
        }
        AstroChannelConfig config = channel.getConfiguration().as(AstroChannelConfig.class);
        instant = applyConfig(eventAt, config);
    } else {
        instant = eventAt;
    }
    List<Job> jobs = events.stream().map(e -> new EventJob(thingUID, channelId, e)).collect(toList());
    schedule(thingUID, astroHandler, new CompositeJob(thingUID, jobs), instant);
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) SECOND(java.util.Calendar.SECOND) AstroChannelConfig(org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig) Logger(org.slf4j.Logger) DateTimeUtils(org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils) MethodHandles(java.lang.invoke.MethodHandles) Planet(org.eclipse.smarthome.binding.astro.internal.model.Planet) LoggerFactory(org.slf4j.LoggerFactory) AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler) Collections.singletonList(java.util.Collections.singletonList) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Calendar(java.util.Calendar) Range(org.eclipse.smarthome.binding.astro.internal.model.Range) Arrays.asList(java.util.Arrays.asList) Thing(org.eclipse.smarthome.core.thing.Thing) Objects.isNull(java.util.Objects.isNull) DateUtils.truncatedEquals(org.apache.commons.lang.time.DateUtils.truncatedEquals) AstroBindingConstants(org.eclipse.smarthome.binding.astro.AstroBindingConstants) SunPhaseName(org.eclipse.smarthome.binding.astro.internal.model.SunPhaseName) Calendar(java.util.Calendar) Channel(org.eclipse.smarthome.core.thing.Channel) AstroChannelConfig(org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig)

Aggregations

AstroThingHandler (org.eclipse.smarthome.binding.astro.handler.AstroThingHandler)6 Planet (org.eclipse.smarthome.binding.astro.internal.model.Planet)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 MethodHandles (java.lang.invoke.MethodHandles)1 Arrays.asList (java.util.Arrays.asList)1 Calendar (java.util.Calendar)1 SECOND (java.util.Calendar.SECOND)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Objects.isNull (java.util.Objects.isNull)1 Collectors.toList (java.util.stream.Collectors.toList)1 DateUtils.truncatedEquals (org.apache.commons.lang.time.DateUtils.truncatedEquals)1 AstroBindingConstants (org.eclipse.smarthome.binding.astro.AstroBindingConstants)1 MoonHandler (org.eclipse.smarthome.binding.astro.handler.MoonHandler)1 SunHandler (org.eclipse.smarthome.binding.astro.handler.SunHandler)1 AstroChannelConfig (org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig)1 Range (org.eclipse.smarthome.binding.astro.internal.model.Range)1 Sun (org.eclipse.smarthome.binding.astro.internal.model.Sun)1 SunPhaseName (org.eclipse.smarthome.binding.astro.internal.model.SunPhaseName)1 DateTimeUtils (org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils)1