Skip to content

Commit de3d93d

Browse files
authored
update from asyncio_mqtt to aiomqtt (#364)
* change from asyncio_mqtt to aiomqtt version 2.1.0 * remove python 3.7 from action as not supported by aiomqtt * add docutils as dev dependency * remove new pylint errors
1 parent c90e5c0 commit de3d93d

25 files changed

+246
-250
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-20.04
99
strategy:
1010
matrix:
11-
python-version: [3.7, 3.8]
11+
python-version: [3.8]
1212

1313
steps:
1414
- uses: actions/checkout@v2

mqtt_io/config/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ def custom_validate_main_config(config: ConfigType) -> ConfigType:
140140
bad_configs: Dict[str, Dict[str, List[str]]] = {}
141141

142142
# Make sure each of the IO configs refer to an existing module config
143-
module_and_io_sections = dict(
144-
gpio_modules=("digital_inputs", "digital_outputs"),
145-
sensor_modules=("sensor_inputs",),
146-
stream_modules=("stream_reads", "stream_writes"),
147-
)
143+
module_and_io_sections = {
144+
"gpio_modules": ("digital_inputs", "digital_outputs"),
145+
"sensor_modules": ("sensor_inputs",),
146+
"stream_modules": ("stream_reads", "stream_writes"),
147+
}
148148
for module_section, io_sections in module_and_io_sections.items():
149149
validate_gpio_module_names(bad_configs, config, module_section, io_sections)
150150

mqtt_io/config/config.schema.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ mqtt:
129129
description: MQTT Client implementation module path.
130130
extra_info: |
131131
There's currently only one implementation, which uses the
132-
[asyncio-mqtt](https://github.com/sbtinstruments/asyncio-mqtt/) client.
132+
[aiomqtt](https://github.com/sbtinstruments/aiomqtt/) client.
133133
type: string
134134
required: no
135-
default: mqtt_io.mqtt.asyncio_mqtt
135+
default: mqtt_io.mqtt.aiomqtt
136136
ha_discovery:
137137
type: dict
138138
required: no

mqtt_io/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
STREAM_TOPIC = "stream"
1414

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

1818
MQTT_SUB_PRIORITY = 1
1919
MQTT_ANNOUNCE_PRIORITY = 2

mqtt_io/home_assistant.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ def get_common_config(
2323
Return config that's common across all HQ discovery announcements.
2424
"""
2525
disco_conf: ConfigType = mqtt_conf["ha_discovery"]
26-
config = dict(name=io_conf["name"])
26+
config = {"name": io_conf['name']}
2727
config.update(
28-
dict(
29-
availability_topic="/".join(
28+
{
29+
"availability_topic": '/'.join(
3030
(mqtt_conf["topic_prefix"], mqtt_conf["status_topic"])
3131
),
32-
payload_available=mqtt_conf["status_payload_running"],
33-
payload_not_available=mqtt_conf["status_payload_dead"],
34-
device=dict(
35-
manufacturer="MQTT IO",
36-
model=f"v{VERSION}",
37-
identifiers=[mqtt_options.client_id],
38-
name=disco_conf["name"],
39-
),
40-
)
32+
"payload_available": mqtt_conf["status_payload_running"],
33+
"payload_not_available": mqtt_conf["status_payload_dead"],
34+
"device": {
35+
"manufacturer": 'MQTT IO',
36+
"model": f'v{VERSION}',
37+
"identifiers": [mqtt_options.client_id],
38+
"name": disco_conf["name"],
39+
},
40+
}
4141
)
4242
config.update(io_conf.get("ha_discovery", {}))
4343
return config
@@ -54,12 +54,12 @@ def hass_announce_digital_input(
5454
disco_prefix: str = disco_conf["prefix"]
5555
sensor_config = get_common_config(in_conf, mqtt_conf, mqtt_options)
5656
sensor_config.update(
57-
dict(
58-
unique_id=f"{mqtt_options.client_id}_{in_conf['module']}_input_{name}",
59-
state_topic="/".join((mqtt_conf["topic_prefix"], INPUT_TOPIC, name)),
60-
payload_on=in_conf["on_payload"],
61-
payload_off=in_conf["off_payload"],
62-
)
57+
{
58+
"unique_id": f'{mqtt_options.client_id}_{in_conf["module"]}_input_{name}',
59+
"state_topic": '/'.join((mqtt_conf["topic_prefix"], INPUT_TOPIC, name)),
60+
"payload_on": in_conf["on_payload"],
61+
"payload_off": in_conf["off_payload"],
62+
}
6363
)
6464
return MQTTMessageSend(
6565
"/".join(
@@ -90,13 +90,13 @@ def hass_announce_digital_output(
9090
disco_prefix: str = disco_conf["prefix"]
9191
switch_config = get_common_config(out_conf, mqtt_conf, mqtt_options)
9292
switch_config.update(
93-
dict(
94-
unique_id=f"{mqtt_options.client_id}_{out_conf['module']}_output_{name}",
95-
state_topic="/".join((prefix, OUTPUT_TOPIC, name)),
96-
command_topic="/".join((prefix, OUTPUT_TOPIC, name, SET_SUFFIX)),
97-
payload_on=out_conf["on_payload"],
98-
payload_off=out_conf["off_payload"],
99-
)
93+
{
94+
"unique_id": f'{mqtt_options.client_id}_{out_conf["module"]}_output_{name}',
95+
"state_topic": '/'.join((prefix, OUTPUT_TOPIC, name)),
96+
"command_topic": '/'.join((prefix, OUTPUT_TOPIC, name, SET_SUFFIX)),
97+
"payload_on": out_conf["on_payload"],
98+
"payload_off": out_conf["off_payload"],
99+
}
100100
)
101101
return MQTTMessageSend(
102102
"/".join(
@@ -127,10 +127,10 @@ def hass_announce_sensor_input(
127127
disco_prefix: str = disco_conf["prefix"]
128128
sensor_config = get_common_config(sens_conf, mqtt_conf, mqtt_options)
129129
sensor_config.update(
130-
dict(
131-
unique_id=f"{mqtt_options.client_id}_{sens_conf['module']}_sensor_{name}",
132-
state_topic="/".join((prefix, SENSOR_TOPIC, name)),
133-
)
130+
{
131+
"unique_id": f'{mqtt_options.client_id}_{sens_conf["module"]}_sensor_{name}',
132+
"state_topic": '/'.join((prefix, SENSOR_TOPIC, name)),
133+
}
134134
)
135135
if "expire_after" not in sensor_config:
136136
sensor_config["expire_after"] = sens_conf["interval"] * 2 + 5

mqtt_io/modules/gpio/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import asyncio
1212
import logging
1313
from concurrent.futures import ThreadPoolExecutor
14-
from enum import Enum, Flag, auto
14+
from enum import Enum, Flag, IntFlag, auto
1515
from typing import Any, Callable, Dict, Iterable, List, Optional
1616

1717
from ...types import ConfigType, PinType
@@ -48,7 +48,7 @@ class InterruptEdge(Enum):
4848
BOTH = auto()
4949

5050

51-
class InterruptSupport(Flag):
51+
class InterruptSupport(IntFlag):
5252
"""
5353
Classifies the kind of support a GPIO module has for interrupts.
5454

mqtt_io/modules/gpio/mcp23017.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GPIO(GenericGPIO):
3232
| InterruptSupport.SET_TRIGGERS
3333
)
3434
PIN_SCHEMA = {
35-
"pin": dict(type="integer", required=True, min=0, max=15),
35+
"pin": {"type": 'integer', "required": True, "min": 0, "max": 15},
3636
}
3737

3838
def setup_module(self) -> None:

mqtt_io/modules/gpio/mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from . import GenericGPIO, InterruptEdge, InterruptSupport, PinDirection, PinPUD
1010

1111
REQUIREMENTS = ()
12-
CONFIG_SCHEMA = dict(test=dict(type="boolean", required=False, default=False))
12+
CONFIG_SCHEMA = {"test": {"type": 'boolean', "required": False, "default": False}}
1313

1414

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

3030
def __init__(self, config: ConfigType):

mqtt_io/modules/sensor/ads1x15.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@
1414

1515
REQUIREMENTS = ("adafruit-circuitpython-ads1x15",)
1616
CONFIG_SCHEMA: CerberusSchemaType = {
17-
"chip_addr": dict(type="integer", required=False, empty=False, default=0x48),
18-
"type": dict(
19-
type="string",
20-
required=True,
21-
empty=False,
22-
allowed=SENSOR_TYPES,
23-
),
24-
"pins": dict(type="list", required=True, empty=False, allowed=[0, 1, 2, 3]),
25-
"gain": dict(
26-
required=False,
27-
empty=False,
28-
allowed=[0.6666666666666666, 1, 2, 4, 8, 16],
29-
default=1,
30-
),
17+
"chip_addr": {"type": 'integer', "required": False, "empty": False, "default": 0x48},
18+
"type": {"type": 'string', "required": True, "empty": False, "allowed": SENSOR_TYPES},
19+
"pins": {"type": 'list', "required": True, "empty": False, "allowed": [0, 1, 2, 3]},
20+
"gain": {
21+
"required": False,
22+
"empty": False,
23+
"allowed": [0.6666666666666666, 1, 2, 4, 8, 16],
24+
"default": 1
25+
},
3126
}
3227

3328

@@ -37,20 +32,20 @@ class Sensor(GenericSensor):
3732
"""
3833

3934
SENSOR_SCHEMA: CerberusSchemaType = {
40-
"type": dict(
41-
type="string",
42-
required=False,
43-
empty=False,
44-
allowed=["value", "voltage"],
45-
default="value",
46-
),
47-
"pin": dict(
48-
type="integer",
49-
required=True,
50-
empty=False,
51-
allowed=[0, 1, 2, 3],
52-
default=0,
53-
),
35+
"type": {
36+
"type": 'string',
37+
"required": False,
38+
"empty": False,
39+
"allowed": ['value', 'voltage'],
40+
"default": 'value',
41+
},
42+
"pin": {
43+
"type": 'integer',
44+
"required": True,
45+
"empty": False,
46+
"allowed": [0, 1, 2, 3],
47+
"default": 0,
48+
},
5449
}
5550

5651
def setup_module(self) -> None:
@@ -90,10 +85,10 @@ def get_value(self, sens_conf: ConfigType) -> SensorValueType:
9085
# acquire the lock
9186
with self.lock:
9287
sens_type = sens_conf["type"]
93-
data = dict(
94-
value=self.channels[sens_conf["pin"]].value,
95-
voltage=self.channels[sens_conf["pin"]].voltage,
96-
)
88+
data = {
89+
"value": self.channels[sens_conf['pin']].value,
90+
"voltage": self.channels[sens_conf['pin']].voltage,
91+
}
9792

9893
return cast(
9994
float,

mqtt_io/modules/sensor/adxl345.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
REQUIREMENTS = ("adxl345",)
2323
CONFIG_SCHEMA: CerberusSchemaType = {
24-
"chip_addr": dict(type="integer", required=True, empty=False),
25-
"output_g": dict(type="boolean", required=False, empty=False),
24+
"chip_addr": {"type": 'integer', "required": True, "empty": False},
25+
"output_g": {"type": 'boolean', "required": False, "empty": False},
2626
}
2727

2828

@@ -32,13 +32,13 @@ class Sensor(GenericSensor):
3232
"""
3333

3434
SENSOR_SCHEMA: CerberusSchemaType = {
35-
"type": dict(
36-
type="string",
37-
required=False,
38-
empty=False,
39-
default="all",
40-
allowed=["all", "x", "y", "z"],
41-
)
35+
"type": {
36+
"type": 'string',
37+
"required": False,
38+
"empty": False,
39+
"default": 'all',
40+
"allowed": ['all', 'x', 'y', 'z'],
41+
}
4242
}
4343

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

6060
return cast(
6161
float,
62-
dict(
63-
x=all_axes["x"],
64-
y=all_axes["y"],
65-
z=all_axes["z"],
66-
all_axes=dumps(all_axes),
67-
)[sens_type],
62+
{
63+
"x": all_axes['x'],
64+
"y": all_axes['y'],
65+
"z": all_axes['z'],
66+
"all_axes": dumps(all_axes),
67+
}[sens_type],
6868
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy