Implement curfew.
This commit is contained in:
27
server.py
27
server.py
@ -4,7 +4,7 @@
|
||||
import json
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
from devices import shutdown_all, status_all, _set_budget, _get_budget, BUDGET_SECONDS, TICK_INTERVAL
|
||||
from devices import shutdown_all, status_all, curfew_status, _set_budget, _get_budget, BUDGET_SECONDS, TICK_INTERVAL
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
@ -15,10 +15,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
self.wfile.write(HTML.encode())
|
||||
elif self.path == "/status":
|
||||
devices_status, curfew = status_all()
|
||||
response = {"devices": devices_status, "curfew": curfew}
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(status_all()).encode())
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
else:
|
||||
self.send_error(404)
|
||||
|
||||
@ -119,6 +121,16 @@ HTML = """\
|
||||
.status-item .icon { font-size: 1.1rem; flex-shrink: 0; }
|
||||
.status-item .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.status-item .budget { color: #aaa; font-size: .75rem; margin-left: auto; flex-shrink: 0; }
|
||||
#curfew {
|
||||
text-align: center;
|
||||
padding: .5rem;
|
||||
margin-bottom: 1rem;
|
||||
border-radius: 6px;
|
||||
font-size: .85rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
#curfew.blocked { background: #3a1a1a; color: #f87171; }
|
||||
#curfew.allowed { background: #1a3a2c; color: #4ade80; }
|
||||
.status-item .actions {
|
||||
display: flex; align-items: center; gap: .25rem;
|
||||
flex-shrink: 0;
|
||||
@ -135,6 +147,7 @@ HTML = """\
|
||||
<div class="card">
|
||||
<h1>📺 Kids Devices</h1>
|
||||
<p>TV + Gabi's computer + Gaja's computer</p>
|
||||
<div id="curfew"></div>
|
||||
<div id="status"></div>
|
||||
<button id="btn" onclick="run()">TURN OFF</button>
|
||||
<div id="output"></div>
|
||||
@ -178,7 +191,15 @@ HTML = """\
|
||||
try {
|
||||
const res = await fetch('https://noom.cc/off/status');
|
||||
const data = await res.json();
|
||||
document.getElementById('status').innerHTML = data.map(s => {
|
||||
|
||||
// Curfew status
|
||||
const curfew = data.curfew;
|
||||
const curfewEl = document.getElementById('curfew');
|
||||
curfewEl.className = curfew.in_curfew ? 'blocked' : 'allowed';
|
||||
curfewEl.textContent = (curfew.in_curfew ? '🔴 ' : '🟢 ') + curfew.message;
|
||||
|
||||
// Device status
|
||||
document.getElementById('status').innerHTML = data.devices.map(s => {
|
||||
const devId = s.title === 'TV' ? 'tv' : s.title.includes("Gabi") ? 'gabi' : 'gaja';
|
||||
return `<div class="status-item">
|
||||
<span class="center">
|
||||
|
||||
Reference in New Issue
Block a user