Search in sources :

Example 1 with Eclipse

use of org.eclipse.smarthome.binding.astro.internal.model.Eclipse in project smarthome by eclipse.

the class MoonCalc method getMoonInfo.

/**
 * Calculates all moon data at the specified coordinates
 */
public Moon getMoonInfo(Calendar calendar, double latitude, double longitude) {
    Moon moon = new Moon();
    double julianDate = DateTimeUtils.dateToJulianDate(calendar);
    double julianDateMidnight = DateTimeUtils.midnightDateToJulianDate(calendar);
    double[] riseSet = getRiseSet(calendar, latitude, longitude);
    Calendar rise = DateTimeUtils.timeToCalendar(calendar, riseSet[0]);
    Calendar set = DateTimeUtils.timeToCalendar(calendar, riseSet[1]);
    if (rise == null || set == null) {
        Calendar tomorrow = (Calendar) calendar.clone();
        tomorrow.add(Calendar.DAY_OF_MONTH, 1);
        double[] riseSeTomorrow = getRiseSet(tomorrow, latitude, longitude);
        if (rise == null) {
            rise = DateTimeUtils.timeToCalendar(tomorrow, riseSeTomorrow[0]);
        }
        if (set == null) {
            set = DateTimeUtils.timeToCalendar(tomorrow, riseSeTomorrow[1]);
        }
    }
    moon.setRise(new Range(rise, rise));
    moon.setSet(new Range(set, set));
    MoonPhase phase = moon.getPhase();
    phase.setNew(DateTimeUtils.toCalendar(getNextPhase(calendar, julianDateMidnight, NEW_MOON)));
    phase.setFirstQuarter(DateTimeUtils.toCalendar(getNextPhase(calendar, julianDateMidnight, FIRST_QUARTER)));
    phase.setFull(DateTimeUtils.toCalendar(getNextPhase(calendar, julianDateMidnight, FULL_MOON)));
    phase.setThirdQuarter(DateTimeUtils.toCalendar(getNextPhase(calendar, julianDateMidnight, LAST_QUARTER)));
    Eclipse eclipse = moon.getEclipse();
    double eclipseJd = getEclipse(calendar, ECLIPSE_TYPE_MOON, julianDateMidnight, ECLIPSE_MODE_PARTIAL);
    eclipse.setPartial(DateTimeUtils.toCalendar(eclipseJd));
    eclipseJd = getEclipse(calendar, ECLIPSE_TYPE_MOON, julianDateMidnight, ECLIPSE_MODE_TOTAL);
    eclipse.setTotal(DateTimeUtils.toCalendar(eclipseJd));
    double decimalYear = DateTimeUtils.getDecimalYear(calendar);
    MoonDistance apogee = moon.getApogee();
    double apogeeJd = getApogee(julianDate, decimalYear);
    apogee.setDate(DateTimeUtils.toCalendar(apogeeJd));
    apogee.setKilometer(getDistance(apogeeJd));
    MoonDistance perigee = moon.getPerigee();
    double perigeeJd = getPerigee(julianDate, decimalYear);
    perigee.setDate(DateTimeUtils.toCalendar(perigeeJd));
    perigee.setKilometer(getDistance(perigeeJd));
    return moon;
}
Also used : MoonPhase(org.eclipse.smarthome.binding.astro.internal.model.MoonPhase) Moon(org.eclipse.smarthome.binding.astro.internal.model.Moon) MoonDistance(org.eclipse.smarthome.binding.astro.internal.model.MoonDistance) Eclipse(org.eclipse.smarthome.binding.astro.internal.model.Eclipse) Calendar(java.util.Calendar) Range(org.eclipse.smarthome.binding.astro.internal.model.Range)

Example 2 with Eclipse

use of org.eclipse.smarthome.binding.astro.internal.model.Eclipse in project smarthome by eclipse.

the class DailyJobMoon method run.

@Override
public void run() {
    handler.publishDailyInfo();
    String thingUID = getThingUID();
    LOGGER.info("Scheduled Astro event-jobs for thing {}", thingUID);
    Planet planet = handler.getPlanet();
    if (planet == null) {
        LOGGER.error("Planet not instantiated");
        return;
    }
    Moon moon = (Moon) planet;
    scheduleEvent(thingUID, handler, moon.getRise().getStart(), EVENT_START, EVENT_CHANNEL_ID_RISE, false);
    scheduleEvent(thingUID, handler, moon.getSet().getEnd(), EVENT_END, EVENT_CHANNEL_ID_SET, false);
    MoonPhase moonPhase = moon.getPhase();
    scheduleEvent(thingUID, handler, moonPhase.getFirstQuarter(), EVENT_PHASE_FIRST_QUARTER, EVENT_CHANNEL_ID_MOON_PHASE, false);
    scheduleEvent(thingUID, handler, moonPhase.getThirdQuarter(), EVENT_PHASE_THIRD_QUARTER, EVENT_CHANNEL_ID_MOON_PHASE, false);
    scheduleEvent(thingUID, handler, moonPhase.getFull(), EVENT_PHASE_FULL, EVENT_CHANNEL_ID_MOON_PHASE, false);
    scheduleEvent(thingUID, handler, moonPhase.getNew(), EVENT_PHASE_NEW, EVENT_CHANNEL_ID_MOON_PHASE, false);
    Eclipse eclipse = moon.getEclipse();
    scheduleEvent(thingUID, handler, eclipse.getPartial(), EVENT_ECLIPSE_PARTIAL, EVENT_CHANNEL_ID_ECLIPSE, false);
    scheduleEvent(thingUID, handler, eclipse.getTotal(), EVENT_ECLIPSE_TOTAL, EVENT_CHANNEL_ID_ECLIPSE, false);
    scheduleEvent(thingUID, handler, moon.getPerigee().getDate(), EVENT_PERIGEE, EVENT_CHANNEL_ID_PERIGEE, false);
    scheduleEvent(thingUID, handler, moon.getApogee().getDate(), EVENT_APOGEE, EVENT_CHANNEL_ID_APOGEE, false);
}
Also used : MoonPhase(org.eclipse.smarthome.binding.astro.internal.model.MoonPhase) Moon(org.eclipse.smarthome.binding.astro.internal.model.Moon) Eclipse(org.eclipse.smarthome.binding.astro.internal.model.Eclipse) Planet(org.eclipse.smarthome.binding.astro.internal.model.Planet)

Aggregations

Eclipse (org.eclipse.smarthome.binding.astro.internal.model.Eclipse)2 Moon (org.eclipse.smarthome.binding.astro.internal.model.Moon)2 MoonPhase (org.eclipse.smarthome.binding.astro.internal.model.MoonPhase)2 Calendar (java.util.Calendar)1 MoonDistance (org.eclipse.smarthome.binding.astro.internal.model.MoonDistance)1 Planet (org.eclipse.smarthome.binding.astro.internal.model.Planet)1 Range (org.eclipse.smarthome.binding.astro.internal.model.Range)1