Skip to content

Commit

Permalink
Implements logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fdobrovolny committed May 10, 2023
1 parent d06dc42 commit c80d3f2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/mh_zxx/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ def read(self) -> Tuple[int, float, int, int]:
Read all values.
:note: last value is auto calibration point, see
:link: https://revspace.nl/MH-Z19#Command_set
:link: https://revspace.nl/MHZ19#Command_set
:return: CO2 concentration, temperature, status, co2 auto calibration point
"""
logger.debug("Reading values from sensor")
self._write_command(self.READ_CO2)
response = self._read_response()
if response[0] != 0xFF or response[1] != 0x86:
logger.error("Invalid response: %s" % response)
raise ValueError("Invalid response")
elif response[8] != self._checksum(response[:8]):
logger.error("Invalid checksum: %s" % response)
raise ValueError("Invalid checksum")

return (
Expand All @@ -100,12 +103,14 @@ def zero_calibration(self):
"""
Zero calibration.
"""
logger.info("Zero calibration")
self._write_command(self.ZERO_CALIBRATION)

def span_calibration(self, span: int):
"""
Span calibration.
"""
logger.info("Span calibration to %d" % span)
command = self.SPAN_CALIBRATION.copy()
command[3] = span // 256
command[4] = span % 256
Expand All @@ -115,6 +120,7 @@ def set_auto_calibration(self, state: bool):
"""
Set auto calibration point.
"""
logger.info("Setting auto calibration to %s" % state)
if state:
self._write_command(self.AUTO_CALIBRATION)
else:
Expand All @@ -124,4 +130,5 @@ def close(self):
"""
Close serial port.
"""
logger.info("Closing serial port")
self.serial.close()

0 comments on commit c80d3f2

Please sign in to comment.