0.2.64 update
This commit is contained in:
@@ -100,14 +100,18 @@ type HeroPlacementPolicy struct {
|
||||
PrimeSubtitle string `json:"primeSubtitle"`
|
||||
}
|
||||
|
||||
// HeroSchedule is resolved by the gateway for every home response. Times are UTC RFC3339;
|
||||
// weekdays use the local calendar day (Sunday=0) and an empty list means every day.
|
||||
// HeroSchedule is resolved by the gateway for every home response. An empty Frequency is
|
||||
// the original absolute start/end shape and remains valid. Daily and weekly schedules use
|
||||
// the gateway's local clock; a window such as 22:00–02:00 belongs to the day it starts.
|
||||
type HeroSchedule struct {
|
||||
ID string `json:"id"`
|
||||
ItemID string `json:"itemId"`
|
||||
StartAt time.Time `json:"startAt"`
|
||||
EndAt time.Time `json:"endAt"`
|
||||
Weekdays []int `json:"weekdays,omitempty"`
|
||||
Frequency string `json:"frequency,omitempty"`
|
||||
StartTime string `json:"startTime,omitempty"`
|
||||
EndTime string `json:"endTime,omitempty"`
|
||||
Priority int `json:"priority"`
|
||||
UserID string `json:"userId,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
@@ -205,9 +209,25 @@ func normalizeHeroPolicy(policy HeroPolicy) HeroPolicy {
|
||||
seenSchedules := map[string]bool{}
|
||||
for _, schedule := range policy.Schedules {
|
||||
schedule.ID, schedule.ItemID, schedule.UserID = strings.TrimSpace(schedule.ID), strings.TrimSpace(schedule.ItemID), strings.TrimSpace(schedule.UserID)
|
||||
if schedule.ID == "" || schedule.ItemID == "" || seenSchedules[schedule.ID] || !schedule.EndAt.After(schedule.StartAt) {
|
||||
schedule.Frequency = strings.ToLower(strings.TrimSpace(schedule.Frequency))
|
||||
if schedule.Frequency == "once" {
|
||||
// "once" is explicit in the new console; empty is the compatible legacy form.
|
||||
schedule.Frequency = ""
|
||||
}
|
||||
recurring := schedule.Frequency == "daily" || schedule.Frequency == "weekly"
|
||||
if schedule.ID == "" || schedule.ItemID == "" || seenSchedules[schedule.ID] ||
|
||||
(!recurring && !schedule.EndAt.After(schedule.StartAt)) {
|
||||
continue
|
||||
}
|
||||
if recurring {
|
||||
schedule.StartTime = normaliseHeroClock(schedule.StartTime)
|
||||
schedule.EndTime = normaliseHeroClock(schedule.EndTime)
|
||||
if schedule.StartTime == "" || schedule.EndTime == "" || schedule.StartTime == schedule.EndTime {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
schedule.StartTime, schedule.EndTime = "", ""
|
||||
}
|
||||
seenSchedules[schedule.ID] = true
|
||||
if schedule.Priority < -1000 {
|
||||
schedule.Priority = -1000
|
||||
@@ -224,6 +244,9 @@ func normalizeHeroPolicy(policy HeroPolicy) HeroPolicy {
|
||||
}
|
||||
}
|
||||
schedule.Weekdays = weekdays
|
||||
if schedule.Frequency == "daily" {
|
||||
schedule.Weekdays = []int{}
|
||||
}
|
||||
placements := make([]string, 0, len(schedule.Placements))
|
||||
seenPlacements := map[string]bool{}
|
||||
for _, placement := range schedule.Placements {
|
||||
@@ -243,6 +266,14 @@ func normalizeHeroPolicy(policy HeroPolicy) HeroPolicy {
|
||||
return policy
|
||||
}
|
||||
|
||||
func normaliseHeroClock(value string) string {
|
||||
parsed, err := time.Parse("15:04", strings.TrimSpace(value))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return parsed.Format("15:04")
|
||||
}
|
||||
|
||||
func (s *Store) HeroPolicy(ctx context.Context) (HeroPolicy, error) {
|
||||
var raw []byte
|
||||
err := s.pool.QueryRow(ctx, `SELECT value FROM app_settings WHERE key = $1`, HeroPolicyKey).Scan(&raw)
|
||||
|
||||
Reference in New Issue
Block a user