Skip to content

Commit ca28304

Browse files
committed
split extra commands
1 parent d468fff commit ca28304

File tree

5 files changed

+56
-59
lines changed

5 files changed

+56
-59
lines changed

src/pms/sensor/honeywell/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import hpma115s0, hpma115c0
1+
from . import hpma115s0, hpma115c0, extra_commands
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Additional commands for Honeywell sensors
2+
3+
HPM Series, Particulate Matter Sensors, 32322550 Issue F
4+
https://sensing.honeywell.com/honeywell-sensing-particulate-hpm-series-datasheet-32322550
5+
"""
6+
7+
from pms.sensor.base import Cmd
8+
9+
10+
def read_cf() -> Cmd:
11+
"""Read Customer Adjustment Coefficient
12+
13+
HPM Series, Table 4 and Table 6
14+
"""
15+
return Cmd(b"\x68\x01\x10\x87", b"\x40\x02\x10", 5)
16+
17+
18+
def write_cf(cf: int = 0) -> Cmd:
19+
"""Set Customer Adjustment Coefficient
20+
21+
HPM Series, Table 4 and Table 6
22+
cf: 30 ~ 200 (Default, 100)
23+
"""
24+
25+
assert 30 <= cf <= 200, f"out of range: 30 <= {cf} <= 200"
26+
return Cmd(bytes.fromhex(f"680208{cf:02X}{(0xff8e-cf)%0x100:02X}"), b"\xA5\xA5", 2)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import sds01x, sds198
1+
from . import sds01x, sds198, extra_commands
+26-56
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,42 @@
1-
from pms.sensor.base import Cmd
2-
1+
"""Additional commands for NovaFitness sensors
32
4-
class SDS:
5-
"""Additional commands for NovaFitness sensors
6-
7-
Laser Dust Sensor Control Protocol V1.3
8-
https://learn.watterott.com/sensors/sds011/sds011_protocol.pdf
9-
"""
3+
Laser Dust Sensor Control Protocol V1.3
4+
https://learn.watterott.com/sensors/sds011/sds011_protocol.pdf
5+
"""
106

11-
@staticmethod
12-
def _msg(cmd: int, payload: str, device: int = 0xFFFF) -> bytes:
13-
assert 0 <= cmd <= 0xFF, f"command id out of range: 0 <= {cmd} <= 0xFF"
14-
assert 0 <= device <= 0xFFFF, f"device id out of range: 0 <= {device} <= 0xFFFF"
15-
checksum = sum(bytes.fromhex(payload)) + device // 0x100 + device % 0x100
16-
return bytes.fromhex(f"AA{cmd:02X}{payload}{device:04X}{checksum%0x100:02X}AB")
177

18-
@classmethod
19-
def write_id(cls, new_id: int, device: int = 0xFFFF) -> Cmd:
20-
"""Protocol V1.3, section 3) Set Device ID
8+
from pms.sensor.base import Cmd
219

22-
The setting is still effective after power off [Factory default has set a unique ID]
23-
"""
24-
return Cmd(cls._msg(0xB4, f"0500000000000000000000{new_id:02X}", device), b"\xAA\xC0", 10)
2510

26-
@classmethod
27-
def work_period(cls, minutes: int = 0, device: int = 0xFFFF) -> Cmd:
28-
"""Protocol V1.3, section 5) Set working period
11+
def _msg(cmd: int, payload: str, device: int = 0xFFFF) -> bytes:
12+
assert 0 <= cmd <= 0xFF, f"command id out of range: 0 <= {cmd} <= 0xFF"
13+
assert 0 <= device <= 0xFFFF, f"device id out of range: 0 <= {device} <= 0xFFFF"
14+
checksum = sum(bytes.fromhex(payload)) + device // 0x100 + device % 0x100
15+
return bytes.fromhex(f"AA{cmd:02X}{payload}{device:04X}{checksum%0x100:02X}AB")
2916

30-
The setting is still effective after power off [factory default is continuous measurement]
31-
The sensor works periodically and reports the latest data.
3217

33-
0 minute: continuous mode (default), i.e. report every 1 second
34-
1-30 minutes: sample for 30 secors and sleep the rest of the period
35-
"""
18+
def write_id(new_id: int, device: int = 0xFFFF) -> Cmd:
19+
"""Protocol V1.3, section 3) Set Device ID
3620
37-
assert 0 <= minutes <= 30, f"minutes out of range: 0 <= {minutes} <= 30"
38-
return Cmd(
39-
cls._msg(0xB4, f"0801{minutes:02X}00000000000000000000", device), b"\xAA\xC0", 10
40-
)
21+
The setting is still effective after power off [Factory default has set a unique ID]
22+
"""
23+
return Cmd(_msg(0xB4, f"0500000000000000000000{new_id:02X}", device), b"\xAA\xC0", 10)
4124

42-
@classmethod
43-
def firmware_version(cls, device: int = 0xFFFF) -> Cmd:
44-
"""Protocol V1.3, 6) Check firmware version"""
45-
return Cmd(cls._msg(0xB4, "07000000000000000000000000", device), b"\xAA\xC0", 10)
4625

26+
def work_period(minutes: int = 0, device: int = 0xFFFF) -> Cmd:
27+
"""Protocol V1.3, section 5) Set working period
4728
48-
class HPMA:
49-
"""Additional commands for Honeywell sensors
29+
The setting is still effective after power off [factory default is continuous measurement]
30+
The sensor works periodically and reports the latest data.
5031
51-
HPM Series, Particulate Matter Sensors, 32322550 Issue F
52-
https://sensing.honeywell.com/honeywell-sensing-particulate-hpm-series-datasheet-32322550
32+
0 minute: continuous mode (default), i.e. report every 1 second
33+
1-30 minutes: sample for 30 secors and sleep the rest of the period
5334
"""
5435

55-
@staticmethod
56-
def read_cf() -> Cmd:
57-
"""Read Customer Adjustment Coefficient
58-
59-
HPM Series, Table 4 and Table 6
60-
"""
61-
return Cmd(b"\x68\x01\x10\x87", b"\x40\x02\x10", 5)
62-
63-
@staticmethod
64-
def write_cf(cf: int = 0) -> Cmd:
65-
"""Set Customer Adjustment Coefficient
36+
assert 0 <= minutes <= 30, f"minutes out of range: 0 <= {minutes} <= 30"
37+
return Cmd(_msg(0xB4, f"0801{minutes:02X}00000000000000000000", device), b"\xAA\xC0", 10)
6638

67-
HPM Series, Table 4 and Table 6
68-
cf: 30 ~ 200 (Default, 100)
69-
"""
7039

71-
assert 30 <= cf <= 200, f"out of range: 30 <= {cf} <= 200"
72-
return Cmd(bytes.fromhex(f"680208{cf:02X}{(0xff8e-cf)%0x100:02X}"), b"\xA5\xA5", 2)
40+
def firmware_version(device: int = 0xFFFF) -> Cmd:
41+
"""Protocol V1.3, 6) Check firmware version"""
42+
return Cmd(_msg(0xB4, "07000000000000000000000000", device), b"\xAA\xC0", 10)

tests/sensor/test_extra_commands.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import pytest
33

44
os.environ["LEVEL"] = "DEBUG"
5-
from pms.sensor.novafitness.extra_commands import SDS, HPMA
5+
import pms.sensor.novafitness.extra_commands as SDS
6+
import pms.sensor.honeywell.extra_commands as HPMA
67

78

89
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)