From e4636bc73f73d4af8c528b2e83f34a2696c01321 Mon Sep 17 00:00:00 2001 From: Michael Schlenstedt Date: Mon, 5 Aug 2024 06:11:25 +0200 Subject: [PATCH] fix pylint issues --- mqtt_io/modules/sensor/tsl2561.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mqtt_io/modules/sensor/tsl2561.py b/mqtt_io/modules/sensor/tsl2561.py index bbd5f229..615ef05f 100644 --- a/mqtt_io/modules/sensor/tsl2561.py +++ b/mqtt_io/modules/sensor/tsl2561.py @@ -6,7 +6,7 @@ from ...types import CerberusSchemaType, ConfigType, SensorValueType from . import GenericSensor -REQUIREMENTS = ("adafruit-circuitpython-tsl2561",) # type: ignore +REQUIREMENTS = ("adafruit-circuitpython-tsl2561",) CONFIG_SCHEMA: CerberusSchemaType = { "chip_addr": { "type": 'integer', @@ -48,7 +48,7 @@ def setup_module(self) -> None: # pylint: disable=import-error,no-member import board # type: ignore import busio # type: ignore - import adafruit_tsl2561 + import adafruit_tsl2561 # type: ignore # Create the I2C bus self.i2c = busio.I2C(board.SCL, board.SDA) @@ -63,7 +63,6 @@ def setup_module(self) -> None: self.tsl = adafruit_tsl2561.TSL2561(self.i2c, self.address) - # Set gain 0=1x, 1=16x if self.config["gain"] == 1: self.tsl.gain = 0 @@ -85,15 +84,22 @@ def setup_module(self) -> None: #print("tsl2561 Integration time = {}".format(self.tsl.integration_time)) def get_value(self, sens_conf: ConfigType) -> SensorValueType: - """ - Get the values from the sensor - """ + # pylint: disable=import-outside-toplevel,attribute-defined-outside-init + # pylint: disable=import-error,no-member + import time + + self.tsl.enabled = True + time.sleep(1) + sens_type = sens_conf["type"] data = { "broadband": self.tsl.broadband, "infrared": self.tsl.infrared, "lux": self.tsl.lux } + + self.tsl.enabled = False + if data[sens_type] is None: # Possible sensor underrange or overrange. data[sens_type] = -1