Skip to content

Commit

Permalink
Add function to get model name (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Jul 20, 2024
1 parent 5871636 commit 72098c2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/airgradient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PmStandard,
TemperatureUnit,
)
from airgradient.util import get_model_name

__all__ = [
"AirGradientClient",
Expand All @@ -21,4 +22,5 @@
"TemperatureUnit",
"ConfigurationControl",
"LedBarMode",
"get_model_name",
]
14 changes: 14 additions & 0 deletions src/airgradient/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Utility functions for AirGradient."""

from __future__ import annotations


def get_model_name(model_id: str) -> str | None:
"""Get model name from identifier."""
if model_id.startswith("I-9PSL"):
return "AirGradient ONE"
if model_id.startswith("O-1PPT"):
return "AirGradient Open Air"
if "DIY" in model_id:
return "AirGradient DIY"
return None
24 changes: 24 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Tests for the util module."""

from __future__ import annotations

import pytest

from airgradient import get_model_name


@pytest.mark.parametrize(
("model_id", "model_name"),
[
("I-9PSL", "AirGradient ONE"),
("I-9PSL-DE", "AirGradient ONE"),
("O-1PPT", "AirGradient Open Air"),
("DIY-PRO-4.3", "AirGradient DIY"),
("DIY-PRO-3.7", "AirGradient DIY"),
("DIY-BASIC-4.0", "AirGradient DIY"),
("ABC", None),
],
)
def test_get_model_name(model_id: str, model_name: str | None) -> None:
"""Test get_model_name."""
assert get_model_name(model_id) == model_name

0 comments on commit 72098c2

Please sign in to comment.