adafruit / Adafruit_CircuitPython_SCD4X

CircuitPython/Python driver for Sensirion SCD40 & SCD41
MIT License
20 stars 10 forks source link

Guard against idle mode only methods? #10

Closed caternuson closed 2 years ago

caternuson commented 2 years ago

Some commands only work in idle mode, altitude for example: image

This can lead to potentially unexpected hiccups in user code:

>>> scd4x.altitude = 42
>>> scd4x.altitude
42
>>> scd4x.start_periodic_measurement()
>>> scd4x.altitude
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_scd4x.py", line 284, in altitude
  File "adafruit_scd4x.py", line 307, in _send_command
OSError: [Errno 5] Input/output error
>>> 

Could just catch this in user code, but might be better to handle this more gracefully here in driver code?

ladyada commented 2 years ago

ermm maybe throw an exception so at least they know what happened?

caternuson commented 2 years ago

like just catch the OSError here and throw something else with a more helpful message?

ladyada commented 2 years ago

yaz

caternuson commented 2 years ago

Fixed with #13.