From a00176d7bcb8b1799916df9054c45cb0a02a0d77 Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Tue, 6 Dec 2022 23:00:55 +0000 Subject: [PATCH] Enable pre-heat for PMSx003 sensors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PMSA003 sensor takes approximately 10 seconds to warm up, with InconsistentObservation and WrongMessageFormat exceptions raised for earlier samples. From experimentation, 10 seconds is almost exactly the warm up time, but the datasheet actually recommends 30s [^1]: Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan’s performance. However, it makes sense to set this number based on what happens in practice; we can always increase if others observe worse behaviour. [^1]: https://cdn.shopify.com/s/files/1/0176/3274/files/PMSA003_datasheet.pdf?v=1619703 --- src/pms/sensors/plantower/pmsx003.py | 1 + tests/core/test_reader.py | 2 ++ tests/sensors/test_sensor.py | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pms/sensors/plantower/pmsx003.py b/src/pms/sensors/plantower/pmsx003.py index f37d0a5..5f80de6 100644 --- a/src/pms/sensors/plantower/pmsx003.py +++ b/src/pms/sensors/plantower/pmsx003.py @@ -13,6 +13,7 @@ ALIASES = ("PMS1003", "G1", "PMS5003", "G5", "PMS7003", "G7", "PMSA003", "G10") +PREHEAT = 10 # 10 seconds commands = base.Commands( passive_read=base.Cmd(b"\x42\x4D\xE2\x00\x00\x01\x71", b"\x42\x4D\x00\x1c", 32), diff --git a/tests/core/test_reader.py b/tests/core/test_reader.py index 429ac71..0ccc455 100644 --- a/tests/core/test_reader.py +++ b/tests/core/test_reader.py @@ -158,6 +158,8 @@ def factory( lambda: None, ) + sensor_reader.pre_heat = 0 # disable any preheat + return sensor_reader return factory diff --git a/tests/sensors/test_sensor.py b/tests/sensors/test_sensor.py index 4830158..0963182 100644 --- a/tests/sensors/test_sensor.py +++ b/tests/sensors/test_sensor.py @@ -29,7 +29,12 @@ def test_baud(sensor): @pytest.mark.parametrize("sensor", Supported) def test_pre_heat(sensor): - pre_heat = 0 if sensor != "MHZ19B" else 180 + if sensor == "MHZ19B": + pre_heat = 180 + elif sensor == "PMSx003": + pre_heat = 10 + else: + pre_heat = 0 assert Sensor[sensor].pre_heat == pre_heat