Updated Celebrations and Silent Dying on Critical/Warning
This commit is contained in:
@@ -118,7 +118,7 @@ def get_current_state():
|
|||||||
sound = top_event["sound"]
|
sound = top_event["sound"]
|
||||||
|
|
||||||
# Check for recovery (was bad, now optimal)
|
# Check for recovery (was bad, now optimal)
|
||||||
if priority == 4 and previous_priority < 4:
|
if priority == 4 and previous_priority < 3:
|
||||||
celebrating_until = now + CELEBRATION_DURATION
|
celebrating_until = now + CELEBRATION_DURATION
|
||||||
|
|
||||||
previous_priority = priority
|
previous_priority = priority
|
||||||
@@ -171,20 +171,23 @@ def write_status():
|
|||||||
def cleanup_expired_events():
|
def cleanup_expired_events():
|
||||||
"""Background thread to remove expired TTL events."""
|
"""Background thread to remove expired TTL events."""
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
try:
|
||||||
now = time.time()
|
time.sleep(1)
|
||||||
expired = []
|
now = time.time()
|
||||||
|
expired = []
|
||||||
|
|
||||||
with events_lock:
|
with events_lock:
|
||||||
for eid, event in active_events.items():
|
for eid, event in active_events.items():
|
||||||
if event.get("ttl") and now > event["ttl"]:
|
if event.get("ttl") and now > event["ttl"]:
|
||||||
expired.append(eid)
|
expired.append(eid)
|
||||||
|
|
||||||
for eid in expired:
|
for eid in expired:
|
||||||
del active_events[eid]
|
del active_events[eid]
|
||||||
|
|
||||||
if expired:
|
if expired:
|
||||||
write_status()
|
write_status()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[cleanup] Error: {e}")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/event", methods=["POST"])
|
@app.route("/event", methods=["POST"])
|
||||||
|
|||||||
60
openapi.yaml
60
openapi.yaml
@@ -19,7 +19,7 @@ info:
|
|||||||
name: MIT
|
name: MIT
|
||||||
|
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:5100
|
- url: http://192.168.2.114:5100
|
||||||
description: Local development server
|
description: Local development server
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
@@ -36,7 +36,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/EventRequest'
|
$ref: "#/components/schemas/EventRequest"
|
||||||
examples:
|
examples:
|
||||||
critical:
|
critical:
|
||||||
summary: Critical event
|
summary: Critical event
|
||||||
@@ -52,18 +52,18 @@ paths:
|
|||||||
message: "CPU nominal"
|
message: "CPU nominal"
|
||||||
ttl: 60
|
ttl: 60
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Event registered successfully
|
description: Event registered successfully
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/EventResponse'
|
$ref: "#/components/schemas/EventResponse"
|
||||||
'400':
|
"400":
|
||||||
description: Invalid request
|
description: Invalid request
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: "#/components/schemas/Error"
|
||||||
|
|
||||||
/clear:
|
/clear:
|
||||||
post:
|
post:
|
||||||
@@ -84,24 +84,24 @@ paths:
|
|||||||
description: Event identifier to clear
|
description: Event identifier to clear
|
||||||
example: "disk_root"
|
example: "disk_root"
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Event cleared successfully
|
description: Event cleared successfully
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ClearResponse'
|
$ref: "#/components/schemas/ClearResponse"
|
||||||
'400':
|
"400":
|
||||||
description: Missing required field
|
description: Missing required field
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: "#/components/schemas/Error"
|
||||||
'404':
|
"404":
|
||||||
description: Event not found
|
description: Event not found
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: "#/components/schemas/Error"
|
||||||
|
|
||||||
/notify:
|
/notify:
|
||||||
post:
|
post:
|
||||||
@@ -116,7 +116,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/NotifyRequest'
|
$ref: "#/components/schemas/NotifyRequest"
|
||||||
examples:
|
examples:
|
||||||
simple:
|
simple:
|
||||||
summary: Simple notification
|
summary: Simple notification
|
||||||
@@ -133,12 +133,12 @@ paths:
|
|||||||
animation: "celebrating"
|
animation: "celebrating"
|
||||||
sound: "chime"
|
sound: "chime"
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Notification sent
|
description: Notification sent
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/NotifyResponse'
|
$ref: "#/components/schemas/NotifyResponse"
|
||||||
|
|
||||||
/sleep:
|
/sleep:
|
||||||
post:
|
post:
|
||||||
@@ -148,12 +148,12 @@ paths:
|
|||||||
dimmed colors. All events are preserved but not displayed until wake.
|
dimmed colors. All events are preserved but not displayed until wake.
|
||||||
operationId: sleep
|
operationId: sleep
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Entered sleep mode
|
description: Entered sleep mode
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/SleepResponse'
|
$ref: "#/components/schemas/SleepResponse"
|
||||||
|
|
||||||
/wake:
|
/wake:
|
||||||
post:
|
post:
|
||||||
@@ -161,12 +161,12 @@ paths:
|
|||||||
description: Wake Kao from sleep mode and resume normal status display.
|
description: Wake Kao from sleep mode and resume normal status display.
|
||||||
operationId: wake
|
operationId: wake
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Exited sleep mode
|
description: Exited sleep mode
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/WakeResponse'
|
$ref: "#/components/schemas/WakeResponse"
|
||||||
|
|
||||||
/status:
|
/status:
|
||||||
get:
|
get:
|
||||||
@@ -176,12 +176,12 @@ paths:
|
|||||||
animation, and list of active events. The frontend polls this endpoint.
|
animation, and list of active events. The frontend polls this endpoint.
|
||||||
operationId: getStatus
|
operationId: getStatus
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Current status
|
description: Current status
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
/events:
|
/events:
|
||||||
get:
|
get:
|
||||||
@@ -189,12 +189,12 @@ paths:
|
|||||||
description: Returns all currently active events with their full details.
|
description: Returns all currently active events with their full details.
|
||||||
operationId: listEvents
|
operationId: listEvents
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: List of active events
|
description: List of active events
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/EventList'
|
$ref: "#/components/schemas/EventList"
|
||||||
|
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
@@ -231,7 +231,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
example: "ok"
|
example: "ok"
|
||||||
current_state:
|
current_state:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
ClearResponse:
|
ClearResponse:
|
||||||
type: object
|
type: object
|
||||||
@@ -240,7 +240,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
example: "cleared"
|
example: "cleared"
|
||||||
current_state:
|
current_state:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
NotifyRequest:
|
NotifyRequest:
|
||||||
type: object
|
type: object
|
||||||
@@ -261,7 +261,7 @@ components:
|
|||||||
color:
|
color:
|
||||||
type: string
|
type: string
|
||||||
description: Custom color in hex format
|
description: Custom color in hex format
|
||||||
pattern: '^#[0-9A-Fa-f]{6}$'
|
pattern: "^#[0-9A-Fa-f]{6}$"
|
||||||
example: "#FF9900"
|
example: "#FF9900"
|
||||||
animation:
|
animation:
|
||||||
type: string
|
type: string
|
||||||
@@ -299,7 +299,7 @@ components:
|
|||||||
description: Generated event ID
|
description: Generated event ID
|
||||||
example: "ha_notify_1704067200000"
|
example: "ha_notify_1704067200000"
|
||||||
current_state:
|
current_state:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
SleepResponse:
|
SleepResponse:
|
||||||
type: object
|
type: object
|
||||||
@@ -308,7 +308,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
example: "sleeping"
|
example: "sleeping"
|
||||||
current_state:
|
current_state:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
WakeResponse:
|
WakeResponse:
|
||||||
type: object
|
type: object
|
||||||
@@ -317,7 +317,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
example: "awake"
|
example: "awake"
|
||||||
current_state:
|
current_state:
|
||||||
$ref: '#/components/schemas/Status'
|
$ref: "#/components/schemas/Status"
|
||||||
|
|
||||||
Status:
|
Status:
|
||||||
type: object
|
type: object
|
||||||
@@ -355,7 +355,7 @@ components:
|
|||||||
active_events:
|
active_events:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ActiveEvent'
|
$ref: "#/components/schemas/ActiveEvent"
|
||||||
last_updated:
|
last_updated:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
|||||||
Reference in New Issue
Block a user