# Plug P100
This is a fork of original work of [@K4CZP3R](https://github.com/K4CZP3R/tapo-p100-python)
The purpose of this fork is to provide the library as PyPi package.
# How to install
```pip install plugp100```
## Library Architecture
The library was rewritten by taking inspiration from [Component Gaming Design Pattern](https://gameprogrammingpatterns.com/component.html) to achieve better decoupling from device and its capabilities.
Each Tapo Device, now, is something like a container of Device Component. A Device Component represent a specific feature, so a Tapo Device can be composed by multiple device component.
e.g. `EnergyComponent`, `OverheatComponent`, `OnOffComponent` and so on.
There 3 main Tapo Device class family, which simplify access to underlying components:
- TapoBulb
- TapoPlug
- TapoHub
## Supported Devices
This library supports a wide range of Tapo devices, including:
- Tapo Smart Plugs
- Tapo Smart Plug Strip
- Tapo Smart Led Strip
- Tapo Smart Bulb
- Tapo HUB H100
- Water Leak
- Trigger Button (like S200)
- Switch
- Smart Door
- Temperature Humidity Sensor
Every device class has more than one component which enrich the basic capability of Tapo Device.
You can see the supported components inside `plugp100/new/components` package.
## Usage
Replace `<tapo_username>`, `<tapo_password>`, and `<tapo_device_ip>` with your Tapo account credentials and device IP address.
### Authentication
Before using the library, make sure to have your Tapo credentials ready:
```python
from plugp100.common.credentials import AuthCredential
credentials = AuthCredential("<tapo_username>", "<tapo_password>")
```
### Example: Discovery
Use the library to discover Tapo devices on the network:
```python
import asyncio
import logging
from plugp100.common.credentials import AuthCredential
from plugp100.discovery.tapo_discovery import TapoDiscovery
async def example_discovery(credentials: AuthCredential):
discovered = await TapoDiscovery.scan(timeout=5)
for discovered_device in discovered:
try:
device = await discovered_device.get_tapo_device(credentials)
await device.update()
print({
'type': type(device),
'protocol': device.protocol_version,
'raw_state': device.raw_state
})
await device.client.close()
except Exception as e:
logging.error(f"Failed to update {discovered_device.ip} {discovered_device.device_type}", exc_info=e)
async def main():
credentials = AuthCredential("<tapo_username>", "<tapo_password>")
await example_discovery(credentials)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
```
### Example: Connecting by only ip address
Connect to a Tapo device without knowing its device type and protocol. The library will try to guess:
```python
import asyncio
from plugp100.common.credentials import AuthCredential
from plugp100.new.device_factory import connect, DeviceConnectConfiguration
async def example_connect_by_guessing(credentials: AuthCredential, host: str):
device_configuration = DeviceConnectConfiguration(
host=host,
credentials=credentials
)
device = await connect(device_configuration)
await device.update()
print({
'type': type(device),
'protocol': device.protocol_version,
'raw_state': device.raw_state,
'components': device.get_device_components
})
async def main():
credentials = AuthCredential("<tapo_username>", "<tapo_password>")
await example_connect_by_guessing(credentials, "<tapo_device_ip>")
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
```
### Example: Connecting by knowing Protocol
Connect to a Tapo device with known device type and protocol details:
```python
import asyncio
from plugp100.common.credentials import AuthCredential
from plugp100.new.device_factory import connect, DeviceConnectConfiguration
async def example_connect_knowing_device_and_protocol(credentials: AuthCredential, host: str):
device_configuration = DeviceConnectConfiguration(
host=host,
credentials=credentials,
device_type="SMART.TAPOPLUG",
encryption_type="klap",
encryption_version=2
)
device = await connect(device_configuration)
await device.update()
print({
'type': type(device),
'protocol': device.protocol_version,
'raw_state': device.raw_state,
'components': device.get_device_components
})
async def main():
credentials = AuthCredential("<tapo_username>", "<tapo_password>")
await example_connect_knowing_device_and_protocol(credentials, "<tapo_device_ip>")
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(asyncio.sleep(0.1))
loop.close()
```
## Supported Protocols
- Klap v1
- Klap v2
- Passthorugh
- Ipcamera-like?! (work in progress hub H200)
Raw data
{
"_id": null,
"home_page": "https://github.com/petretiandrea/plugp100",
"name": "plugp100",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "Tapo, P100",
"author": "@petretiandrea",
"author_email": "petretiandrea@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/28/03/c659dc96b766aab9cc292e3e96a17eddfa2e21b8ee341a46771824c7259c/plugp100-5.1.3.tar.gz",
"platform": null,
"description": "# Plug P100\nThis is a fork of original work of [@K4CZP3R](https://github.com/K4CZP3R/tapo-p100-python)\n\nThe purpose of this fork is to provide the library as PyPi package. \n\n# How to install\n```pip install plugp100```\n\n## Library Architecture\nThe library was rewritten by taking inspiration from [Component Gaming Design Pattern](https://gameprogrammingpatterns.com/component.html) to achieve better decoupling from device and its capabilities.\nEach Tapo Device, now, is something like a container of Device Component. A Device Component represent a specific feature, so a Tapo Device can be composed by multiple device component.\ne.g. `EnergyComponent`, `OverheatComponent`, `OnOffComponent` and so on.\n\nThere 3 main Tapo Device class family, which simplify access to underlying components:\n- TapoBulb\n- TapoPlug\n- TapoHub\n\n\n## Supported Devices\n\nThis library supports a wide range of Tapo devices, including:\n\n- Tapo Smart Plugs\n- Tapo Smart Plug Strip\n- Tapo Smart Led Strip\n- Tapo Smart Bulb\n- Tapo HUB H100\n - Water Leak\n - Trigger Button (like S200)\n - Switch\n - Smart Door\n - Temperature Humidity Sensor\n\nEvery device class has more than one component which enrich the basic capability of Tapo Device. \nYou can see the supported components inside `plugp100/new/components` package.\n\n\n## Usage\n\nReplace `<tapo_username>`, `<tapo_password>`, and `<tapo_device_ip>` with your Tapo account credentials and device IP address.\n\n### Authentication\n\nBefore using the library, make sure to have your Tapo credentials ready:\n\n```python\nfrom plugp100.common.credentials import AuthCredential\n\ncredentials = AuthCredential(\"<tapo_username>\", \"<tapo_password>\")\n```\n\n### Example: Discovery\n\nUse the library to discover Tapo devices on the network:\n\n```python\nimport asyncio\nimport logging\nfrom plugp100.common.credentials import AuthCredential\nfrom plugp100.discovery.tapo_discovery import TapoDiscovery\n\nasync def example_discovery(credentials: AuthCredential):\n discovered = await TapoDiscovery.scan(timeout=5)\n for discovered_device in discovered:\n try:\n device = await discovered_device.get_tapo_device(credentials)\n await device.update()\n print({\n 'type': type(device),\n 'protocol': device.protocol_version,\n 'raw_state': device.raw_state\n })\n await device.client.close()\n except Exception as e:\n logging.error(f\"Failed to update {discovered_device.ip} {discovered_device.device_type}\", exc_info=e)\n\nasync def main():\n credentials = AuthCredential(\"<tapo_username>\", \"<tapo_password>\")\n await example_discovery(credentials)\n\nif __name__ == \"__main__\":\n loop = asyncio.new_event_loop()\n loop.run_until_complete(main())\n loop.run_until_complete(asyncio.sleep(0.1))\n loop.close()\n```\n\n### Example: Connecting by only ip address\n\nConnect to a Tapo device without knowing its device type and protocol. The library will try to guess:\n\n```python\nimport asyncio\nfrom plugp100.common.credentials import AuthCredential\nfrom plugp100.new.device_factory import connect, DeviceConnectConfiguration\n\nasync def example_connect_by_guessing(credentials: AuthCredential, host: str):\n device_configuration = DeviceConnectConfiguration(\n host=host,\n credentials=credentials\n )\n device = await connect(device_configuration)\n await device.update()\n print({\n 'type': type(device),\n 'protocol': device.protocol_version,\n 'raw_state': device.raw_state,\n 'components': device.get_device_components\n })\n\nasync def main():\n credentials = AuthCredential(\"<tapo_username>\", \"<tapo_password>\")\n await example_connect_by_guessing(credentials, \"<tapo_device_ip>\")\n\nif __name__ == \"__main__\":\n loop = asyncio.new_event_loop()\n loop.run_until_complete(main())\n loop.run_until_complete(asyncio.sleep(0.1))\n loop.close()\n```\n\n### Example: Connecting by knowing Protocol\n\nConnect to a Tapo device with known device type and protocol details:\n\n```python\nimport asyncio\nfrom plugp100.common.credentials import AuthCredential\nfrom plugp100.new.device_factory import connect, DeviceConnectConfiguration\n\nasync def example_connect_knowing_device_and_protocol(credentials: AuthCredential, host: str):\n device_configuration = DeviceConnectConfiguration(\n host=host,\n credentials=credentials,\n device_type=\"SMART.TAPOPLUG\",\n encryption_type=\"klap\",\n encryption_version=2\n )\n device = await connect(device_configuration)\n await device.update()\n print({\n 'type': type(device),\n 'protocol': device.protocol_version,\n 'raw_state': device.raw_state,\n 'components': device.get_device_components\n })\n\nasync def main():\n credentials = AuthCredential(\"<tapo_username>\", \"<tapo_password>\")\n await example_connect_knowing_device_and_protocol(credentials, \"<tapo_device_ip>\")\n\nif __name__ == \"__main__\":\n loop = asyncio.new_event_loop()\n loop.run_until_complete(main())\n loop.run_until_complete(asyncio.sleep(0.1))\n loop.close()\n```\n\n\n\n## Supported Protocols\n\n- Klap v1\n- Klap v2\n- Passthorugh\n- Ipcamera-like?! (work in progress hub H200)\n",
"bugtrack_url": null,
"license": "GPL3",
"summary": "Controller for TP-Link Tapo P100 and other devices",
"version": "5.1.3",
"project_urls": {
"Download": "https://github.com/petretiandrea/plugp100",
"Homepage": "https://github.com/petretiandrea/plugp100"
},
"split_keywords": [
"tapo",
" p100"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b8d9470b26f24f67f32c488596d557371f935166994391601af160a8b0cfdbb6",
"md5": "6656f2f3c79b3bdd26524712e13eaf0d",
"sha256": "ea368e4aa6e5b90d07b3932051d513ff3c1476ad04bfd7ee488b3b879ed21ac6"
},
"downloads": -1,
"filename": "plugp100-5.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6656f2f3c79b3bdd26524712e13eaf0d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 102979,
"upload_time": "2024-04-13T09:58:23",
"upload_time_iso_8601": "2024-04-13T09:58:23.794791Z",
"url": "https://files.pythonhosted.org/packages/b8/d9/470b26f24f67f32c488596d557371f935166994391601af160a8b0cfdbb6/plugp100-5.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2803c659dc96b766aab9cc292e3e96a17eddfa2e21b8ee341a46771824c7259c",
"md5": "0e2f6ff5d2ea8cf85b0750256401421b",
"sha256": "5011473cebb35d1fa6755f9a6532f55d9b00503371a46be2de480f38a83a6114"
},
"downloads": -1,
"filename": "plugp100-5.1.3.tar.gz",
"has_sig": false,
"md5_digest": "0e2f6ff5d2ea8cf85b0750256401421b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 66616,
"upload_time": "2024-04-13T09:58:25",
"upload_time_iso_8601": "2024-04-13T09:58:25.814667Z",
"url": "https://files.pythonhosted.org/packages/28/03/c659dc96b766aab9cc292e3e96a17eddfa2e21b8ee341a46771824c7259c/plugp100-5.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-13 09:58:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "petretiandrea",
"github_project": "plugp100",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "plugp100"
}