Skip to content

Added sensor properties + example to reflect consistency changes #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions adafruit_sgp30.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ def __init__(self, i2c, address=_SGP30_DEFAULT_I2C_ADDR):
raise RuntimeError('SGP30 Not detected')
self.iaq_init()

self._co2eq = None # pylint: disable=invalid-name
self._tvoc = None # pylint: disable=invalid-name
self._baseline_tvoc = None # pylint: disable=invalid-name
self._baseline_co2eq = None # pylint: disable=invalid-name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need these because you always update them in the property getter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!



@property
def tvoc(self): # pylint: disable=invalid-name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like valid names to me. Did you copy the lint part from somewhere else? I don't think they are needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was copying that from the CCS811 library. I'll remove.

"""Total Volatile Organic Compound in parts per billion."""
self._tvoc = self.iaq_measure()[1]
return self._tvoc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return self.iaq_measure()[1] and similar below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed - thanks (will keep this in mind next time)!



@property
def baseline_tvoc(self): #pylint: disable=invalid-name
"""Total Volatile Organic Compound baseline value"""
self._baseline_tvoc = self.get_iaq_baseline()[1]
return self._baseline_tvoc


@property
def co2eq(self): #pylint: disable=invalid-name
"""Carbon Dioxide Equivalent in parts per million"""
self._co2eq = self.iaq_measure()[0]
return self._co2eq


@property
def baseline_co2eq(self): #pylint: disable=invalid-name
"""Carbon Dioxide Equivalent baseline value"""
self._baseline_co2eq = self.get_iaq_baseline()[0]
return self._baseline_co2eq


def iaq_init(self):
"""Initialize the IAQ algorithm"""
# name, command, signals, delay
Expand Down
5 changes: 3 additions & 2 deletions examples/sgp30_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

while True:
co2eq, tvoc = sgp30.iaq_measure()
print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))
print("co2eq = %d ppm \t tvoc = %d ppb" % (sgp30.co2eq, sgp30.tvoc))
time.sleep(1)
elapsed_sec += 1
if elapsed_sec > 10:
elapsed_sec = 0
co2eq_base, tvoc_base = sgp30.get_iaq_baseline()
print("**** Baseline values: CO2eq = 0x%x, TVOC = 0x%x" % (co2eq_base, tvoc_base))
print("**** Baseline values: co2eq = 0x%x, tvoc = 0x%x"
% (sgp30.baseline_co2eq, sgp30.baseline_tvoc))