Fix default values

This commit is contained in:
Adam Štrauch 2024-08-08 11:02:21 +02:00
parent 5699452ebf
commit 84e5b54837
Signed by: cx
GPG Key ID: 7262DAFE292BCE20

View File

@ -1,6 +1,6 @@
import datetime import datetime
import calendar import calendar
from typing import List from typing import List, Optional
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
@ -70,9 +70,9 @@ rest:
@app.get("/price/day", description=docs) @app.get("/price/day", description=docs)
@app.get("/price/day/{date}", description=docs) @app.get("/price/day/{date}", description=docs)
def read_item( def read_item(
date: datetime.date=datetime.date.today(), date: Optional[datetime.date]=None,
hour:int=datetime.datetime.now().hour, hour: Optional[int]=None,
monthly_fees: float = 509.24, monthly_fees: float=509.24,
daily_fees: float=4.18, daily_fees: float=4.18,
kwh_fees_low: float=1.62421, kwh_fees_low: float=1.62421,
kwh_fees_high: float=1.83474, kwh_fees_high: float=1.83474,
@ -82,6 +82,11 @@ def read_item(
num_cheapest_hours:int = 8, num_cheapest_hours:int = 8,
) -> DayPrice: ) -> DayPrice:
if not date:
date = datetime.date.today()
if not hour:
hour = datetime.datetime.now().hour
is_today = datetime.date.today() == date is_today = datetime.date.today() == date
low_tariff_hours_parsed = [int(x.strip()) for x in low_tariff_hours.split(",")] low_tariff_hours_parsed = [int(x.strip()) for x in low_tariff_hours.split(",")]