Skip to content

Commit 72098c2

Browse files
authored
Add function to get model name (#150)
1 parent 5871636 commit 72098c2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/airgradient/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
PmStandard,
1111
TemperatureUnit,
1212
)
13+
from airgradient.util import get_model_name
1314

1415
__all__ = [
1516
"AirGradientClient",
@@ -21,4 +22,5 @@
2122
"TemperatureUnit",
2223
"ConfigurationControl",
2324
"LedBarMode",
25+
"get_model_name",
2426
]

src/airgradient/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Utility functions for AirGradient."""
2+
3+
from __future__ import annotations
4+
5+
6+
def get_model_name(model_id: str) -> str | None:
7+
"""Get model name from identifier."""
8+
if model_id.startswith("I-9PSL"):
9+
return "AirGradient ONE"
10+
if model_id.startswith("O-1PPT"):
11+
return "AirGradient Open Air"
12+
if "DIY" in model_id:
13+
return "AirGradient DIY"
14+
return None

tests/test_util.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Tests for the util module."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from airgradient import get_model_name
8+
9+
10+
@pytest.mark.parametrize(
11+
("model_id", "model_name"),
12+
[
13+
("I-9PSL", "AirGradient ONE"),
14+
("I-9PSL-DE", "AirGradient ONE"),
15+
("O-1PPT", "AirGradient Open Air"),
16+
("DIY-PRO-4.3", "AirGradient DIY"),
17+
("DIY-PRO-3.7", "AirGradient DIY"),
18+
("DIY-BASIC-4.0", "AirGradient DIY"),
19+
("ABC", None),
20+
],
21+
)
22+
def test_get_model_name(model_id: str, model_name: str | None) -> None:
23+
"""Test get_model_name."""
24+
assert get_model_name(model_id) == model_name

0 commit comments

Comments
 (0)