powerbar-api

This commit is contained in:
Matthew Frost 2023-11-19 01:55:54 +01:00
parent ab33cec8a0
commit 852d08a91d

View file

@ -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/<string:powerbar>')
def powerbar_outlets(powerbar):
if not vaild_power_bar(powerbar):
print("Invalid powerbar")
return jsonify({'error': 'Invalid powerbar'}), 400
return jsonify(powerbars[powerbar]['outlets'])