📄 scheduleevent.java
字号:
package net.sf.dz.scheduler;import java.util.Date;import java.util.Calendar;import java.util.GregorianCalendar;import org.freehold.jukebox.scheduler.RecurringTaskDescriptor;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.LogChannel;import org.freehold.jukebox.logger.LogLevels;import net.sf.dz.device.model.Thermostat;import net.sf.dz.device.model.ThermostatController;/** * Defines the thermostat schedule event. */public class ScheduleEvent extends RecurringTaskDescriptor implements LogLevels { public static final LogChannel CH_SE = new LogChannel("ScheduleEvent"); /** * Minimum allowed temperature, C\u00B0. */ public static final double TEMP_MIN = 15; /** * Maximum allowed temperature, C\u00B0. */ public static final double TEMP_MAX = 32; /** * Event name. */ private String name; /** * Temperature to hold. */ private double setpoint; /** * False if this period requires to shut the thermostat off. */ private boolean enabled; /** * True if the zone is voting in this period. */ private boolean voting; /** * Day of week for this event. */ private int dayOffset; /** * Dump priority for this event. */ private int dumpPriority; /** * @param dayOffset Day offset (0 is Sunday). * * @param name Period name. * * @param start Absolute start time, in milliseconds. * * @param setpoint Setpoint. * * @param enabled true if the zone is not disabled in this period. * * @param voting true if the zone is voting in this period. * * @param dump Dump priority for this period. */ ScheduleEvent(int dayOffset, String name, long start, double setpoint, boolean enabled, boolean voting, int dumpPriority) { super(start, 1 << dayOffset); this.dayOffset = dayOffset; if ( setpoint < TEMP_MIN || setpoint > TEMP_MAX ) { throw new IllegalArgumentException("Setpoint has to be between " + TEMP_MIN + " and " + TEMP_MAX + " centigree"); } this.name = name; this.setpoint = setpoint; this.enabled = enabled; this.voting = voting; this.dumpPriority = dumpPriority; } /** * Get the day offset. * * @return {@link #dayOffset dayOffset}. */ public int getDayOffset() { return dayOffset; } public String toString() { return name + ": setpoint " + setpoint + "(" + (enabled ? "enabled" : "disabled") + ", " + (voting ? "voting" : "not voting") + "), dump " + dumpPriority + " (" + super.toString() + ")"; } public double getSetpoint() { return setpoint; } public void setSetpoint(double value) { if ( value < TEMP_MIN || value > TEMP_MAX ) { //throw new IllegalArgumentException("Value out of range: " + TEMP_MIN + " to " + TEMP_MAX + ": " + value); return; } setpoint = value; } public boolean isOn() { return enabled; } public void setOn(boolean enabled) { this.enabled = enabled; } public String getName() { return name; } public int getDumpPriority() { return dumpPriority; } /** * Set the dump priority. * * @param dumpPriority Dump priority to set. * * @exception IllegalArgumentException if the value is outside of 0...3 range. */ public void setDumpPriority(int dumpPriority) { if ( dumpPriority < 0 || dumpPriority > 3 ) { throw new IllegalArgumentException("Illegal dump priority value (" + dumpPriority + "), only 0..3 allowed"); } this.dumpPriority = dumpPriority; } public boolean isVoting() { return voting; } public void setVoting(boolean voting) { this.voting = voting; } public String getStartTimeAsString() { Calendar c = new GregorianCalendar(); // FIXME: reinstate this when JDK 1.4 becomes the standard //c.setTimeInMillis(getStartTime()); c.setTime(new Date(getStartTime())); String hours = Integer.toString(c.get(Calendar.HOUR_OF_DAY)); String minutes = Integer.toString(c.get(Calendar.MINUTE)); if ( minutes.length() == 1 ) { minutes = "0" + minutes; } return hours + ":" + minutes; } public void run(Thermostat ts) { // VT: FIXME: Look up the current mode and figure out whether to set // the heating or cooling setpoint. This is the only point in the // system where this is still required, all the other places have // enough information about it. if ( ts.isOnHold() ) { if ( ts instanceof LogAware ) { ((LogAware)ts).complain(LOG_NOTICE, CH_SE, ts.getName() + ": on hold, period skipped"); } } else { if ( ts instanceof LogAware ) { ((LogAware)ts).complain(LOG_NOTICE, CH_SE, ts.getName() + ": running period: " + this); } ts.getController().setSetpoint(getSetpoint()); // VT: FIXME: What if the thermostat is not a thermostat controller? ((ThermostatController)ts).setOn(isOn()); } } public int compareTo(Object other) { int diff = super.compareTo(other); switch ( diff ) { case 0: return name.compareTo(((ScheduleEvent)other).name); default: return diff; } } /** * Render the one-line representation so it can be sent over the * plaintext stream. */ public String renderStatus() { return Schedule.days[dayOffset] + ":" + getName() + ":" + getStartTimeAsString() + ":" + getSetpoint() + ":" + (isOn() ? "on" : "-") + ":" + (isVoting() ? "voting" : "-") + ":" + getDumpPriority(); } /** * Set start time. * * @param offset Milliseconds since beginning of the current day. */ public void setStartOffset(long offset) { long now = System.currentTimeMillis(); long nowOffset = RecurringTaskDescriptor.getOffset(now); long startOfDay = now - nowOffset; super.setStartTime(startOfDay + offset); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -