mqtt-io icon indicating copy to clipboard operation
mqtt-io copied to clipboard

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

Open mihadoo opened this issue 2 years ago • 2 comments

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.

mihadoo avatar Jun 09 '22 19:06 mihadoo

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:

BoW2EviL avatar May 05 '23 19:05 BoW2EviL

Thanks

mihadoo avatar May 07 '23 10:05 mihadoo