Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pressure max value #47

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airthings_ble/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
CO2_MAX = 65534
VOC_MAX = 65534
PERCENTAGE_MAX = 100
PRESSURE_MAX = 1310
RADON_MAX = 16383
TEMPERATURE_MAX = 100

Expand Down
3 changes: 2 additions & 1 deletion airthings_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
LOW,
MODERATE,
PERCENTAGE_MAX,
PRESSURE_MAX,
RADON_MAX,
TEMPERATURE_MAX,
UPDATE_TIMEOUT,
Expand Down Expand Up @@ -142,7 +143,7 @@ def handler(raw_data: bytearray) -> dict[str, float | None | str]:
data["temperature"] = validate_value(
value=val[6] / 100.0, max_value=TEMPERATURE_MAX
)
data["pressure"] = float(val[7] / 50.0)
data["pressure"] = validate_value(val[7] / 50.0, max_value=PRESSURE_MAX)
data["co2"] = validate_value(value=val[8] * 1.0, max_value=CO2_MAX)
data["voc"] = validate_value(value=val[9] * 1.0, max_value=VOC_MAX)
return data
Expand Down
12 changes: 10 additions & 2 deletions tests/test_validate_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from airthings_ble.const import CO2_MAX, PERCENTAGE_MAX, RADON_MAX
from airthings_ble.const import CO2_MAX, PERCENTAGE_MAX, PRESSURE_MAX, RADON_MAX
from airthings_ble.parser import validate_value, illuminance_converter


Expand Down Expand Up @@ -35,4 +35,12 @@ def test_validate_value_co2():
def test_validate_value_illuminance():
assert illuminance_converter(0) == 0
assert illuminance_converter(255) == 100
assert illuminance_converter(256) == None
assert illuminance_converter(256) is None


def test_validata_value_pressure():
assert validate_value(value=0.0, max_value=PRESSURE_MAX) == 0
assert validate_value(value=1310.0, max_value=PRESSURE_MAX) == 1310
assert validate_value(value=1311.0, max_value=PRESSURE_MAX) is None
assert validate_value(value=-1.0, max_value=PRESSURE_MAX) is None
assert validate_value(value=65535.0, max_value=PRESSURE_MAX) is None