Skip to content

Commit

Permalink
Merge pull request #5 from FEEprojects/improve-test
Browse files Browse the repository at this point in the history
Improve test
  • Loading branch information
FlorentinBulotAQ authored Feb 10, 2020
2 parents 8fc5297 + bc5b1c3 commit 2fc5b20
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 26 deletions.
8 changes: 7 additions & 1 deletion plantower/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
from .plantower import PlantowerReading, Plantower, PlantowerException
from .plantower import (
PlantowerReading,
Plantower,
PlantowerException,
PMS_PASSIVE_MODE,
PMS_ACTIVE_MODE
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="plantower",
version="0.0.10",
version="0.0.11",
author="Philip Basford",
author_email="[email protected]",
description="An interface for plantower particulate matter sensors",
Expand Down
47 changes: 23 additions & 24 deletions test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
# test code for sleep wakeup with passive mode
pt = plantower.Plantower(port='COM3')
#!/usr/bin/env python3
"""
Basic test script to demonstrate active mode of the plantower
"""

pt.set_to_sleep()
time.sleep(5)
from argparse import ArgumentParser
import time
import plantower

pt.set_to_wakeup()
pt.mode_change(0)
time.sleep(10)

result = pt.read_in_passive()
pt.set_to_sleep()
print(result)
exit(0)


# test code for passive mode
pt = plantower.Plantower(port='COM3')
pt.mode_change(0)
time.sleep(5)
result = pt.read_in_passive()
print(result)
exit(0)

PARSER = ArgumentParser(
description="Test plantower code in active mode")
PARSER.add_argument(
"port",
action="store",
help="The serial port to use")
ARGS = PARSER.parse_args()

# test code for active mode
pt = plantower.Plantower(port='COM3')
print(pt.read())

PLANTOWER = plantower.Plantower(port=ARGS.port)
print("Making sure it's correctly setup for active mode. Please wait")
#make sure it's in the correct mode if it's been used for passive beforehand
#Not needed if freshly plugged in
PLANTOWER.mode_change(plantower.PMS_ACTIVE_MODE) #change back into active mode
PLANTOWER.set_to_wakeup() #ensure fan is spinning
time.sleep(30) # give it a chance to stabilise
#actually do the reading
print(PLANTOWER.read())
25 changes: 25 additions & 0 deletions test_passive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""
Basic test script to demonstrate passive mode of the plantower
"""
from argparse import ArgumentParser
import time
import plantower


PARSER = ArgumentParser(
description="Test plantower code in passive mode")
PARSER.add_argument(
"port",
action="store",
help="The serial port to use")
ARGS = PARSER.parse_args()


PLANTOWER = plantower.Plantower(port=ARGS.port) # create the object
print("Setting sensor into passive mode. Please wait.")
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE) #change into passive mode
PLANTOWER.set_to_wakeup() #spin up the fan
time.sleep(30) #give the sensor a chance to settle
RESULT = PLANTOWER.read_in_passive() # request data in passive mode
print(RESULT)
31 changes: 31 additions & 0 deletions test_passive_sleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""
Basic test script to demonstrate passive mode with fan turn off for the plantower
"""
import time
from argparse import ArgumentParser
import plantower


PARSER = ArgumentParser(
description="Test plantower code in passive mode with fan turn off")
PARSER.add_argument(
"port",
action="store",
help="The serial port to use")
ARGS = PARSER.parse_args()


PLANTOWER = plantower.Plantower(port=ARGS.port)
print("Turning off the fan for 15s")
PLANTOWER.set_to_sleep() #Stop the fan in the sensor
time.sleep(15)
print("Waking back up. Please wait")
PLANTOWER.set_to_wakeup() # Start the fan in the sensor
PLANTOWER.mode_change(plantower.PMS_PASSIVE_MODE)
time.sleep(30) # Give the readings a chance to settle after fan spin up
#30s is suggested in the datasheet

RESULT = PLANTOWER.read_in_passive() # request data in passive mode
PLANTOWER.set_to_sleep() # turn fan off again
print(RESULT)

0 comments on commit 2fc5b20

Please sign in to comment.