flyte / mqtt-io

Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.
MIT License
476 stars 159 forks source link

Support i2c_bus_num for all i2c devices (i.e. aht20) #271

Open mihadoo opened 2 years ago

mihadoo commented 2 years ago

i2c_bus_num in yml is supported for lm75. However it is not supported for example for aht20.

Please add support for i2c_bus_num to all supported i2c devices.

BoW2EviL commented 1 year ago

this is how i fixed that i also formated the output to F dont change that part if you dont want it.

for the experts HEAD 23f7b7474952f0c75960b74d709423233a67baed

git diff
--- a/mqtt_io/modules/sensor/aht20.py
+++ b/mqtt_io/modules/sensor/aht20.py
@@ -9,6 +9,9 @@ from . import GenericSensor
 from ...exceptions import RuntimeConfigError

 REQUIREMENTS = ("adafruit-circuitpython-ahtx0",)
+CONFIG_SCHEMA = {
+    "chip_addr": {"type": "integer", "required": True, "empty": False},
+}

 class Sensor(GenericSensor):
@@ -33,11 +36,12 @@ class Sensor(GenericSensor):
         import busio  # type: ignore

         i2c = busio.I2C(board.SCL, board.SDA)
-        self.sensor = adafruit_ahtx0.AHTx0(i2c)
+        self.address: int = self.config["chip_addr"]
+        self.sensor = adafruit_ahtx0.AHTx0(i2c, self.address)

     @property
     def _temperature(self) -> SensorValueType:
-        return cast(SensorValueType, self.sensor.temperature)
+        return cast(SensorValueType, (self.sensor.temperature * 1.8) + 32)

     @property
     def _humidity(self) -> SensorValueType:
mihadoo commented 1 year ago

Thanks