From 87f7d3ebe6e82476cd279e4a637a86a8455cad85 Mon Sep 17 00:00:00 2001 From: Benji <46675043+BenjiU@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:22:22 +0200 Subject: [PATCH] fix docutil dependencies (#389) * fix docutil dependencies * fix new pylint errors --- mqtt_io/modules/gpio/sunxi.py | 57 +++++++++++++++++++++++++++++ mqtt_io/modules/sensor/bmp085.py | 16 ++++----- mqtt_io/modules/sensor/ens160.py | 49 +++++++++++++------------ mqtt_io/modules/sensor/mhz19.py | 6 ++-- mqtt_io/modules/sensor/yfs201.py | 10 +++--- pi_mqtt_gpio/modules/bme280.py | 61 -------------------------------- pi_mqtt_gpio/modules/sunxi.py | 51 -------------------------- pyproject.toml | 2 +- 8 files changed, 100 insertions(+), 152 deletions(-) create mode 100644 mqtt_io/modules/gpio/sunxi.py delete mode 100644 pi_mqtt_gpio/modules/bme280.py delete mode 100644 pi_mqtt_gpio/modules/sunxi.py diff --git a/mqtt_io/modules/gpio/sunxi.py b/mqtt_io/modules/gpio/sunxi.py new file mode 100644 index 00000000..a418104a --- /dev/null +++ b/mqtt_io/modules/gpio/sunxi.py @@ -0,0 +1,57 @@ +""" +Sunxi Board +""" +from typing import Optional +from ...types import ConfigType, PinType +from . import GenericGPIO, PinDirection, PinPUD + +REQUIREMENTS = ("pySUNXI",) + +class GPIO(GenericGPIO): + """ + Implementation of GPIO class for Sunxi native GPIO. + """ + def setup_module(self) -> None: + # pylint: disable=import-outside-toplevel,import-error + from pySUNXI import gpio # type: ignore + + self.io: gpio = gpio + self.direction_map = {PinDirection.INPUT: gpio.INPUT, PinDirection.OUTPUT: gpio.OUTPUT} + + self.pullup_map = { + PinPUD.OFF: gpio.PULLNONE, + PinPUD.UP: gpio.PULLUP, + PinPUD.DOWN: gpio.PULLDOWN, + } + gpio.init() + + def setup_pin( + self, + pin: PinType, + direction: PinDirection, + pullup: PinPUD, + pin_config: ConfigType, + initial: Optional[str] = None, + ) -> None: + direction = self.direction_map[direction] + + if pullup is None: + pullup = self.pullup_map[PinPUD.OFF] + else: + pullup = self.pullup_map[pullup] + + initial_state = {None: -1, "low": 0, "high": 1}[initial] + #self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) + self.io.setcfg(pin, direction) + self.io.pullup(pin, pullup) + if direction==self.io.OUTPUT: + self.io.output(pin, initial_state) + + def set_pin(self, pin: PinType, value: bool) -> None: + self.io.output(pin, value) + + def get_pin(self, pin: PinType) -> bool: + return bool(self.io.input(pin)) + + def cleanup(self) -> None: + pass diff --git a/mqtt_io/modules/sensor/bmp085.py b/mqtt_io/modules/sensor/bmp085.py index 768f5791..542752dd 100644 --- a/mqtt_io/modules/sensor/bmp085.py +++ b/mqtt_io/modules/sensor/bmp085.py @@ -9,7 +9,7 @@ REQUIREMENTS = ("Adafruit_BMP",) CONFIG_SCHEMA: CerberusSchemaType = { - "chip_addr": dict(type="integer", required=True, empty=False), + "chip_addr": {"type": 'integer', "required": True, "empty": False}, } DATA_READER = { "temperature": lambda bmp: bmp.read_temperature(), @@ -24,13 +24,13 @@ class Sensor(GenericSensor): """ SENSOR_SCHEMA: CerberusSchemaType = { - "type": dict( - type="string", - required=False, - empty=False, - default="temperature", - allowed=["temperature", "pressure", "altitude"], - ) + "type": { + "type": 'string', + "required": False, + "empty": False, + "default": 'temperature', + "allowed": ['temperature', 'pressure', 'altitude'], + } } def setup_module(self) -> None: diff --git a/mqtt_io/modules/sensor/ens160.py b/mqtt_io/modules/sensor/ens160.py index 526f1906..b8da64a3 100644 --- a/mqtt_io/modules/sensor/ens160.py +++ b/mqtt_io/modules/sensor/ens160.py @@ -40,21 +40,24 @@ REQUIREMENTS = ("adafruit-circuitpython-ens160",) CONFIG_SCHEMA: CerberusSchemaType = { - "chip_addr": dict( - type="integer", required=False, empty=False, default=DEFAULT_CHIP_ADDR - ), - "temperature_compensation": dict( - type="float", - required=False, - empty=False, - default=DEFAULT_TEMPERATURE_COMPENSATION, - ), - "humidity_compensation": dict( - type="float", - required=False, - empty=False, - default=DEFAULT_HUMIDITY_COMPENSATION, - ), + "chip_addr": { + "type": 'integer', + "required": False, + "empty": False, + "default": 'DEFAULT_CHIP_ADDR', + }, + "temperature_compensation": { + "type": 'float', + "required": False, + "empty": False, + "default": 'DEFAULT_TEMPERATURE_COMPENSATION', + }, + "humidity_compensation": { + "type": 'float', + "required": False, + "empty": False, + "default": 'DEFAULT_HUMIDITY_COMPENSATION', + }, } @@ -81,13 +84,13 @@ class Sensor(GenericSensor): """ SENSOR_SCHEMA: CerberusSchemaType = { - "type": dict( - type="string", - required=False, - empty=False, - default="aqi", - allowed=["aqi", "tvoc", "eco2"], - ), + "type": { + "type": 'string', + "required": False, + "empty": False, + "default": 'aqi', + "allowed": ['aqi', 'tvoc', 'eco2'], + }, } def setup_module(self) -> None: @@ -119,7 +122,7 @@ def get_value(self, sens_conf: ConfigType) -> float: sens_type = sens_conf["type"] return cast( int, - dict(aqi=self.ens160.AQI, tvoc=self.ens160.TVOC, eco2=self.ens160.eCO2)[ + {"aqi": self.ens160.AQI, "tvoc": self.ens160.TVOC, "eco2": self.ens160.eCO2}[ sens_type ], ) diff --git a/mqtt_io/modules/sensor/mhz19.py b/mqtt_io/modules/sensor/mhz19.py index 04f30ead..944970d6 100644 --- a/mqtt_io/modules/sensor/mhz19.py +++ b/mqtt_io/modules/sensor/mhz19.py @@ -7,9 +7,9 @@ REQUIREMENTS = ("pyserial",) CONFIG_SCHEMA: CerberusSchemaType = { - "device": dict(type="string", required=True, empty=False), - "range": dict(type="integer", required=False, empty=False, default=5000, - allowed=[2000, 5000, 10000]), + "device": {"type": 'string', "required": True, "empty": False}, + "range": {"type": 'integer', "required": False, "empty": False, "default": 5000, + "allowed": [2000, 5000, 10000]}, } class Sensor(GenericSensor): diff --git a/mqtt_io/modules/sensor/yfs201.py b/mqtt_io/modules/sensor/yfs201.py index 6fc3fcc0..39534c66 100644 --- a/mqtt_io/modules/sensor/yfs201.py +++ b/mqtt_io/modules/sensor/yfs201.py @@ -70,11 +70,11 @@ class Sensor(GenericSensor): """ SENSOR_SCHEMA: CerberusSchemaType = { - "pin": dict( - type="integer", - required=True, - empty=False, - ) + "pin": { + "type": 'integer', + "required": True, + "empty": False, + } } def setup_module(self) -> None: diff --git a/pi_mqtt_gpio/modules/bme280.py b/pi_mqtt_gpio/modules/bme280.py deleted file mode 100644 index 6b9a656b..00000000 --- a/pi_mqtt_gpio/modules/bme280.py +++ /dev/null @@ -1,61 +0,0 @@ -from pi_mqtt_gpio.modules import GenericSensor - -#DEVICE = 0x76 # Default device I2C address -#bus = smbus.SMBus(2) - -REQUIREMENTS = ("smbus2","RPi.bme280") - -CONFIG_SCHEMA = { - "i2c_bus_num": {"type": "integer", "required": True, "empty": False}, - "chip_addr": {"type": "integer", "required": True, "empty": False}, - } - -SENSOR_SCHEMA = { - "type": dict ( - type="string", - required=False, - empty=False, - default="temperature", - allowed=["temperature", "humidity", "pressure"], - ), -} - -class Sensor(GenericSensor): - """ - Implementation of Sensor class for the BME280 Temperature, Pressure, Humidity. - """ - - def __init__(self, config): - import smbus2 - import time - import bme280 - self.time=time - self.lastMeas=self.time.time()-2 - self.bme280=bme280 - self.addr=config["chip_addr"] - self.bus=smbus2.SMBus(config["i2c_bus_num"]) - self.calibration=self.bme280.load_calibration_params(self.bus,self.addr) - self.bmedata = self.bme280.sample(self.bus, self.addr, self.calibration) - #print("END SETUP") - - def setup_sensor(self, config): - return True # nothing to do here - - def get_value(self, config): - """get the temperature or humidity or value from the sensor""" - if (self.time.time()-self.lastMeas>2): - print("READING BME280") - try: - self.bmedata = self.bme280.sample(self.bus, self.addr, self.calibration) - self.lastMeas=self.time.time() - except: - print("BUS Error - data buffered") - else: - print("BME data buffer") - - if config["type"] == "temperature": - return self.bmedata.temperature - if config["type"] == "humidity": - return self.bmedata.humidity - if config["type"] == "pressure": - return self.bmedata.pressure diff --git a/pi_mqtt_gpio/modules/sunxi.py b/pi_mqtt_gpio/modules/sunxi.py deleted file mode 100644 index d614d245..00000000 --- a/pi_mqtt_gpio/modules/sunxi.py +++ /dev/null @@ -1,51 +0,0 @@ -from pi_mqtt_gpio.modules import GenericGPIO, PinDirection, PinPullup - - -REQUIREMENTS = ("pySUNXI",) - -DIRECTIONS = None -PULLUPS = None - - -class GPIO(GenericGPIO): - """ - Implementation of GPIO class for Sunxi native GPIO. - """ - - def __init__(self, config): - global DIRECTIONS, PULLUPS - from pySUNXI import gpio - - self.io = gpio - DIRECTIONS = {PinDirection.INPUT: gpio.INPUT, PinDirection.OUTPUT: gpio.OUTPUT} - - PULLUPS = { - PinPullup.OFF: gpio.PULLNONE, - PinPullup.UP: gpio.PULLUP, - PinPullup.DOWN: gpio.PULLDOWN, - } - gpio.init() - - def setup_pin(self, pin, direction, pullup, pin_config): - direction = DIRECTIONS[direction] - - if pullup is None: - pullup = PULLUPS[PinPullup.OFF] - else: - pullup = PULLUPS[pullup] - - initial = {None: -1, "low": 0, "high": 1}[pin_config.get("initial")] - #self.io.setup(pin, direction, pull_up_down=pullup, initial=initial) - self.io.setcfg(pin, direction) - self.io.pullup(pin, pullup) - if direction==self.io.OUTPUT: - self.io.output(pin, initial) - - def set_pin(self, pin, value): - self.io.output(pin, value) - - def get_pin(self, pin): - return self.io.input(pin) - - def cleanup(self): - pass diff --git a/pyproject.toml b/pyproject.toml index 4b711d08..41a9a98e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ Jinja2 = "^3.1.3" ast-to-xml="^0.2.3" GitPython = "^3.1.15" semver = "^2.13.0" -docutils = "^0.16" +docutils = "0.18.1" [build-system] requires = ["poetry-core>=1.0.0"]