Skip to content

Commit

Permalink
remove new pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjiU committed May 8, 2024
1 parent 5a14d7e commit b7cdd21
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 232 deletions.
10 changes: 5 additions & 5 deletions mqtt_io/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ def custom_validate_main_config(config: ConfigType) -> ConfigType:
bad_configs: Dict[str, Dict[str, List[str]]] = {}

# Make sure each of the IO configs refer to an existing module config
module_and_io_sections = dict(
gpio_modules=("digital_inputs", "digital_outputs"),
sensor_modules=("sensor_inputs",),
stream_modules=("stream_reads", "stream_writes"),
)
module_and_io_sections = {
"gpio_modules": ("digital_inputs", "digital_outputs"),
"sensor_modules": ("sensor_inputs",),
"stream_modules": ("stream_reads", "stream_writes"),
}
for module_section, io_sections in module_and_io_sections.items():
validate_gpio_module_names(bad_configs, config, module_section, io_sections)

Expand Down
2 changes: 1 addition & 1 deletion mqtt_io/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
STREAM_TOPIC = "stream"

MODULE_IMPORT_PATH = "mqtt_io.modules"
MODULE_CLASS_NAMES = dict(gpio="GPIO", sensor="Sensor", stream="Stream")
MODULE_CLASS_NAMES = {"gpio": 'GPIO', "sensor": 'Sensor', "stream": 'Stream'}

MQTT_SUB_PRIORITY = 1
MQTT_ANNOUNCE_PRIORITY = 2
Expand Down
58 changes: 29 additions & 29 deletions mqtt_io/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ def get_common_config(
Return config that's common across all HQ discovery announcements.
"""
disco_conf: ConfigType = mqtt_conf["ha_discovery"]
config = dict(name=io_conf["name"])
config = {"name": io_conf['name']}
config.update(
dict(
availability_topic="/".join(
{
"availability_topic": '/'.join(
(mqtt_conf["topic_prefix"], mqtt_conf["status_topic"])
),
payload_available=mqtt_conf["status_payload_running"],
payload_not_available=mqtt_conf["status_payload_dead"],
device=dict(
manufacturer="MQTT IO",
model=f"v{VERSION}",
identifiers=[mqtt_options.client_id],
name=disco_conf["name"],
),
)
"payload_available": mqtt_conf["status_payload_running"],
"payload_not_available": mqtt_conf["status_payload_dead"],
"device": {
"manufacturer": 'MQTT IO',
"model": f'v{VERSION}',
"identifiers": [mqtt_options.client_id],
"name": disco_conf["name"],
},
}
)
config.update(io_conf.get("ha_discovery", {}))
return config
Expand All @@ -54,12 +54,12 @@ def hass_announce_digital_input(
disco_prefix: str = disco_conf["prefix"]
sensor_config = get_common_config(in_conf, mqtt_conf, mqtt_options)
sensor_config.update(
dict(
unique_id=f"{mqtt_options.client_id}_{in_conf['module']}_input_{name}",
state_topic="/".join((mqtt_conf["topic_prefix"], INPUT_TOPIC, name)),
payload_on=in_conf["on_payload"],
payload_off=in_conf["off_payload"],
)
{
"unique_id": f'{mqtt_options.client_id}_{in_conf["module"]}_input_{name}',
"state_topic": '/'.join((mqtt_conf["topic_prefix"], INPUT_TOPIC, name)),
"payload_on": in_conf["on_payload"],
"payload_off": in_conf["off_payload"],
}
)
return MQTTMessageSend(
"/".join(
Expand Down Expand Up @@ -90,13 +90,13 @@ def hass_announce_digital_output(
disco_prefix: str = disco_conf["prefix"]
switch_config = get_common_config(out_conf, mqtt_conf, mqtt_options)
switch_config.update(
dict(
unique_id=f"{mqtt_options.client_id}_{out_conf['module']}_output_{name}",
state_topic="/".join((prefix, OUTPUT_TOPIC, name)),
command_topic="/".join((prefix, OUTPUT_TOPIC, name, SET_SUFFIX)),
payload_on=out_conf["on_payload"],
payload_off=out_conf["off_payload"],
)
{
"unique_id": f'{mqtt_options.client_id}_{out_conf["module"]}_output_{name}',
"state_topic": '/'.join((prefix, OUTPUT_TOPIC, name)),
"command_topic": '/'.join((prefix, OUTPUT_TOPIC, name, SET_SUFFIX)),
"payload_on": out_conf["on_payload"],
"payload_off": out_conf["off_payload"],
}
)
return MQTTMessageSend(
"/".join(
Expand Down Expand Up @@ -127,10 +127,10 @@ def hass_announce_sensor_input(
disco_prefix: str = disco_conf["prefix"]
sensor_config = get_common_config(sens_conf, mqtt_conf, mqtt_options)
sensor_config.update(
dict(
unique_id=f"{mqtt_options.client_id}_{sens_conf['module']}_sensor_{name}",
state_topic="/".join((prefix, SENSOR_TOPIC, name)),
)
{
"unique_id": f'{mqtt_options.client_id}_{sens_conf["module"]}_sensor_{name}',
"state_topic": '/'.join((prefix, SENSOR_TOPIC, name)),
}
)
if "expire_after" not in sensor_config:
sensor_config["expire_after"] = sens_conf["interval"] * 2 + 5
Expand Down
4 changes: 2 additions & 2 deletions mqtt_io/modules/gpio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import asyncio
import logging
from concurrent.futures import ThreadPoolExecutor
from enum import Enum, Flag, auto
from enum import Enum, Flag, IntFlag, auto
from typing import Any, Callable, Dict, Iterable, List, Optional

from ...types import ConfigType, PinType
Expand Down Expand Up @@ -48,7 +48,7 @@ class InterruptEdge(Enum):
BOTH = auto()


class InterruptSupport(Flag):
class InterruptSupport(IntFlag):
"""
Classifies the kind of support a GPIO module has for interrupts.
Expand Down
2 changes: 1 addition & 1 deletion mqtt_io/modules/gpio/mcp23017.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GPIO(GenericGPIO):
| InterruptSupport.SET_TRIGGERS
)
PIN_SCHEMA = {
"pin": dict(type="integer", required=True, min=0, max=15),
"pin": {"type": 'integer', "required": True, "min": 0, "max": 15},
}

