Skip to content

Commit

Permalink
change from asyncio_mqtt to aiomqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjiU committed Apr 9, 2024
1 parent 67d455a commit 189cc9e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions mqtt_io/config/config.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ mqtt:
description: MQTT Client implementation module path.
extra_info: |
There's currently only one implementation, which uses the
[asyncio-mqtt](https://github.com/sbtinstruments/asyncio-mqtt/) client.
[aiomqtt](https://github.com/sbtinstruments/aiomqtt/) client.
type: string
required: no
default: mqtt_io.mqtt.asyncio_mqtt
default: mqtt_io.mqtt.aiomqtt
ha_discovery:
type: dict
required: no
Expand Down
11 changes: 4 additions & 7 deletions mqtt_io/mqtt/asyncio_mqtt.py → mqtt_io/mqtt/aiomqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import wraps
from typing import Any, Callable, List, Optional, Tuple, TypeVar, cast

from asyncio_mqtt.client import Client, MqttError, Will # type: ignore
from aiomqtt.client import Client, MqttError, Will # type: ignore
from paho.mqtt import client as paho # type: ignore

from . import (
Expand Down Expand Up @@ -93,7 +93,7 @@ def __init__(self, options: MQTTClientOptions):
port=options.port,
username=options.username,
password=options.password,
client_id=options.client_id,
identifier=options.client_id,
#keepalive=options.keepalive,
tls_context=tls_context,
protocol=protocol_map[options.protocol],
Expand All @@ -113,7 +113,7 @@ async def connect(self, timeout: int = 10) -> None:
Returns:
None: This function does not return anything.
"""
await self._client.connect(timeout=timeout)
await self._client.__aenter__()

@_map_exception
async def disconnect(self) -> None:
Expand All @@ -126,10 +126,7 @@ async def disconnect(self) -> None:
Returns:
None
"""
try:
await self._client.disconnect()
except TimeoutError:
await self._client.force_disconnect()
await self._client.__aexit__(None, None, None)

@_map_exception
async def subscribe(self, topics: List[Tuple[str, int]]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion mqtt_io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from hashlib import sha1
from importlib import import_module
from typing import Any, Dict, List, Optional, Tuple, Type, Union, overload
from asyncio_mqtt.error import MqttCodeError # type: ignore
from aiomqtt.exceptions import MqttCodeError # type: ignore

import backoff # type: ignore
from typing_extensions import Literal
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ license = "MIT"
documentation = "https://flyte.github.io/mqtt-io/"

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.8"
PyYAML = "^6.0.1"
Cerberus = "^1.3.2"
typing-extensions = "^3.7.4"
typing-extensions = "^4.4.0"
dataclasses = { version = "^0.8", python = ">=3.6,<3.7" }
asyncio-mqtt = "^0.8.1"
aiomqtt = "^2.0.1"
backoff = "^1.10.0"
confp = "^0.4.0"

Expand All @@ -25,11 +25,11 @@ pylint = "^2.6.2"
mypy = "^0.812"
behave = "^1.2.6"
coverage = "^5.4"
md-toc = "^7.1.0"
md-toc = "^8.0.0"
Sphinx = "^3.5.1"
sphinx-autoapi = "^1.7.0"
recommonmark = "^0.7.1"
Jinja2 = "^2.11.3"
Jinja2 = "^3.1.3"
ast-to-xml="^0.2.3"
GitPython = "^3.1.15"
semver = "^2.13.0"
Expand Down

0 comments on commit 189cc9e

Please sign in to comment.