Initial HanchuESS services
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI(title="HanchuESS Solar Backend API")
|
||||
|
||||
|
||||
class DecryptRequest(BaseModel):
|
||||
encrypted_payload: str
|
||||
|
||||
|
||||
@app.get("/", tags=["Root"])
|
||||
def root():
|
||||
return {"message": "Welcome to the HanchuESS Solar Backend API!"}
|
||||
|
||||
@app.get("/get_access_token", tags=["HanchuESS"])
|
||||
def get_access_token():
|
||||
"""Get access token by logging into HanchuESS"""
|
||||
from service.hanchu_service import HanchuESSService
|
||||
|
||||
hanchu_service = HanchuESSService()
|
||||
@@ -17,6 +24,61 @@ def get_access_token():
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
@app.post("/decrypt_payload", tags=["Payload"])
|
||||
def decrypt_payload(request: DecryptRequest):
|
||||
"""Decrypt an AES-encrypted HanchuESS payload"""
|
||||
from service.hanchu_service import HanchuESSService
|
||||
|
||||
try:
|
||||
hanchu_service = HanchuESSService()
|
||||
decrypted_data = hanchu_service.decrypt_payload(request.encrypted_payload)
|
||||
|
||||
return {
|
||||
"decrypted_data": decrypted_data,
|
||||
"data_type": type(decrypted_data).__name__
|
||||
}
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return {"error": str(e), "traceback": traceback.format_exc()}
|
||||
|
||||
@app.get("/get_power_chart", tags=["HanchuESS"])
|
||||
def get_power_chart():
|
||||
"""Get 65-second power chart data from HanchuESS"""
|
||||
from service.hanchu_service import HanchuESSService
|
||||
|
||||
try:
|
||||
hanchu_service = HanchuESSService()
|
||||
|
||||
# Get power chart data (will automatically handle authentication)
|
||||
power_data = hanchu_service.get_power_chart()
|
||||
|
||||
return power_data
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return {"error": str(e), "traceback": traceback.format_exc()}
|
||||
|
||||
@app.get("/get_power_minute_chart", tags=["HanchuESS"])
|
||||
def get_power_minute_chart(start_ts: int = None, end_ts: int = None):
|
||||
"""Get minute-by-minute power chart data from HanchuESS
|
||||
|
||||
Args:
|
||||
start_ts: Optional start timestamp in milliseconds
|
||||
end_ts: Optional end timestamp in milliseconds
|
||||
"""
|
||||
from service.hanchu_service import HanchuESSService
|
||||
|
||||
try:
|
||||
hanchu_service = HanchuESSService()
|
||||
|
||||
# Get minute chart data (will automatically handle authentication)
|
||||
chart_data = hanchu_service.get_power_minute_chart(start_ts=start_ts, end_ts=end_ts)
|
||||
|
||||
return chart_data
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return {"error": str(e), "traceback": traceback.format_exc()}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8050)
|
||||
Reference in New Issue
Block a user