From 852d08a91d9ec049207862b608836dc3328ebdde Mon Sep 17 00:00:00 2001 From: Matthew Frost Date: Sun, 19 Nov 2023 01:55:54 +0100 Subject: [PATCH] powerbar-api --- app/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/views.py b/app/views.py index 70ae074..5f96342 100644 --- a/app/views.py +++ b/app/views.py @@ -77,3 +77,16 @@ def powerbar_state(powerbar, outlet): state = powerbars[powerbar]['outlets'][outlet].get('state', 'unknown') return jsonify({'state': state}) + + +@routes.route('/powerbars') +def powerbars_list(): + return jsonify(powerbars) + +@routes.route('/powerbars/') +def powerbar_outlets(powerbar): + if not vaild_power_bar(powerbar): + print("Invalid powerbar") + return jsonify({'error': 'Invalid powerbar'}), 400 + + return jsonify(powerbars[powerbar]['outlets'])