summaryrefslogtreecommitdiff
path: root/api/routes/sensors.py
diff options
context:
space:
mode:
Diffstat (limited to 'api/routes/sensors.py')
-rw-r--r--api/routes/sensors.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/api/routes/sensors.py b/api/routes/sensors.py
index e69de29..18e0f84 100644
--- a/api/routes/sensors.py
+++ b/api/routes/sensors.py
@@ -0,0 +1,27 @@
+from fastapi import APIRouter
+from sqlalchemy import select
+from ..database import SessionLocal
+from ..models import SensorDevice
+
+router = APIRouter(
+ prefix='/sensors',
+ tags=['sensors']
+)
+
+@router.get('/')
+async def get_sensors():
+ dc = {'sensors': []}
+ session = SessionLocal()
+ stmt = select(SensorDevice)
+ devices = session.execute(stmt)
+ for device in devices.scalars():
+ dev = {
+ 'id': device.id,
+ 'name': device.name,
+ 'installation_date': device.installation_date,
+ 'station_id': device.station_id,
+ 'is_active': device.is_active
+ }
+ dc['sensors'].append(dev)
+ dc['size'] = len(dc['sensors'])
+ return dc