File: test_device_type.py

package info (click to toggle)
airthings-ble 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: python: 1,577; makefile: 3
file content (92 lines) | stat: -rw-r--r-- 5,218 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
from airthings_ble.device_type import AirthingsDeviceType


def test_device_type() -> None:
    """Test device type."""
    assert AirthingsDeviceType.WAVE_MINI.product_name == "Wave Mini"
    assert AirthingsDeviceType.WAVE_PLUS.product_name == "Wave Plus"
    assert AirthingsDeviceType.WAVE_RADON.product_name == "Wave Radon"
    assert AirthingsDeviceType.WAVE_GEN_1.product_name == "Wave Gen 1"
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.product_name == "Wave Enhance"
    assert AirthingsDeviceType.WAVE_ENHANCE_US.product_name == "Wave Enhance"
    assert AirthingsDeviceType("2900") == AirthingsDeviceType.WAVE_GEN_1
    assert AirthingsDeviceType("2920") == AirthingsDeviceType.WAVE_MINI
    assert AirthingsDeviceType("2930") == AirthingsDeviceType.WAVE_PLUS
    assert AirthingsDeviceType("2950") == AirthingsDeviceType.WAVE_RADON
    assert AirthingsDeviceType("3210") == AirthingsDeviceType.WAVE_ENHANCE_EU
    assert AirthingsDeviceType("3220") == AirthingsDeviceType.WAVE_ENHANCE_US
    with pytest.raises(ValueError):
        AirthingsDeviceType("1234")

    assert AirthingsDeviceType.from_raw_value("2900") == AirthingsDeviceType.WAVE_GEN_1
    assert AirthingsDeviceType.from_raw_value("2920") == AirthingsDeviceType.WAVE_MINI
    assert AirthingsDeviceType.from_raw_value("2930") == AirthingsDeviceType.WAVE_PLUS
    assert AirthingsDeviceType.from_raw_value("2950") == AirthingsDeviceType.WAVE_RADON
    assert (
        AirthingsDeviceType.from_raw_value("3210")
        == AirthingsDeviceType.WAVE_ENHANCE_EU
    )
    assert (
        AirthingsDeviceType.from_raw_value("3220")
        == AirthingsDeviceType.WAVE_ENHANCE_US
    )

    unknown_device = AirthingsDeviceType.from_raw_value("1234")
    assert unknown_device == AirthingsDeviceType.UNKNOWN
    assert unknown_device.product_name == "Unknown"
    assert unknown_device.raw_value == "1234"


def test_battery_calculation() -> None:
    """Test battery calculation for all devices."""
    # Starting with the Wave Mini, since it has a different battery voltage range.
    # Max voltage is 4.5V, min voltage is 2.4V.

    # Starting with 5V, which is more than the max voltage
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(5.0) == 100
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(4.5) == 100
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(4.2) == 85
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(3.9) == 62
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(3.75) == 42
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(3.3) == 23
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(2.4) == 0
    assert AirthingsDeviceType.WAVE_MINI.battery_percentage(2.3) == 0

    # Repeat for the rest of the devices since they have the same amount of batteries.
    # Max voltage is 3.0V, min voltage is 2.1V.
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(3.2) == 100
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(3.0) == 100
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.8) == 81
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.6) == 53
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.5) == 28
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.2) == 5
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.1) == 0
    assert AirthingsDeviceType.WAVE_PLUS.battery_percentage(2.0) == 0

    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(3.2) == 100
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(3.0) == 100
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.8) == 81
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.6) == 53
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.5) == 28
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.2) == 5
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.1) == 0
    assert AirthingsDeviceType.WAVE_RADON.battery_percentage(2.0) == 0

    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(3.2) == 100
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(3.0) == 100
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.8) == 81
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.6) == 53
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.5) == 28
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.2) == 5
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.1) == 0
    assert AirthingsDeviceType.WAVE_GEN_1.battery_percentage(2.0) == 0

    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(3.2) == 100
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(3.0) == 100
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.8) == 81
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.6) == 53
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.5) == 28
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.2) == 5
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.1) == 0
    assert AirthingsDeviceType.WAVE_ENHANCE_EU.battery_percentage(2.0) == 0