Skip to content

Commit 6f1fd12

Browse files
committed
feat: Add known state change progress to 'Last Updated' field to show any upcoming known state changes.
1 parent 5b20bf3 commit 6f1fd12

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

alpaca/device.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,30 @@ def is_safe(self) -> bool:
431431
with self.detection_lock:
432432
return self._stable_safe_state
433433

434+
def get_pending_status(self) -> Dict[str, Any]:
435+
"""Get information about any pending state changes"""
436+
with self.detection_lock:
437+
if self._pending_safe_state is None or self._state_change_start_time is None:
438+
return {'is_pending': False}
439+
440+
now = get_current_time(self.alpaca_config.timezone)
441+
elapsed = (now - self._state_change_start_time).total_seconds()
442+
443+
if self._pending_safe_state:
444+
required = self.alpaca_config.debounce_to_safe_sec
445+
else:
446+
required = self.alpaca_config.debounce_to_unsafe_sec
447+
448+
remaining = max(0, required - elapsed)
449+
450+
return {
451+
'is_pending': True,
452+
'target_state': 'SAFE' if self._pending_safe_state else 'UNSAFE',
453+
'target_color': 'rgb(52, 211, 153)' if self._pending_safe_state else 'rgb(248, 113, 113)',
454+
'remaining_seconds': round(remaining, 1),
455+
'total_duration': required
456+
}
457+
434458
def get_safety_history(self) -> List[Dict[str, Any]]:
435459
"""Get a thread-safe copy of the safety history"""
436460
with self.detection_lock:

alpaca/routes/management.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def setup_device(device_number: int):
8484
ascom_safe_status = "SAFE" if is_safe else "UNSAFE"
8585
ascom_safe_color = "rgb(52, 211, 153)" if is_safe else "rgb(248, 113, 113)"
8686

87+
# Get pending status
88+
pending_status = monitor.get_pending_status()
89+
8790
# Format timestamp
8891
if timestamp:
8992
last_update = timestamp.strftime("%Y-%m-%d %H:%M:%S")
@@ -245,7 +248,8 @@ def setup_device(device_number: int):
245248
safe_conditions=safe_cond,
246249
unsafe_conditions=unsafe_cond,
247250
default_threshold=monitor.alpaca_config.default_threshold,
248-
class_thresholds=monitor.alpaca_config.class_thresholds
251+
class_thresholds=monitor.alpaca_config.class_thresholds,
252+
pending_status=pending_status
249253
)
250254

251255

templates/setup.html

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,30 @@
200200
padding: 14px;
201201
border-radius: 6px;
202202
border: 1px solid rgba(71, 85, 105, 0.5);
203+
display: flex;
204+
flex-direction: column;
205+
min-height: 120px;
203206
}
204207

205208
.detection-label {
206209
color: rgb(148, 163, 184);
207210
font-size: 11px;
208211
text-transform: uppercase;
209212
letter-spacing: 0.5px;
210-
margin-bottom: 6px;
213+
margin-bottom: 0;
214+
flex-shrink: 0;
215+
text-align: left;
211216
}
212217

213218
.detection-value {
214219
color: rgb(226, 232, 240);
215-
font-size: 20px;
220+
font-size: 24px;
216221
font-weight: 700;
217222
font-family: 'JetBrains Mono', monospace;
223+
flex-grow: 1;
224+
display: flex;
225+
align-items: center;
226+
justify-content: flex-start;
218227
}
219228

220229
.detection-sub {
@@ -743,11 +752,11 @@ <h1>☁️ Simple<span class="highlight">Cloud</span>Detect</h1>
743752

744753
<div class="status-grid">
745754
<!-- Current Detection - Prominent -->
746-
<div style="display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 16px;">
755+
<div style="display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 16px; grid-auto-rows: auto;">
747756
<!-- Latest Detection Image -->
748-
<div class="status-card">
757+
<div class="status-card" style="display: flex; flex-direction: column;">
749758
<div class="status-card-title">📷 Latest Image</div>
750-
<div style="display: flex; justify-content: center; align-items: center; padding: 8px; min-height: 250px;">
759+
<div style="display: flex; justify-content: center; align-items: center; flex: 1;">
751760
<img id="latest-image" src="/api/v1/latest_image?t={{ last_update }}"
752761
alt="Latest Detection"
753762
style="width: 100%; height: 100%; object-fit: contain; border-radius: 6px; border: 1px solid rgba(71, 85, 105, 0.5);"
@@ -758,7 +767,7 @@ <h1>☁️ Simple<span class="highlight">Cloud</span>Detect</h1>
758767
</div>
759768
</div>
760769

761-
<!-- Current Detection - Prominent -->
770+
<!-- Current Detection Status -->
762771
<div class="status-card status-card-large">
763772
<div class="detection-grid" style="margin-top: 0; height: 100%;">
764773
<div class="detection-item">
@@ -782,11 +791,19 @@ <h1>☁️ Simple<span class="highlight">Cloud</span>Detect</h1>
782791
</div>
783792
<div class="detection-item">
784793
<div class="detection-label">Last Updated</div>
785-
<div class="detection-value" style="font-size: 14px;">{{ last_update }}</div>
794+
<div class="detection-value" style="font-size: 16px;">{{ last_update }}</div>
795+
<div class="detection-sub" style="margin-top: 6px;">
796+
{% if pending_status.is_pending %}
797+
<span style="color: rgb(251, 191, 36); font-weight: 600;">⏳ {{ pending_status.target_state }}</span>
798+
<span style="color: rgb(251, 191, 36);"> in {{ pending_status.remaining_seconds }}s</span>
799+
{% else %}
800+
<span style="color: rgb(100, 116, 139);">No pending changes</span>
801+
{% endif %}
802+
</div>
786803
</div>
787804
<div class="detection-item">
788805
<div class="detection-label">Container Uptime</div>
789-
<div class="detection-value" style="font-size: 14px;">{{ container_uptime }}</div>
806+
<div class="detection-value" style="font-size: 16px;">{{ container_uptime }}</div>
790807
</div>
791808
</div>
792809
</div>

0 commit comments

Comments
 (0)