{"library":"plugp100","title":"Tapo P100 Smart Plug Controller","description":"PlugP100 is an asynchronous Python library designed to control TP-Link Tapo P100, P105, P110, L900, L920, and similar smart devices locally. It provides a simple API for common operations like turning devices on/off, checking status, and accessing energy monitoring data where available. The current stable version is 5.1.7, with active development on version 6.x indicating a potential upcoming major release with significant changes.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install plugp100"],"cli":null},"imports":["from plugp100.api.plug_device import PlugP100","from plugp100.common.exceptions import TapoError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import asyncio\nimport os\nfrom plugp100.api.plug_device import PlugP100\nfrom plugp100.common.exceptions import TapoError\n\nasync def main():\n    # It's recommended to use environment variables for sensitive data\n    ip_address = os.environ.get(\"TAPO_IP\", \"192.168.1.100\") # Replace with your device IP\n    username = os.environ.get(\"TAPO_USERNAME\", \"your_tapo_email@example.com\") # Your Tapo account email\n    password = os.environ.get(\"TAPO_PASSWORD\", \"YourTapoPassword\") # Your Tapo account password\n\n    if not all([ip_address, username, password]):\n        print(\"Please set TAPO_IP, TAPO_USERNAME, and TAPO_PASSWORD environment variables.\")\n        return\n\n    # Initialize the device client\n    plug = PlugP100(ip_address, username, password)\n\n    try:\n        # Authenticate with the device\n        await plug.login()\n        print(f\"Successfully logged in to Tapo device at {ip_address}\")\n\n        # Get device information\n        device_info = await plug.get_device_info()\n        print(f\"Device Model: {device_info.model}\")\n        print(f\"Device Name: {device_info.device_name}\")\n        print(f\"Device is currently {'On' if device_info.device_on else 'Off'}\")\n\n        # Toggle the plug's power state\n        if device_info.device_on:\n            print(\"Turning off the device...\")\n            await plug.turn_off()\n        else:\n            print(\"Turning on the device...\")\n            await plug.turn_on()\n\n        # Get updated device info to confirm state change\n        device_info_updated = await plug.get_device_info()\n        print(f\"Device is now {'On' if device_info_updated.device_on else 'Off'}\")\n\n        # Example for P110/P105 with energy monitoring (uncomment if applicable)\n        # if hasattr(plug, 'get_current_energy_usage'):\n        #     energy_usage = await plug.get_current_energy_usage()\n        #     print(f\"Current Power: {energy_usage.current_power} mW\")\n\n    except TapoError as e:\n        print(f\"Tapo device error: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n    finally:\n        # Ensure the session is properly closed\n        if plug.is_logged_in: # Check if plug is still logged in before attempting logout\n            await plug.logout()\n            print(\"Logged out from Tapo device.\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to connect to a Tapo P100-series smart plug, retrieve its status, and toggle its power state. It uses environment variables for secure credential management and handles common exceptions. The library is asynchronous, so the code must be run within an `asyncio` event loop.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}