def setup_module(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions mqtt_io/modules/gpio/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import GenericGPIO, InterruptEdge, InterruptSupport, PinDirection, PinPUD

REQUIREMENTS = ()
CONFIG_SCHEMA = dict(test=dict(type="boolean", required=False, default=False))
CONFIG_SCHEMA = {"test": {"type": 'boolean', "required": False, "default": False}}


# pylint: disable=useless-super-delegation,too-many-instance-attributes
Expand All @@ -24,7 +24,7 @@ class GPIO(GenericGPIO):
| InterruptSupport.CAPTURE_REGISTER
)
PIN_SCHEMA = {
"test": dict(type="boolean", required=False, default=False),
"test": {"type": 'boolean', "required": False, "default": False},
}

def __init__(self, config: ConfigType):
Expand Down
59 changes: 27 additions & 32 deletions mqtt_io/modules/sensor/ads1x15.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

REQUIREMENTS = ("adafruit-circuitpython-ads1x15",)
CONFIG_SCHEMA: CerberusSchemaType = {
"chip_addr": dict(type="integer", required=False, empty=False, default=0x48),
"type": dict(
type="string",
required=True,
empty=False,
allowed=SENSOR_TYPES,
),
"pins": dict(type="list", required=True, empty=False, allowed=[0, 1, 2, 3]),
"gain": dict(
required=False,
empty=False,
allowed=[0.6666666666666666, 1, 2, 4, 8, 16],
default=1,
),
"chip_addr": {"type": 'integer', "required": False, "empty": False, "default": 0x48},
"type": {"type": 'string', "required": True, "empty": False, "allowed": SENSOR_TYPES},
"pins": {"type": 'list', "required": True, "empty": False, "allowed": [0, 1, 2, 3]},
"gain": {
"required": False,
"empty": False,
"allowed": [0.6666666666666666, 1, 2, 4, 8, 16],
"default": 1
},
}


