{"id":14985290,"url":"https://github.com/stackia/libdeye","last_synced_at":"2025-04-10T23:50:44.365Z","repository":{"id":86678366,"uuid":"606608181","full_name":"stackia/libdeye","owner":"stackia","description":"A python library and CLI to control Deye (德业) devices.","archived":false,"fork":false,"pushed_at":"2025-03-07T06:51:50.000Z","size":134,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T20:38:14.804Z","etag":null,"topics":["deye","home-assistant","home-automation"],"latest_commit_sha":null,"homepage":"https://libdeye.readthedocs.io/","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/stackia.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-26T01:51:16.000Z","updated_at":"2025-03-07T06:51:54.000Z","dependencies_parsed_at":"2023-07-26T02:50:50.232Z","dependency_job_id":"662316e8-cfb6-4f9e-b719-a0cfcaa525d5","html_url":"https://github.com/stackia/libdeye","commit_stats":{"total_commits":44,"total_committers":3,"mean_commits":"14.666666666666666","dds":"0.43181818181818177","last_synced_commit":"4780c11ed03ce29327f682be485edf5c35875c11"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackia%2Flibdeye","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackia%2Flibdeye/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackia%2Flibdeye/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackia%2Flibdeye/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackia","download_url":"https://codeload.github.com/stackia/libdeye/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317707,"owners_count":21083528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["deye","home-assistant","home-automation"],"created_at":"2024-09-24T14:10:39.652Z","updated_at":"2025-04-10T23:50:44.359Z","avatar_url":"https://github.com/stackia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: https://img.shields.io/badge/-PyScaffold-005CA0?logo=pyscaffold\n    :alt: Project generated with PyScaffold\n    :target: https://pyscaffold.org/\n.. image:: https://results.pre-commit.ci/badge/github/stackia/libdeye/main.svg\n    :target: https://results.pre-commit.ci/latest/github/stackia/libdeye/main\n    :alt: pre-commit.ci status\n.. image:: https://codecov.io/gh/stackia/libdeye/graph/badge.svg?token=DUKdoWnYcw\n    :target: https://codecov.io/gh/stackia/libdeye\n    :alt: Codecov\n.. image:: https://img.shields.io/pypi/v/libdeye.svg\n    :target: https://pypi.org/project/libdeye/\n    :alt: PyPI-Server\n.. image:: https://pepy.tech/badge/libdeye/month\n    :alt: Monthly Downloads\n    :target: https://pepy.tech/project/libdeye\n.. image:: https://readthedocs.org/projects/libdeye/badge/?version=latest\n    :alt: ReadTheDocs\n    :target: https://libdeye.readthedocs.io/en/stable/\n\n=======\nlibdeye\n=======\n\n\n    A Python library to connect to `Deye 德业 \u003chttps://deye.com/\u003e`_ Cloud and control Deye dehumidifier devices.\n\n\nSupported devices:\n\n* DYD-B12A3\n* DYD-D50A3\n* DYD-D50B3\n* DYD-E12A3\n* DYD-G25A3\n* DYD-N20A3\n* DYD-L48A3\n* DYD-T22A3\n* DYD-U20A3\n* DYD-U20Air\n* DYD-V58A3\n* DYD-W20A3\n* DYD-W20A3-京鱼座\n* DYD-X20A3\n* DYD-Z12A3\n* DYD-Z20B3\n* DYD-Z20B3-天猫精灵\n* DYD-S12A3\n* DYD-F20C3\n* JD121EC\n* JD201FC\n* TM208FC\n* DY-612S\n* DY-620S\n* DY-8220C\n* DY-890C\n* DY-890T\n* DY-6138A\n* DY-8138C\n* DY-8158C\n* DY-8158T\n\n\nFor devices not in the above list, consider `adding your own definitions here \u003chttps://github.com/stackia/libdeye/blob/master/src/libdeye/const.py\u003e`_.\n\n-----------------\nCommand Line Tool\n-----------------\n\nThis library also includes a command-line tool for testing and interacting with Deye devices.\n\nInstallation\n------------\n\nThe CLI tool is automatically installed when you install the library:\n\n.. code-block:: bash\n\n    pip install libdeye\n\nUsage\n-----\n\n.. code-block:: bash\n\n    # List all devices\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD devices\n\n    # List all available product types\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD products\n\n    # Get device state\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD get --device-id YOUR_DEVICE_ID\n\n    # Set device state\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD set --device-id YOUR_DEVICE_ID --power on --target-humidity 50\n\n    # Set device mode and fan speed\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD set --device-id YOUR_DEVICE_ID --mode Auto --fan-speed High\n\n    # Set additional device features\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD set --device-id YOUR_DEVICE_ID --anion on --oscillating on --child-lock off\n\n    # Monitor device state changes in real-time\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD monitor --device-id YOUR_DEVICE_ID\n\n    # Get MQTT information for Classic platform\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD classic-mqtt\n\n    # Get MQTT information for Fog platform\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD fog-mqtt\n\n    # Enable debug logging\n    deye-cli --debug --username YOUR_USERNAME --password YOUR_PASSWORD devices\n\n    # Print authentication token (useful for saving to .env file)\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD print-token\n\n    # Force refresh the authentication token\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD refresh-token\n\nUsing .env File\n---------------\n\nYou can store your credentials in a .env file to avoid typing them in each command:\n\n.. code-block:: bash\n\n    # Create a .env file in your working directory\n    echo \"DEYE_USERNAME=your_username\" \u003e .env\n    echo \"DEYE_PASSWORD=your_password\" \u003e\u003e .env\n\n    # Now you can run commands without specifying credentials\n    deye-cli devices\n\n    # You can also specify a different .env file location\n    deye-cli --env-file /path/to/your/.env devices\n\nThe .env file format is simple:\n\n.. code-block:: text\n\n    DEYE_USERNAME=your_phone_number_or_username\n    DEYE_PASSWORD=your_password\n    # Optional: store auth token to avoid login each time\n    DEYE_AUTH_TOKEN=your_auth_token\n    # Optional: store device and product IDs for quick access\n    DEYE_DEVICE_ID=your_device_id\n\nWith device and product IDs in your .env file, you can simplify commands:\n\n.. code-block:: bash\n\n    # Get device state without specifying device-id\n    deye-cli get\n\n    # Set device state without specifying device-id\n    deye-cli set --power on --target-humidity 50\n\n    # Monitor device state changes\n    deye-cli monitor\n\nGetting and Using Authentication Tokens\n---------------------------------------\n\nTo avoid sending your username and password with each request, you can use an authentication token:\n\n.. code-block:: bash\n\n    # Get your authentication token\n    deye-cli --username YOUR_USERNAME --password YOUR_PASSWORD print-token\n\n    # Copy the token and add it to your .env file\n    echo \"DEYE_AUTH_TOKEN=your_token_here\" \u003e\u003e .env\n\n    # Now you can use the token instead of username/password\n    deye-cli devices\n\n    # If your token expires, you can refresh it\n    deye-cli --token YOUR_TOKEN refresh-token\n\nAvailable Commands\n------------------\n\n- ``devices``: List all devices connected to your account\n- ``products``: List all available product types\n- ``get``: Get the current state of a device\n- ``set``: Set the state of a device (power, mode, fan speed, etc.)\n- ``monitor``: Monitor device state changes in real-time\n- ``print-token``: Print the authentication token for use in .env file\n- ``refresh-token``: Force refresh the authentication token\n- ``classic-mqtt``: Get MQTT information for Classic platform\n- ``fog-mqtt``: Get MQTT information for Fog platform\n\nFor more options, run:\n\n.. code-block:: bash\n\n    deye-cli --help\n\n-------------\nExample Usage\n-------------\n\n.. code-block:: python\n\n    import asyncio\n    from typing import List, Optional, Union\n\n    import aiohttp\n    from libdeye.cloud_api import DeyeApiResponseDeviceInfo, DeyeCloudApi, DeyeIotPlatform\n    from libdeye.device_state import DeyeDeviceState\n    from libdeye.mqtt_client import DeyeClassicMqttClient, DeyeFogMqttClient\n\n\n    async def main() -\u003e None:\n        async with aiohttp.ClientSession() as client:\n            # You can authenticate with username/password\n            cloud_api = DeyeCloudApi(client, \"\u003cphone_number\u003e\", \"\u003cpassword\u003e\")\n            await cloud_api.authenticate()\n\n            # Get the list of devices\n            devices: List[DeyeApiResponseDeviceInfo] = await cloud_api.get_device_list()\n            if not devices:\n                print(\"No devices found\")\n                return\n\n            # Get the first device\n            device = devices[0]\n            product_id: str = device[\"product_id\"]\n            device_id: str = device[\"device_id\"]\n            platform: DeyeIotPlatform = DeyeIotPlatform(device[\"platform\"])\n\n            print(f\"Device: {device['device_name']} (ID: {device_id})\")\n            print(\n                f\"Platform: {'Classic' if platform == DeyeIotPlatform.Classic else 'Fog'}\"\n            )\n\n            mqtt_client: Optional[Union[DeyeClassicMqttClient, DeyeFogMqttClient]] = None\n\n            # Handle device based on platform\n            if platform == DeyeIotPlatform.Classic:\n                # Create MQTT client for Classic platform\n                mqtt_client = DeyeClassicMqttClient(cloud_api)\n                await mqtt_client.connect()\n            elif platform == DeyeIotPlatform.Fog:\n                # Create MQTT client for Fog platform\n                mqtt_client = DeyeFogMqttClient(cloud_api)\n                await mqtt_client.connect()\n\n            assert mqtt_client is not None\n\n            # Query current state\n            state: DeyeDeviceState = await mqtt_client.query_device_state(\n                product_id, device_id\n            )\n            print(\n                f\"Current humidity: {state.environment_humidity}% (Target: {state.target_humidity}%)\"\n            )\n\n            # Subscribe to state changes\n            def on_state_update(state: DeyeDeviceState) -\u003e None:\n                print(\n                    f\"Device state updated. Current humidity: {state.environment_humidity}% (Target: {state.target_humidity}%)\"\n                )\n\n            # Subscribe to availability changes\n            def on_availability_change(available: bool) -\u003e None:\n                print(\n                    f\"Device availability changed: {'Online' if available else 'Offline'}\"\n                )\n\n            # Set up subscriptions\n            unsubscribe_state = mqtt_client.subscribe_state_change(\n                product_id, device_id, on_state_update\n            )\n            unsubscribe_availability = mqtt_client.subscribe_availability_change(\n                product_id, device_id, on_availability_change\n            )\n\n            # Set target humidity\n            state.target_humidity = 40\n            await mqtt_client.publish_command(product_id, device_id, state.to_command())\n\n            await asyncio.sleep(30)\n\n            # Unsubscribe from state changes\n            unsubscribe_state()\n            unsubscribe_availability()\n            mqtt_client.disconnect()\n\n\n    # Run the example\n    if __name__ == \"__main__\":\n        asyncio.run(main())\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackia%2Flibdeye","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackia%2Flibdeye","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackia%2Flibdeye/lists"}