{"id":34102887,"url":"https://github.com/cmgrayb/libdyson-mqtt","last_synced_at":"2026-04-06T02:01:37.523Z","repository":{"id":310743116,"uuid":"1039328314","full_name":"cmgrayb/libdyson-mqtt","owner":"cmgrayb","description":"MQTT based connections to Dyson devices","archived":false,"fork":false,"pushed_at":"2025-08-25T00:42:12.000Z","size":84,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-16T00:38:01.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmgrayb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-17T01:16:16.000Z","updated_at":"2025-10-02T22:39:29.000Z","dependencies_parsed_at":"2025-08-20T01:19:07.596Z","dependency_job_id":"e86081ba-1034-4bad-93b7-2ac771bcdfa7","html_url":"https://github.com/cmgrayb/libdyson-mqtt","commit_stats":null,"previous_names":["cmgrayb/libdyson-mqtt"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/cmgrayb/libdyson-mqtt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmgrayb%2Flibdyson-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmgrayb%2Flibdyson-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmgrayb%2Flibdyson-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmgrayb%2Flibdyson-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmgrayb","download_url":"https://codeload.github.com/cmgrayb/libdyson-mqtt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmgrayb%2Flibdyson-mqtt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31456664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-14T17:04:14.260Z","updated_at":"2026-04-06T02:01:37.518Z","avatar_url":"https://github.com/cmgrayb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libdyson-mqtt\n\nA Python library for MQTT communication with Dyson devices.\n\n## Overview\n\n`libdyson-mqtt` provides a clean, non-blocking interface for communicating with Dyson devices over MQTT. The library handles connection management, message queuing, and provides callbacks for real-time message processing.\n\n## Features\n\n- **Non-blocking operations**: All operations are asynchronous and won't block your application\n- **Clean connection management**: Automatic connection handling with proper cleanup\n- **Message queuing**: Messages are queued internally for processing\n- **Callback support**: Real-time callbacks for messages and connection status\n- **Type safety**: Full type annotations and mypy support\n- **Comprehensive testing**: Unit and integration tests included\n\n## Installation\n\n```bash\npip install libdyson-mqtt\n```\n\nFor development:\n\n```bash\npip install -e .[dev]\n```\n\n## Quick Start\n\n```python\nfrom libdyson_mqtt import DysonMqttClient, ConnectionConfig\n\n# Configure connection\nconfig = ConnectionConfig(\n    host=\"192.168.1.100\",  # Your Dyson device IP\n    mqtt_username=\"your_username\",\n    mqtt_password=\"your_password\", \n    mqtt_topics=[\"475/device/status\", \"475/device/command\"],\n    port=1883,\n    keepalive=60\n)\n\n# Create and connect client\nclient = DysonMqttClient(config)\nclient.connect()\n\n# Check if connected\nif client.is_connected():\n    print(\"Connected successfully!\")\n    \n    # Publish a command\n    client.publish(\"475/device/command\", '{\"command\": \"status\"}')\n    \n    # Get received messages\n    messages = client.get_messages()\n    for msg in messages:\n        print(f\"Topic: {msg.topic}, Payload: {msg.payload_str}\")\n\n# Clean disconnect\nclient.disconnect()\n```\n\n## Using Context Manager\n\nFor automatic connection management:\n\n```python\nfrom libdyson_mqtt import DysonMqttClient, ConnectionConfig\n\nconfig = ConnectionConfig(\n    host=\"192.168.1.100\",\n    mqtt_username=\"your_username\",\n    mqtt_password=\"your_password\",\n    mqtt_topics=[\"475/device/status\", \"475/device/command\"]\n)\n\n# Automatically connects and disconnects\nwith DysonMqttClient(config) as client:\n    client.publish(\"475/device/command\", '{\"command\": \"status\"}')\n    messages = client.get_messages()\n```\n\n## Using Callbacks\n\nFor real-time message processing:\n\n```python\ndef on_message(message):\n    print(f\"Received: {message.topic} -\u003e {message.payload_str}\")\n\ndef on_connection_change(connected, error):\n    if connected:\n        print(\"Connected to device!\")\n    else:\n        print(f\"Connection lost: {error}\")\n\nclient = DysonMqttClient(config)\nclient.set_message_callback(on_message)\nclient.set_connection_callback(on_connection_change)\n\nclient.connect()\n# Messages will now be processed in real-time via callbacks\n```\n\n## API Reference\n\n### ConnectionConfig\n\nConfiguration class for MQTT connection:\n\n- `host`: IPv4 address or IPv6 .local DNS address\n- `mqtt_username`: MQTT username  \n- `mqtt_password`: MQTT password\n- `mqtt_topics`: List of topics to subscribe to\n- `port`: MQTT port (default: 1883)\n- `keepalive`: Keep-alive interval in seconds (default: 60)\n- `client_id`: Optional custom client ID\n\n### DysonMqttClient\n\nMain client class for MQTT communication:\n\n#### Methods\n\n- `connect()`: Connect to MQTT broker (non-blocking)\n- `disconnect()`: Disconnect from broker\n- `publish(topic, payload, qos=2, retain=False)`: Publish message\n- `get_messages(clear_queue=True)`: Get queued messages\n- `set_message_callback(callback)`: Set message received callback\n- `set_connection_callback(callback)`: Set connection status callback\n- `is_connected()`: Check connection status\n- `get_status()`: Get detailed connection status\n\n### MqttMessage\n\nRepresents a received MQTT message:\n\n- `topic`: Message topic\n- `payload`: Raw payload bytes\n- `payload_str`: Payload as UTF-8 string\n- `qos`: Quality of Service level\n- `retain`: Whether message is retained\n- `timestamp`: When message was received\n- `to_dict()`: Convert to dictionary\n\n## Error Handling\n\nThe library defines several exception types:\n\n- `DysonMqttError`: Base exception\n- `ConnectionError`: Connection issues\n- `AuthenticationError`: Authentication failures  \n- `TopicError`: Topic subscription/publishing issues\n- `ClientNotConnectedError`: Operations on disconnected client\n- `CleanupError`: Cleanup failures\n\n```python\nfrom libdyson_mqtt.exceptions import ConnectionError, ClientNotConnectedError\n\ntry:\n    client.connect()\nexcept ConnectionError as e:\n    print(f\"Failed to connect: {e}\")\n\ntry:\n    client.publish(\"test/topic\", \"message\")\nexcept ClientNotConnectedError:\n    print(\"Not connected to broker\")\n```\n\n## Development\n\nInstall development dependencies:\n\n```bash\npip install -e .[dev]\n```\n\nRun tests:\n\n```bash\npytest\n```\n\nRun type checking:\n\n```bash\nmypy src/\n```\n\nFormat code:\n\n```bash\nblack src/ tests/\nisort src/ tests/\n```\n\n## Requirements\n\n- Python 3.9+\n- paho-mqtt \u003e= 1.6.0\n\n## License\n\nMIT License. See LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please read the contributing guidelines and submit pull requests to the main repository.\n\n## Home Assistant Integration\n\nThis library is designed to work well with Home Assistant integrations. The non-blocking design and callback system make it suitable for use in Home Assistant custom components:\n\n```python\n# In your Home Assistant integration\nimport asyncio\nfrom libdyson_mqtt import DysonMqttClient, ConnectionConfig\n\nclass DysonDevice:\n    def __init__(self, hass, config):\n        self.hass = hass\n        self.client = DysonMqttClient(config)\n        self.client.set_message_callback(self._handle_message)\n        \n    def _handle_message(self, message):\n        # Process device status updates\n        self.hass.loop.call_soon_threadsafe(\n            self._update_state, message\n        )\n        \n    async def _update_state(self, message):\n        # Update Home Assistant entity state\n        pass\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmgrayb%2Flibdyson-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmgrayb%2Flibdyson-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmgrayb%2Flibdyson-mqtt/lists"}