Skip to content

Commit 2fc5b20

Browse files
Merge pull request #5 from FEEprojects/improve-test
Improve test
2 parents 8fc5297 + bc5b1c3 commit 2fc5b20

File tree

5 files changed

+87
-26
lines changed

5 files changed

+87
-26
lines changed

plantower/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
from .plantower import PlantowerReading, Plantower, PlantowerException
1+
from .plantower import (
2+
PlantowerReading,
3+
Plantower,
4+
PlantowerException,
5+
PMS_PASSIVE_MODE,
6+
PMS_ACTIVE_MODE
7+
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="plantower",
8-
version="0.0.10",
8+
version="0.0.11",
99
author="Philip Basford",
1010
author_email="[email protected]",
1111
description="An interface for plantower particulate matter sensors",

test.py

100644100755
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
# test code for sleep wakeup with passive mode
2-
pt = plantower.Plantower(port='COM3')
1+
#!/usr/bin/env python3
2+
"""
3+
Basic test script to demonstrate active mode of the plantower
4+
"""
35

4-
pt.set_to_sleep()
5-
time.sleep(5)
6+
from argparse import ArgumentParser
7+
import time
8+
import plantower
69

7-
pt.set_to_wakeup()
8-
pt.mode_change(0)
9-
time.sleep(10)
10-
11-
result = pt.read_in_passive()
12-
pt.set_to_sleep()
13-
print(result)
14-
exit(0)
15-
16-
17-
# test code for passive mode
18-
pt = plantower.Plantower(port='COM3')
19-
pt.mode_change(0)
20-
time.sleep(5)
21-
result = pt.read_in_passive()
22-
print(result)
23-
exit(0)
2410

11+
PARSER = ArgumentParser(
12+
description="Test plantower code in active mode")
13+
PARSER.add_argument(
14+
"port",
15+
action="store",
16+
help="The serial port to use")
17+
ARGS = PARSER.parse_args()
2518

2619
# test code for active mode
27-
pt = plantower.Plantower(port='COM3')
28-
print(pt.read())
29-
20+
PLANTOWER = plantower.Plantower(port=ARGS.port)
21+
print("Making sure it's correctly setup for active mode. Please wait")
22+
#make sure it's in the correct mode if it's been used for passive beforehand
23+
#Not needed if freshly plugged in
24+
PLANTOWER.mode_change(plantower.PMS_ACTIVE_MODE) #change back into active mode
25+
PLANTOWER.set_to_wakeup() #ensure fan is spinning
26+
time.sleep(30) # give it a chance to stabilise
27+
#actually do the reading
28+
print(PLANTOWER.read())

test_passive.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Basic test script to demonstrate passive mode of the plantower
4+
"""
5+
from argparse import ArgumentParser
6+
import time
7+
import plantower
8+
9+
10+
PARSER = ArgumentParser(
11+
description="Test plantower code in passive mode")
12+
PARSER.add_argument(
13+
"port",
14+
action="store",
15+
help="The serial port to use")
16+
ARGS = PARSER.parse_args()
17+
18+
19+
PLANTOWER = plantower.Plantower(port=ARGS.port) # create the object
20+
print("Setting sensor into passive mode. Please wait.")
21+
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE) #change into passive mode
22+
PLANTOWER.set_to_wakeup() #spin up the fan
23+
time.sleep(30) #give the sensor a chance to settle
24+
RESULT = PLANTOWER.read_in_passive() # request data in passive mode
25+
print(RESULT)

test_passive_sleep.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Basic test script to demonstrate passive mode with fan turn off for the plantower
4+
"""
5+
import time
6+
from argparse import ArgumentParser
7+
import plantower
8+
9+
10+
PARSER = ArgumentParser(
11+
description="Test plantower code in passive mode with fan turn off")
12+
PARSER.add_argument(
13+
"port",
14+
action="store",
15+
help="The serial port to use")
16+
ARGS = PARSER.parse_args()
17+
18+
19+
PLANTOWER = plantower.Plantower(port=ARGS.port)
20+
print("Turning off the fan for 15s")
21+
PLANTOWER.set_to_sleep() #Stop the fan in the sensor
22+
time.sleep(15)
23+
print("Waking back up. Please wait")
24+
PLANTOWER.set_to_wakeup() # Start the fan in the sensor
25+
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE)
26+
time.sleep(30) # Give the readings a chance to settle after fan spin up
27+
#30s is suggested in the datasheet
28+
29+
RESULT = PLANTOWER.read_in_passive() # request data in passive mode
30+
PLANTOWER.set_to_sleep() # turn fan off again
31+
print(RESULT)

0 commit comments

Comments
 (0)