Skip to content

Commit

Permalink
style: format code with Autopep8, Black, ClangFormat, dotnet-format, …
Browse files Browse the repository at this point in the history
…Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf

This commit fixes the style issues introduced in efd381d according to the output
from Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java
Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt,
Scalafmt, StandardJS, StandardRB, swift-format and Yapf.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Aug 27, 2024
1 parent efd381d commit 4b5fe88
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions iot-integration/api/iot_api.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
from flask import Flask, request, jsonify
from data_encryption import encrypt_data
from device_auth import DeviceAuth
from iot_devices import SmartHomeDevice, WearableDevice, AutonomousVehicleDevice
from flask import Flask, jsonify, request
from iot_devices import AutonomousVehicleDevice, SmartHomeDevice, WearableDevice
from microtransactions import MicrotransactionHandler
from data_encryption import encrypt_data

app = Flask(__name__)

# Initialize the device authentication instance
device_auth = DeviceAuth('device_id', 'device_secret')
device_auth = DeviceAuth("device_id", "device_secret")

# Initialize the microtransaction handler instance
microtransaction_handler = MicrotransactionHandler('microtransactions.db')
microtransaction_handler = MicrotransactionHandler("microtransactions.db")

@app.route('/iot/devices', methods=['GET'])

@app.route("/iot/devices", methods=["GET"])
def get_iot_devices():
# Return a list of supported IoT devices
return jsonify(['Smart Home', 'Wearable', 'Autonomous Vehicle'])
return jsonify(["Smart Home", "Wearable", "Autonomous Vehicle"])


@app.route('/iot/devices/<device_type>', methods=['POST'])
@app.route("/iot/devices/<device_type>", methods=["POST"])
def register_iot_device(device_type):
# Register a new IoT device
device_id = request.json['device_id']
device_token = request.json['device_token']
if device_type == 'Smart Home':
device_id = request.json["device_id"]
device_token = request.json["device_token"]
if device_type == "Smart Home":
device = SmartHomeDevice(device_id, device_token)
elif device_type == 'Wearable':
elif device_type == "Wearable":
device = WearableDevice(device_id, device_token)
elif device_type == 'Autonomous Vehicle':
elif device_type == "Autonomous Vehicle":
device = AutonomousVehicleDevice(device_id, device_token)
else:
return jsonify({'error': 'Invalid device type'}), 400
return jsonify({'device_id': device_id, 'device_token': device_token})
return jsonify({"error": "Invalid device type"}), 400
return jsonify({"device_id": device_id, "device_token": device_token})

@app.route('/iot/transactions', methods=['POST'])

@app.route("/iot/transactions", methods=["POST"])
def make_iot_transaction():
# Make a transaction using an IoT device
device_id = request.json['device_id']
transaction_id = request.json['transaction_id']
amount = request.json['amount']
device_id = request.json["device_id"]
transaction_id = request.json["transaction_id"]
amount = request.json["amount"]
device = get_iot_device(device_id)
if device:
# Authenticate the device
Expand All @@ -46,24 +49,26 @@ def make_iot_transaction():
if device.make_payment(amount):
# Create a microtransaction
microtransaction_handler.create_microtransaction(transaction_id, amount)
return jsonify({'transaction_id': transaction_id, 'amount': amount})
return jsonify({"transaction_id": transaction_id, "amount": amount})
else:
return jsonify({'error': 'Transaction failed'}), 400
return jsonify({"error": "Transaction failed"}), 400
else:
return jsonify({'error': 'Device authentication failed'}), 401
return jsonify({"error": "Device authentication failed"}), 401
else:
return jsonify({'error': 'Invalid device ID'}), 404
return jsonify({"error": "Invalid device ID"}), 404


def get_iot_device(device_id):
# Retrieve an IoT device instance
if device_id.startswith('SH'):
return SmartHomeDevice(device_id, 'device_token')
elif device_id.startswith('WR'):
return WearableDevice(device_id, 'device_token')
elif device_id.startswith('AV'):
return AutonomousVehicleDevice(device_id, 'device_token')
if device_id.startswith("SH"):
return SmartHomeDevice(device_id, "device_token")
elif device_id.startswith("WR"):
return WearableDevice(device_id, "device_token")
elif device_id.startswith("AV"):
return AutonomousVehicleDevice(device_id, "device_token")
else:
return None

if __name__ == '__main__':

if __name__ == "__main__":
app.run(debug=True)

0 comments on commit 4b5fe88

Please sign in to comment.