Skip to content

Commit

Permalink
Use floating point values (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Feb 17, 2025
1 parent 44040bf commit c88acc8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/airgradient/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class Measures(DataClassORJSONMixin):
model: str = field(metadata=field_options(alias="model"))
rco2: int | None = None
pm01: int | None = None
pm02: int | None = None
pm02: float | None = None
raw_pm02: int | None = field(default=None, metadata=field_options(alias="pm02"))
compensated_pm02: int | None = field(
compensated_pm02: float | None = field(
default=None, metadata=field_options(alias="pm02Compensated")
)
pm10: int | None = None
total_volatile_organic_component_index: int | None = field(
default=None, metadata=field_options(alias="tvocIndex")
)
raw_total_volatile_organic_component: int | None = field(
raw_total_volatile_organic_component: float | None = field(
default=None, metadata=field_options(alias="tvocRaw")
)
pm003_count: int | None = field(
Expand All @@ -38,7 +38,7 @@ class Measures(DataClassORJSONMixin):
nitrogen_index: int | None = field(
default=None, metadata=field_options(alias="noxIndex")
)
raw_nitrogen: int | None = field(
raw_nitrogen: float | None = field(
default=None, metadata=field_options(alias="noxRaw")
)
ambient_temperature: float | None = field(
Expand Down
40 changes: 33 additions & 7 deletions tests/__snapshots__/test_airgradient.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,65 @@
'nitrogen_index': 1,
'pm003_count': 270,
'pm01': 22,
'pm02': 34,
'pm02': 34.0,
'pm10': 41,
'raw_ambient_temperature': 23.1,
'raw_nitrogen': 16931,
'raw_nitrogen': 16931.0,
'raw_pm02': 34,
'raw_relative_humidity': 32.0,
'raw_total_volatile_organic_component': 31792,
'raw_total_volatile_organic_component': 31792.0,
'rco2': 778,
'relative_humidity': 47.0,
'serial_number': '84fce612f5b8',
'signal_strength': -52,
'total_volatile_organic_component_index': 99,
})
# ---
# name: test_current_fixtures[current_measures_2.json]
dict({
'ambient_temperature': 20.35,
'boot_time': 309,
'compensated_ambient_temperature': 20.35,
'compensated_pm02': 6.83,
'compensated_relative_humidity': 32.51,
'firmware_version': '3.1.21',
'model': 'I-9PSL',
'nitrogen_index': 1,
'pm003_count': 256,
'pm01': 0,
'pm02': 6.83,
'pm10': 2,
'raw_ambient_temperature': 20.35,
'raw_nitrogen': 15568.08,
'raw_pm02': 2,
'raw_relative_humidity': 32.51,
'raw_total_volatile_organic_component': 33774.83,
'rco2': 566,
'relative_humidity': 32.51,
'serial_number': 'aaaaaaaaaa',
'signal_strength': -40,
'total_volatile_organic_component_index': 138,
})
# ---
# name: test_current_fixtures[current_measures_zero.json]
dict({
'ambient_temperature': 0.0,
'boot_time': 4,
'compensated_ambient_temperature': 0.0,
'compensated_pm02': 0,
'compensated_pm02': 0.0,
'compensated_relative_humidity': 0.0,
'firmware_version': '3.1.1',
'model': 'I-9PSL',
'nitrogen_index': 1,
'pm003_count': 270,
'pm01': 22,
'pm02': 0,
'pm02': 0.0,
'pm10': 41,
'raw_ambient_temperature': 23.1,
'raw_nitrogen': 16931,
'raw_nitrogen': 16931.0,
'raw_pm02': 34,
'raw_relative_humidity': 32.0,
'raw_total_volatile_organic_component': 31792,
'raw_total_volatile_organic_component': 31792.0,
'rco2': 778,
'relative_humidity': 0.0,
'serial_number': '84fce612f5b8',
Expand Down
31 changes: 31 additions & 0 deletions tests/fixtures/current_measures_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"pm01": 0,
"pm02": 2,
"pm10": 2,
"pm01Standard": 0,
"pm02Standard": 2,
"pm10Standard": 2,
"pm003Count": 256,
"pm005Count": 216.17,
"pm01Count": 0,
"pm02Count": 0,
"pm50Count": 0,
"pm10Count": 0,
"atmp": 20.35,
"atmpCompensated": 20.35,
"rhum": 32.51,
"rhumCompensated": 32.51,
"pm02Compensated": 6.83,
"rco2": 566,
"tvocIndex": 138,
"tvocRaw": 33774.83,
"noxIndex": 1,
"noxRaw": 15568.08,
"boot": 309,
"bootCount": 309,
"wifi": -40,
"ledMode": "co2",
"serialno": "aaaaaaaaaa",
"firmware": "3.1.21",
"model": "I-9PSL"
}
7 changes: 6 additions & 1 deletion tests/test_airgradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ async def response_handler(_: str, **_kwargs: Any) -> CallbackResult:

@pytest.mark.parametrize(
"fixture",
["current_measures.json", "measures_after_boot.json", "current_measures_zero.json"],
[
"current_measures.json",
"current_measures_2.json",
"measures_after_boot.json",
"current_measures_zero.json",
],
)
async def test_current_fixtures(
responses: aioresponses,
Expand Down

0 comments on commit c88acc8

Please sign in to comment.