Skip to content

Commit

Permalink
Make everest-testing compatible with paho-mqtt 1.x and 2.x (#176)
Browse files Browse the repository at this point in the history
* Make everest-testing compatible with paho-mqtt 1.x and 2.x

---------

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass authored Jan 31, 2025
1 parent 165f2c8 commit febaa93
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion everest-testing/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install_requires =
pytest
pytest-asyncio
python-dateutil
paho-mqtt ==1.6.1
paho-mqtt >=2.0
pyftpdlib
ocpp ==0.26.0
websockets
Expand Down
2 changes: 1 addition & 1 deletion everest-testing/src/everest/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.4.4"
__version__="0.4.5"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
from paho.mqtt.client import Client
import paho.mqtt.client as mqtt
from paho.mqtt import __version__ as paho_mqtt_version

from everest.testing.core_utils.everest_core import EverestCore

Expand Down Expand Up @@ -31,7 +32,11 @@ def stop(self, *exc_details):
def _initialize_external_mqtt_client(self):
mqtt_server_uri = os.environ.get("MQTT_SERVER_ADDRESS", "127.0.0.1")
mqtt_server_port = int(os.environ.get("MQTT_SERVER_PORT", "1883"))
self._mqtt_client = Client(self._everest_core.everest_uuid)
if paho_mqtt_version < '2.0':
self._mqtt_client = mqtt.Client(self._everest_core.everest_uuid)
else:
self._mqtt_client = mqtt.Client(
callback_api_version=mqtt.CallbackAPIVersion.VERSION1, client_id=self._everest_core.everest_uuid)
self._mqtt_client.connect(mqtt_server_uri, mqtt_server_port)

def _initialize_nodered_sil(self):
Expand Down
7 changes: 6 additions & 1 deletion everest-testing/src/everest/testing/core_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
import os
import paho.mqtt.client as mqtt
from paho.mqtt import __version__ as paho_mqtt_version

from ._configuration.everest_configuration_strategies.everest_configuration_strategy import \
EverestConfigAdjustmentStrategy
Expand Down Expand Up @@ -133,7 +134,11 @@ def test_controller(request, tmp_path, everest_core) -> EverestTestController:
def connected_mqtt_client(everest_core: EverestCore) -> mqtt.Client:
mqtt_server_uri = os.environ.get("MQTT_SERVER_ADDRESS", "127.0.0.1")
mqtt_server_port = int(os.environ.get("MQTT_SERVER_PORT", "1883"))
client = mqtt.Client(everest_core.everest_uuid)
if paho_mqtt_version < '2.0':
client = mqtt.Client(everest_core.everest_uuid)
else:
client = mqtt.Client(
callback_api_version=mqtt.CallbackAPIVersion.VERSION1, client_id=everest_core.everest_uuid)
client.connect(mqtt_server_uri, mqtt_server_port)
client.loop_start()

Expand Down

0 comments on commit febaa93

Please sign in to comment.