From 1a241e47442a67fa1794a3aaea0bb670eff3cee6 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sat, 7 Jun 2025 12:42:59 +0200 Subject: [PATCH] refactor: clean up imports in MQTT modules and tests --- src/esp_sensors/mqtt.py | 23 ++--------------------- src/esp_sensors/mqtt_client.py | 3 +-- tests/test_mqtt.py | 5 +++-- tests/test_mqtt_client.py | 12 +++--------- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/esp_sensors/mqtt.py b/src/esp_sensors/mqtt.py index 8777b7f..5efa50e 100644 --- a/src/esp_sensors/mqtt.py +++ b/src/esp_sensors/mqtt.py @@ -7,30 +7,11 @@ It supports both real hardware and simulation mode. This module uses the MQTTClient class from mqtt_client.py for the core MQTT implementation. """ -import time import json +import time + from .mqtt_client import ( MQTTClient, - MQTTException, - CONNECT, - CONNACK, - PUBLISH, - PUBACK, - SUBSCRIBE, - SUBACK, - UNSUBSCRIBE, - UNSUBACK, - PINGREQ, - PINGRESP, - DISCONNECT, - CONN_ACCEPTED, - CONN_REFUSED_PROTOCOL, - CONN_REFUSED_IDENTIFIER, - CONN_REFUSED_SERVER, - CONN_REFUSED_USER_PASS, - CONN_REFUSED_AUTH, - MQTT_PROTOCOL_LEVEL, - MQTT_CLEAN_SESSION, ) diff --git a/src/esp_sensors/mqtt_client.py b/src/esp_sensors/mqtt_client.py index 17f9d2e..d0b7c33 100644 --- a/src/esp_sensors/mqtt_client.py +++ b/src/esp_sensors/mqtt_client.py @@ -7,10 +7,9 @@ and provides a simple interface for connecting to an MQTT broker, publishing messages, and subscribing to topics. """ -import time -import json import socket import struct +import time # MQTT Protocol Constants MQTT_PROTOCOL_LEVEL = 4 # MQTT 3.1.1 diff --git a/tests/test_mqtt.py b/tests/test_mqtt.py index 4b9debe..320554b 100644 --- a/tests/test_mqtt.py +++ b/tests/test_mqtt.py @@ -2,10 +2,11 @@ Tests for the MQTT module. """ -import pytest import json from unittest.mock import patch, MagicMock -from src.esp_sensors.mqtt_client import MQTTClient + +import pytest + from src.esp_sensors.mqtt import setup_mqtt, publish_sensor_data diff --git a/tests/test_mqtt_client.py b/tests/test_mqtt_client.py index 22626f6..db5d63d 100644 --- a/tests/test_mqtt_client.py +++ b/tests/test_mqtt_client.py @@ -4,25 +4,19 @@ Tests for the MQTT Client module. This module contains tests for the MQTTClient class in the mqtt_client.py module. """ +import struct import time +from unittest.mock import patch, MagicMock import pytest -import socket -import struct -from unittest.mock import patch, MagicMock, call + from src.esp_sensors.mqtt_client import ( MQTTClient, MQTTException, - CONNECT, CONNACK, PUBLISH, PUBACK, - SUBSCRIBE, SUBACK, - PINGREQ, - PINGRESP, - DISCONNECT, - CONN_ACCEPTED, )