Skip to content

Commit 4700436

Browse files
committed
Add additional data point collection of liquid level sensor and relay boards.
1 parent 631e6d8 commit 4700436

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,28 @@ repos:
1818
exclude: .patch
1919

2020
- repo: https://github.com/psf/black
21-
rev: 22.3.0
21+
rev: 24.8.0
2222
hooks:
2323
- id: black
2424

2525
- repo: https://github.com/PyCQA/flake8
26-
rev: 4.0.1
26+
rev: 7.1.1
2727
hooks:
2828
- id: flake8
2929
additional_dependencies: [
30-
'flake8-bugbear==20.1.4',
31-
'flake8-logging-format==0.6.0',
32-
'flake8-implicit-str-concat==0.2.0',
30+
'flake8-bugbear==24.8.19',
31+
'flake8-implicit-str-concat==0.4.0',
3332
]
3433
exclude: tests/data
3534

3635
- repo: https://github.com/PyCQA/isort
37-
rev: 5.12.0
36+
rev: 5.13.2
3837
hooks:
3938
- id: isort
4039
files: \.py$
4140

4241
- repo: https://github.com/pre-commit/pygrep-hooks
43-
rev: v1.7.0
42+
rev: v1.10.0
4443
hooks:
4544
- id: python-no-log-warn
4645
- id: python-no-eval

opensensor/collection_apis.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
DeviceMetadata,
1616
Environment,
1717
Humidity,
18+
LiquidLevel,
1819
Lux,
1920
Moisture,
2021
Pressure,
22+
RelayBoard,
2123
Temperature,
2224
)
2325
from opensensor.db import get_open_sensor_db
@@ -63,6 +65,8 @@
6365
"co2": "ppm_CO2",
6466
"moisture": "moisture_readings",
6567
"pH": "pH",
68+
"liquid": "liquid",
69+
"relays": "relays",
6670
}
6771

6872

@@ -308,6 +312,8 @@ def get_uniform_sample_pipeline(
308312
"readings": Moisture,
309313
"pH": PH,
310314
"VPD": VPD,
315+
"liquid": LiquidLevel,
316+
"relays": RelayBoard,
311317
}
312318
model_class_attributes = {v: k for k, v in model_classes.items()}
313319

@@ -450,6 +456,30 @@ async def historical_data_route(
450456
response_model=Page[VPD],
451457
methods=["GET"],
452458
)
459+
router.add_api_route(
460+
"/pressure/{device_id}",
461+
create_historical_data_route(Pressure),
462+
response_model=Page[Pressure],
463+
methods=["GET"],
464+
)
465+
router.add_api_route(
466+
"/lux/{device_id}",
467+
create_historical_data_route(Lux),
468+
response_model=Page[Lux],
469+
methods=["GET"],
470+
)
471+
router.add_api_route(
472+
"/liquid/{device_id}",
473+
create_historical_data_route(LiquidLevel),
474+
response_model=Page[LiquidLevel],
475+
methods=["GET"],
476+
)
477+
router.add_api_route(
478+
"/relays/{device_id}",
479+
create_historical_data_route(RelayBoard),
480+
response_model=Page[RelayBoard],
481+
methods=["GET"],
482+
)
453483

454484

455485
@router.post("/environment/")
@@ -498,5 +528,13 @@ async def record_environment(
498528
_record_data_point_to_ts_collection(
499529
db.pH, "pH", environment.device_metadata, environment.pH, user
500530
)
531+
if environment.liquid:
532+
_record_data_point_to_ts_collection(
533+
db.LiquidLevel, "liquid", environment.device_metadata, environment.liquid, user
534+
)
535+
if environment.relays:
536+
_record_data_point_to_ts_collection(
537+
db.RelayBoard, "relays", environment.device_metadata, environment.relays, user
538+
)
501539

502540
return Response(status_code=status.HTTP_201_CREATED)

opensensor/collections.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ def collection_name(cls):
4646
return "pH"
4747

4848

49+
class LiquidLevel(TimestampModel):
50+
"""Liquid Level Sensor output"""
51+
52+
liquid: bool
53+
54+
55+
class RelayStatus(BaseModel):
56+
position: int
57+
enabled: bool
58+
seconds: int | None = None
59+
description: str | None = None
60+
61+
62+
class RelayBoard(TimestampModel):
63+
"""Relay Board control tracking"""
64+
65+
relays: List[RelayStatus]
66+
67+
4968
class Moisture(TimestampModel):
5069
readings: List[float | Decimal | int] | str
5170

@@ -66,6 +85,8 @@ class Environment(BaseModel):
6685
co2: CO2 | None = None
6786
moisture: Moisture | None = None
6887
pH: PH | None = None
88+
liquid: LiquidLevel | None = None
89+
relays: RelayBoard | None = None
6990

7091

7192
class VPD(BaseModel):

0 commit comments

Comments
 (0)