Remove unused API endpoints from webserver.py
This commit is contained in:
@@ -24,89 +24,7 @@ def create_app(alarm_clock=None):
|
||||
|
||||
@app.route('/<path:filename>')
|
||||
def serve_static(filename):
|
||||
return send_from_directory(public_folder, filename)
|
||||
|
||||
# API endpoints
|
||||
@app.route('/api/status', methods=['GET'])
|
||||
def get_status():
|
||||
"""Get current alarm clock status."""
|
||||
now = datetime.now(ZoneInfo(CITY.timezone))
|
||||
|
||||
response = {
|
||||
'current_time': now.strftime('%H:%M:%S'),
|
||||
'timezone': CITY.timezone,
|
||||
'alarm_active': False,
|
||||
'alarm_time': None,
|
||||
'config_mode': 'normal'
|
||||
}
|
||||
|
||||
if app.alarm_clock:
|
||||
response['alarm_active'] = app.alarm_clock.alarm_active
|
||||
response['alarm_time'] = app.alarm_clock.alarm_time.strftime('%H:%M')
|
||||
response['config_mode'] = app.alarm_clock.config_mode
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
@app.route('/api/alarm', methods=['GET'])
|
||||
def get_alarm():
|
||||
"""Get current alarm time."""
|
||||
if not app.alarm_clock:
|
||||
return jsonify({'error': 'Alarm clock not initialized'}), 503
|
||||
|
||||
return jsonify({
|
||||
'hour': app.alarm_clock.alarm_time.hour,
|
||||
'minute': app.alarm_clock.alarm_time.minute,
|
||||
'formatted': app.alarm_clock.alarm_time.strftime('%H:%M')
|
||||
})
|
||||
|
||||
@app.route('/api/alarm', methods=['POST'])
|
||||
def set_alarm():
|
||||
"""Set alarm time. Expects JSON with 'hour' and 'minute'."""
|
||||
if not app.alarm_clock:
|
||||
return jsonify({'error': 'Alarm clock not initialized'}), 503
|
||||
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({'error': 'JSON body required'}), 400
|
||||
|
||||
hour = data.get('hour')
|
||||
minute = data.get('minute')
|
||||
|
||||
if hour is None or minute is None:
|
||||
return jsonify({'error': 'Both hour and minute are required'}), 400
|
||||
|
||||
try:
|
||||
hour = int(hour)
|
||||
minute = int(minute)
|
||||
except (ValueError, TypeError):
|
||||
return jsonify({'error': 'Hour and minute must be integers'}), 400
|
||||
|
||||
if not (0 <= hour <= 23):
|
||||
return jsonify({'error': 'Hour must be between 0 and 23'}), 400
|
||||
if not (0 <= minute <= 59):
|
||||
return jsonify({'error': 'Minute must be between 0 and 59'}), 400
|
||||
|
||||
app.alarm_clock.alarm_time = app.alarm_clock.alarm_time.replace(
|
||||
hour=hour, minute=minute
|
||||
)
|
||||
app.alarm_clock.reset_wakeup_actions()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'alarm_time': app.alarm_clock.alarm_time.strftime('%H:%M')
|
||||
})
|
||||
|
||||
@app.route('/api/dismiss', methods=['POST'])
|
||||
def dismiss_alarm():
|
||||
"""Dismiss the active alarm."""
|
||||
if not app.alarm_clock:
|
||||
return jsonify({'error': 'Alarm clock not initialized'}), 503
|
||||
|
||||
if not app.alarm_clock.alarm_active:
|
||||
return jsonify({'message': 'No active alarm to dismiss'}), 200
|
||||
|
||||
app.alarm_clock.dismiss_alarm()
|
||||
return jsonify({'success': True, 'message': 'Alarm dismissed'})
|
||||
return send_from_directory(public_folder, 'index.html')
|
||||
|
||||
return app
|
||||
|
||||
|
||||
Reference in New Issue
Block a user