allow slots to be off in the daylight scheduler
This commit is contained in:
parent
e206b83e74
commit
33a942707c
@ -42,9 +42,7 @@ class GainInput(Input):
|
|||||||
{errors}
|
{errors}
|
||||||
</div>
|
</div>
|
||||||
""".format(
|
""".format(
|
||||||
id=self.id,
|
id=self.id, input=self.render_input(value, errors), errors=self.render_errors(errors)
|
||||||
input=self.render_input(value, errors),
|
|
||||||
errors=self.render_errors(errors)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_options(self, value):
|
def render_options(self, value):
|
||||||
@ -187,11 +185,28 @@ class SchedulerInput(Input):
|
|||||||
self.profiles = config["profiles"]
|
self.profiles = config["profiles"]
|
||||||
return super().render(config, errors)
|
return super().render(config, errors)
|
||||||
|
|
||||||
def render_profiles_select(self, value, errors, config_key, stage, extra_classes=""):
|
def render_profiles_select(self, value, errors, config_key, stage, extra_classes="", allow_empty=False):
|
||||||
stage_value = ""
|
stage_value = ""
|
||||||
if value and "schedule" in value and config_key in value["schedule"]:
|
if value and "schedule" in value and config_key in value["schedule"]:
|
||||||
stage_value = value["schedule"][config_key]
|
stage_value = value["schedule"][config_key]
|
||||||
|
|
||||||
|
options = "".join(
|
||||||
|
"""
|
||||||
|
<option value="{id}" {selected}>{name}</option>
|
||||||
|
""".format(
|
||||||
|
id=p_id,
|
||||||
|
name=p["name"],
|
||||||
|
selected="selected" if stage_value == p_id else "",
|
||||||
|
)
|
||||||
|
for p_id, p in self.profiles.items()
|
||||||
|
)
|
||||||
|
|
||||||
|
if allow_empty:
|
||||||
|
# prepend a special "off" option to allow a schedule slot to go unused (daylight scheduler)
|
||||||
|
options = """<option value="None" {selected}>Off</option>""".format(
|
||||||
|
selected="selected" if value is None else ""
|
||||||
|
) + options
|
||||||
|
|
||||||
return """
|
return """
|
||||||
<select class="{extra_classes} {classes}" id="{id}" name="{id}" {disabled}>
|
<select class="{extra_classes} {classes}" id="{id}" name="{id}" {disabled}>
|
||||||
{options}
|
{options}
|
||||||
@ -201,16 +216,7 @@ class SchedulerInput(Input):
|
|||||||
classes=self.input_classes(errors),
|
classes=self.input_classes(errors),
|
||||||
extra_classes=extra_classes,
|
extra_classes=extra_classes,
|
||||||
disabled="disabled" if self.disabled else "",
|
disabled="disabled" if self.disabled else "",
|
||||||
options="".join(
|
options=options,
|
||||||
"""
|
|
||||||
<option value={id} {selected}>{name}</option>
|
|
||||||
""".format(
|
|
||||||
id=p_id,
|
|
||||||
name=p["name"],
|
|
||||||
selected="selected" if stage_value == p_id else "",
|
|
||||||
)
|
|
||||||
for p_id, p in self.profiles.items()
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_static_entires(self, value, errors):
|
def render_static_entires(self, value, errors):
|
||||||
@ -271,7 +277,9 @@ class SchedulerInput(Input):
|
|||||||
</div>
|
</div>
|
||||||
""".format(
|
""".format(
|
||||||
name=name,
|
name=name,
|
||||||
select=self.render_profiles_select(value, errors, stage, stage, extra_classes="col-9"),
|
select=self.render_profiles_select(
|
||||||
|
value, errors, stage, stage, extra_classes="col-9", allow_empty=True
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for stage, name in [("day", "Day"), ("night", "Night"), ("greyline", "Greyline")]
|
for stage, name in [("day", "Day"), ("night", "Night"), ("greyline", "Greyline")]
|
||||||
)
|
)
|
||||||
@ -324,6 +332,9 @@ class SchedulerInput(Input):
|
|||||||
def getStageValue(stage):
|
def getStageValue(stage):
|
||||||
input_id = "{id}-{stage}".format(id=self.id, stage=stage)
|
input_id = "{id}-{stage}".format(id=self.id, stage=stage)
|
||||||
if input_id in data:
|
if input_id in data:
|
||||||
|
# special treatment for the "off" option
|
||||||
|
if data[input_id][0] == "None":
|
||||||
|
return None
|
||||||
return data[input_id][0]
|
return data[input_id][0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -192,7 +192,7 @@ class DaylightSchedule(TimerangeSchedule):
|
|||||||
for event in events:
|
for event in events:
|
||||||
# night profile _until_ sunrise, day profile _until_ sunset
|
# night profile _until_ sunrise, day profile _until_ sunset
|
||||||
stype = "night" if event["type"] == "sunrise" else "day"
|
stype = "night" if event["type"] == "sunrise" else "day"
|
||||||
if previousEvent is not None or event["time"] - delta > now:
|
if stype in self.schedule and (previousEvent is not None or event["time"] - delta > now):
|
||||||
start = now if previousEvent is None else previousEvent
|
start = now if previousEvent is None else previousEvent
|
||||||
entries.append(DatetimeScheduleEntry(start, event["time"] - delta, self.schedule[stype]))
|
entries.append(DatetimeScheduleEntry(start, event["time"] - delta, self.schedule[stype]))
|
||||||
if useGreyline:
|
if useGreyline:
|
||||||
|
Loading…
Reference in New Issue
Block a user