diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/collectors/python.d.plugin/am2320/am2320.chart.py | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/collectors/python.d.plugin/am2320/am2320.chart.py')
-rw-r--r-- | src/collectors/python.d.plugin/am2320/am2320.chart.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/collectors/python.d.plugin/am2320/am2320.chart.py b/src/collectors/python.d.plugin/am2320/am2320.chart.py new file mode 100644 index 000000000..8e66544bd --- /dev/null +++ b/src/collectors/python.d.plugin/am2320/am2320.chart.py @@ -0,0 +1,68 @@ +# _*_ coding: utf-8 _*_ +# Description: AM2320 netdata module +# Author: tommybuck +# SPDX-License-Identifier: GPL-3.0-or-Later + +try: + import board + import busio + import adafruit_am2320 + + HAS_AM2320 = True +except ImportError: + HAS_AM2320 = False + +from bases.FrameworkServices.SimpleService import SimpleService + +ORDER = [ + 'temperature', + 'humidity', +] + +CHARTS = { + 'temperature': { + 'options': [None, 'Temperature', 'celsius', 'temperature', 'am2320.temperature', 'line'], + 'lines': [ + ['temperature'] + ] + }, + 'humidity': { + 'options': [None, 'Relative Humidity', 'percentage', 'humidity', 'am2320.humidity', 'line'], + 'lines': [ + ['humidity'] + ] + } +} + + +class Service(SimpleService): + def __init__(self, configuration=None, name=None): + SimpleService.__init__(self, configuration=configuration, name=name) + self.order = ORDER + self.definitions = CHARTS + self.am = None + + def check(self): + if not HAS_AM2320: + self.error("Could not find the adafruit-circuitpython-am2320 package.") + return False + + try: + i2c = busio.I2C(board.SCL, board.SDA) + self.am = adafruit_am2320.AM2320(i2c) + except ValueError as error: + self.error("error on creating I2C shared bus : {0}".format(error)) + return False + + return True + + def get_data(self): + try: + return { + 'temperature': self.am.temperature, + 'humidity': self.am.relative_humidity, + } + + except (OSError, RuntimeError) as error: + self.error(error) + return None |