Skip to content

Commit

Permalink
Attempt to fix unit conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 3, 2024
1 parent 8292520 commit 110ed46
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions opensensor/collection_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ def create_model_instance(model: Type[BaseModel], data: dict, target_unit: Optio
continue

# Handle temperature unit conversion if applicable
if field_name == "temp" and target_unit and mongo_field in data:
data[field_name] = convert_temperature(data[mongo_field], target_unit)
elif mongo_field in data:
if mongo_field in data:
data[field_name] = data[mongo_field]
elif field_name in data:
# If the field_name exists in data, use it
Expand Down Expand Up @@ -305,7 +303,10 @@ def create_model_instance(model: Type[BaseModel], data: dict, target_unit: Optio
)

logger.debug(f"Creating instance of {model.__name__} with data: {data}")
return model(**data)
result = model(**data)
if isinstance(result, Temperature) and target_unit:
convert_temperature(result, target_unit)
return result


def get_vpd_pipeline(
Expand Down

0 comments on commit 110ed46

Please sign in to comment.