A Python library for connecting to Zafron using MQTT protocol. This library provides a simple interface for sending data to Zafron's MQTT broker and handling device communications.
- Simple, Pythonic API for Zafron MQTT communication
- Automatic connection management
- Type-safe implementation with Python 3.6+ support
- Built-in error handling
- Support for both virtual and sensor data types
- Asynchronous operation for non-blocking I/O
pip install zafron-mqttfrom zafron_mqtt import ZafronConfig, ZafronMQTT
# Create configuration
config = ZafronConfig(
username="your_username",
password="your_password",
client_id="your_client_id"
)
# Initialize Zafron client
zafron = ZafronMQTT(config)
# Connect to Zafron
if zafron.connect():
# Send temperature data
zafron.send_sensor_data(1, 22.5, "°C")
# Send humidity data
zafron.send_sensor_data(2, 65.2, "%")
# Send custom data
zafron.send_data(3, {"status": "online"})
# Disconnect when done
zafron.disconnect()- Python 3.6+
paho-mqttlibrary (automatically installed)
@dataclass
class ZafronConfig:
username: str # Zafron MQTT username
password: str # Zafron MQTT password
client_id: str # Unique client identifier
broker: str = "mqtt.zafron.dev" # MQTT broker address
port: int = 1883 # MQTT portclass ZafronMQTT:
def __init__(self, config: ZafronConfig) -> None:
"""Initialize Zafron MQTT client"""
def connect(self) -> bool:
"""Connect to Zafron MQTT broker"""
def disconnect(self) -> None:
"""Disconnect from Zafron MQTT broker"""
def send_data(self, channel: int, value: Any, data_type: str = "virtual") -> bool:
"""Send data to Zafron"""
def send_sensor_data(self, channel: int, value: float, unit: str) -> bool:
"""Send sensor data with unit information"""Contributions are welcome! Please submit a pull request with:
- Clear description of changes
- Updated documentation if applicable
- Tests for new functionality
For issues or feature requests, please use the issue tracker.
This library follows semantic versioning. Major version changes may include breaking API changes.
# Install test dependencies
pip install -r requirements-dev.txt
# Run tests
pytest