diff --git a/adafruit_scd4x.py b/adafruit_scd4x.py index 22ed6b8..fc770b3 100644 --- a/adafruit_scd4x.py +++ b/adafruit_scd4x.py @@ -229,11 +229,29 @@ def stop_periodic_measurement(self): self._send_command(_SCD4X_STOPPERIODICMEASUREMENT, cmd_delay=0.5) def start_periodic_measurement(self): - """Put sensor into working mode, about 5s per measurement""" + """Put sensor into working mode, about 5s per measurement + + .. note:: + Only the following commands will work once in working mode: + + * :attr:`CO2 ` + * :attr:`temperature ` + * :attr:`relative_humidity ` + * :meth:`data_ready() ` + * :meth:`reinit() ` + * :meth:`factory_reset() ` + * :meth:`force_calibration() ` + * :meth:`self_test() ` + * :meth:`set_ambient_pressure() ` + + """ self._send_command(_SCD4X_STARTPERIODICMEASUREMENT) def start_low_periodic_measurement(self): - """Put sensor into low power working mode, about 30s per measurement""" + """Put sensor into low power working mode, about 30s per measurement. See + :meth:`start_periodic_measurement() ` + for more details. + """ self._send_command(_SCD4X_STARTLOWPOWERPERIODICMEASUREMENT) def persist_settings(self): @@ -303,8 +321,14 @@ def _send_command(self, cmd: int, cmd_delay: float = 0) -> None: self._cmd[0] = (cmd >> 8) & 0xFF self._cmd[1] = cmd & 0xFF - with self.i2c_device as i2c: - i2c.write(self._cmd, end=2) + try: + with self.i2c_device as i2c: + i2c.write(self._cmd, end=2) + except OSError as err: + raise RuntimeError( + "Could not communicate via I2C, some commands/settings " + "unavailable while in working mode" + ) from err time.sleep(cmd_delay) def _set_command_value(self, cmd, value, cmd_delay=0):