Coverage for src/data_api/api/routers/energy.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 19:28 +0000

1"""Energy router.""" 

2 

3from fastapi import APIRouter 

4 

5from data_api.api.errors import service_errors 

6from data_api.api.schemas import energy as schemas 

7from data_api.api.schemas.errors import LIVE_ERROR_RESPONSES 

8from data_api.runtime import get_runtime 

9 

10router = APIRouter() 

11 

12 

13@router.get( 

14 "/electricity", 

15 response_model=list[schemas.EnergyElectricityInfo], 

16 operation_id="getElectricity", 

17 responses=LIVE_ERROR_RESPONSES, 

18) 

19async def get_realtime_electricity_usage(): 

20 """ 

21 取得校園電力即時使用量。 

22 資料來源:[校園能源查詢管理系統](http://140.114.188.86/powermanage/index.aspx) 

23 """ 

24 with service_errors(): 

25 return await get_runtime().energy.get_realtime_electricity_usage()