Skip to content

Commit 435e1b1

Browse files
committed
Leverage the project projection which handles units.
1 parent 796daf4 commit 435e1b1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

opensensor/collection_apis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,7 @@ def sample_and_paginate_collection(
502502
data = [VPD(**item) for item in raw_data]
503503
else:
504504
data = [create_model_instance(response_model, item) for item in raw_data]
505-
506-
if hasattr(response_model, "temp") and unit:
505+
if data and unit:
507506
for item in data:
508507
convert_temperature(item, unit)
509508

@@ -526,7 +525,7 @@ async def historical_data_route(
526525
resolution: int = 30,
527526
page: int = Query(1, ge=1, description="Page number (1-indexed)"),
528527
size: int = Query(50, ge=1, le=1000, description="Page size"),
529-
unit: str | None = None,
528+
unit: str | None = Query(None, description="Unit"),
530529
) -> Page[T]:
531530
if not device_id_is_allowed_for_user(device_id, user=fief_user):
532531
raise HTTPException(
@@ -536,6 +535,8 @@ async def historical_data_route(
536535

537536
# TODO - Refactor this to support paid collections
538537
collection_name = "FreeTier"
538+
if not isinstance(entity, Temperature):
539+
unit = None
539540

540541
return sample_and_paginate_collection(
541542
entity,

0 commit comments

Comments
 (0)