Expand All @@ -37,20 +32,20 @@ class Sensor(GenericSensor):
"""

SENSOR_SCHEMA: CerberusSchemaType = {
"type": dict(
type="string",
required=False,
empty=False,
allowed=["value", "voltage"],
default="value",
),
"pin": dict(
type="integer",
required=True,
empty=False,
allowed=[0, 1, 2, 3],
default=0,
),
"type": {
"type": 'string',
"required": False,
"empty": False,
"allowed": ['value', 'voltage'],
"default": 'value',
},
"pin": {
"type": 'integer',
"required": True,
"empty": False,
"allowed": [0, 1, 2, 3],
"default": 0,
},
}

def setup_module(self) -> None:
Expand Down Expand Up @@ -90,10 +85,10 @@ def get_value(self, sens_conf: ConfigType) -> SensorValueType:
# acquire the lock
with self.lock:
sens_type = sens_conf["type"]
data = dict(
value=self.channels[sens_conf["pin"]].value,
voltage=self.channels[sens_conf["pin"]].voltage,
)
data = {
"value": self.channels[sens_conf['pin']].value,
"voltage": self.channels[sens_conf['pin']].voltage,
}

return cast(
float,
Expand Down
30 changes: 15 additions & 15 deletions mqtt_io/modules/sensor/adxl345.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

REQUIREMENTS = ("adxl345",)
CONFIG_SCHEMA: CerberusSchemaType = {
"chip_addr": dict(type="integer", required=True, empty=False),
"output_g": dict(type="boolean", required=False, empty=False),
"chip_addr": {"type": 'integer', "required": True, "empty": False},
"output_g": {"type": 'boolean', "required": False, "empty": False},
}


Expand All @@ -32,13 +32,13 @@ class Sensor(GenericSensor):
"""

SENSOR_SCHEMA: CerberusSchemaType = {
"type": dict(
type="string",
required=False,
empty=False,
default="all",
allowed=["all", "x", "y", "z"],
)
"type": {
"type": 'string',
"required": False,
"empty": False,
"default": 'all',
"allowed": ['all', 'x', 'y', 'z'],
}
}

def setup_module(self) -> None:
Expand All @@ -59,10 +59,10 @@ def get_value(self, sens_conf: ConfigType) -> SensorValueType:

return cast(
float,
dict(
x=all_axes["x"],
y=all_axes["y"],
z=all_axes["z"],
all_axes=dumps(all_axes),
)[sens_type],
{
"x": all_axes['x'],
"y": all_axes['y'],
"z": all_axes['z'],
"all_axes": dumps(all_axes),
}[sens_type],
)
14 changes: 7 additions & 7 deletions mqtt_io/modules/sensor/aht20.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Sensor(GenericSensor):
"""

SENSOR_SCHEMA = {
"type": dict(
type="string",
required=False,
empty=False,
default="temperature",
allowed=["temperature", "humidity"],
)
"type": {
"type": 'string',
"required": False,
"empty": False,
"default": 'temperature',
"allowed": ['temperature', 'humidity'],
}
}

def setup_module(self) -> None:
Expand Down
28 changes: 14 additions & 14 deletions mqtt_io/modules/sensor/bme280.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

REQUIREMENTS = ("smbus2", "RPi.bme280")
CONFIG_SCHEMA: CerberusSchemaType = {
"i2c_bus_num": dict(type="integer", required=True, empty=False),
"chip_addr": dict(type="integer", required=True, empty=False),
"i2c_bus_num": {"type": 'integer', "required": True, "empty": False},
"chip_addr": {"type": 'integer', "required": True, "empty": False},
}


Expand All @@ -20,13 +20,13 @@ class Sensor(GenericSensor):
"""

SENSOR_SCHEMA: CerberusSchemaType = {
"type": dict(
type="string",
required=False,
empty=False,
default="temperature",
allowed=["temperature", "humidity", "pressure"],
)
"type": {
"type": 'string',
"required": False,
"empty": False,
"default": 'temperature',
"allowed": ['temperature', 'humidity', 'pressure'],
}
}

def setup_module(self) -> None:
Expand All @@ -48,9 +48,9 @@ def get_value(self, sens_conf: ConfigType) -> SensorValueType:
data = self.bme.sample(self.bus, self.address, self.calib)
return cast(
float,
dict(
temperature=data.temperature,
humidity=data.humidity,
pressure=data.pressure,
)[sens_type],
{
"temperature": data.temperature,
"humidity": data.humidity,
"pressure": data.pressure,
}[sens_type],
)
Loading

0 comments on commit b7cdd21

Please sign in to comment.