-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.go
More file actions
167 lines (127 loc) · 5.74 KB
/
constants.go
File metadata and controls
167 lines (127 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2025 Matthew Gall <me@matthewgall.dev>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import "time"
// Cache durations - tuned based on real-world Octopus Energy API update patterns
const (
// CacheDurationMeterDevices - Smart meter device list rarely changes
CacheDurationMeterDevices = 7 * 24 * time.Hour
// CacheDurationUsageMeasurements - Usage data updated every 30 minutes for balance between freshness and API limits
CacheDurationUsageMeasurements = 30 * time.Minute
// CacheDurationWheelSpins - Wheel of Fortune spins refresh daily, check twice per day
CacheDurationWheelSpins = 12 * time.Hour
// CacheDurationAccountInfo - Account balance updates hourly
CacheDurationAccountInfo = 1 * time.Hour
// CacheDurationCampaignStatus - Campaign enrollment status changes rarely
CacheDurationCampaignStatus = 24 * time.Hour
// CacheDurationOctoPoints - OctoPoints balance changes slowly, updated after wheel spins
CacheDurationOctoPoints = 1 * time.Hour
// CacheDurationFreeElectricity - Free electricity sessions from static JSON, check frequently
CacheDurationFreeElectricity = 5 * time.Minute
// CacheDurationSavingSessionsOffPeak - Saving sessions cache during off-peak hours
CacheDurationSavingSessionsOffPeak = 2 * time.Hour
// CacheDurationSavingSessionsPeak - Saving sessions cache during peak announcement window (2-4 PM)
CacheDurationSavingSessionsPeak = 10 * time.Minute
// CacheDurationSavingSessionsBusiness - Saving sessions cache during business hours
CacheDurationSavingSessionsBusiness = 30 * time.Minute
)
// Smart interval durations - check frequency based on UK business hours and announcement patterns
const (
// IntervalPeakAnnouncement - Peak announcement window (2-4 PM UK weekdays) when new sessions typically announced
IntervalPeakAnnouncement = 5 * time.Minute
// IntervalBusinessHours - Business hours (9 AM-6 PM UK weekdays) for occasional announcements
IntervalBusinessHours = 10 * time.Minute
// IntervalOffPeak - Off-peak hours (evenings/weekends) when announcements are rare
IntervalOffPeak = 30 * time.Minute
// IntervalEventDrivenBase - Base interval for event-driven backoff after finding new sessions
IntervalEventDrivenBase = 15 * time.Minute
// IntervalEventDrivenIncrement - Increment added per consecutive empty check (up to IntervalOffPeak max)
IntervalEventDrivenIncrement = 5 * time.Minute
// IntervalAfterNewSession - Check more frequently for 30 minutes after finding new sessions (batch detection)
IntervalAfterNewSession = 30 * time.Minute
)
// JWT token settings
const (
// JWTRefreshBuffer - Refresh JWT tokens this many minutes before expiry
JWTRefreshBuffer = 5 * time.Minute
)
// HTTP client settings
const (
// HTTPClientTimeout - Maximum time for HTTP requests
HTTPClientTimeout = 30 * time.Second
// HTTPMinInterval - Minimum time between API requests (rate limiting)
HTTPMinInterval = 1 * time.Second
// HTTPMaxRetries - Maximum number of retries for failed requests
HTTPMaxRetries = 3
)
// Wheel of Fortune settings
const (
// WheelSpinDelay - Delay between consecutive wheel spins to respect API rate limits
WheelSpinDelay = 1 * time.Second
)
// Web dashboard settings
const (
// WebDashboardRefreshInterval - Auto-refresh interval for web dashboard (client-side)
WebDashboardRefreshInterval = 30 * time.Second
// WebMaxUsageDays - Maximum number of days of usage data that can be requested
WebMaxUsageDays = 30
// WebDefaultUsageDays - Default number of days shown in usage graph
WebDefaultUsageDays = 7
)
// UK business hours for smart interval calculation
const (
// UKPeakAnnouncementStartHour - Start of peak announcement window (2 PM)
UKPeakAnnouncementStartHour = 14
// UKPeakAnnouncementEndHour - End of peak announcement window (4 PM)
UKPeakAnnouncementEndHour = 16
// UKBusinessHoursStartHour - Start of business hours (9 AM)
UKBusinessHoursStartHour = 9
// UKBusinessHoursEndHour - End of business hours (6 PM)
UKBusinessHoursEndHour = 18
)
// Octopus Energy API error codes
const (
// OctopusErrorCodeJWTExpired - JWT token has expired
OctopusErrorCodeJWTExpired = "KT-CT-1139"
// OctopusErrorCodeInvalidAuth - Invalid authorization header
OctopusErrorCodeInvalidAuth = "KT-CT-1143"
)
// State management settings
const (
// StateMaxWheelSpinHistory - Maximum number of wheel spin records to keep in history
StateMaxWheelSpinHistory = 100
// StateCleanupAge - Clean up alert states older than this duration
StateCleanupAge = 7 * 24 * time.Hour
)
// Free electricity alert intervals - multi-stage alerting to prevent spam
const (
// AlertIntervalFinal - Alert when session starts in 15 minutes or less
AlertIntervalFinal = 15 * time.Minute
// AlertIntervalSixHour - Alert 6 hours before session
AlertIntervalSixHour = 6 * time.Hour
// AlertIntervalTwelveHour - Alert 12 hours before session
AlertIntervalTwelveHour = 12 * time.Hour
// AlertIntervalDayOf - Alert on day of session (24 hours before)
AlertIntervalDayOf = 24 * time.Hour
)
// Display thresholds for time formatting
const (
// DisplayThreshold24Hours - Show days format after 24 hours
DisplayThreshold24Hours = 24 * time.Hour
)
// Monitor settings
const (
// MonitorDefaultCheckInterval - Default check interval when smart intervals disabled
MonitorDefaultCheckInterval = 15 * time.Minute
)