Skip to main content

Plug P100

This is a fork of original work of @K4CZP3R

The purpose of this fork is to provide the library as PyPi package.

How to install

pip install plugp100

Development

uv sync
uv run pytest tests/unit
uv run black --check .

Library Architecture

The library was rewritten by taking inspiration from Component Gaming Design Pattern 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 the plugp100/components package.

Usage

Replace <tapo_username>, <tapo_password>, and <tapo_device_ip> with your Tapo account credentials and device IP address.

To run the bundled example, copy .env.example to .env, fill in the device credentials, and install the optional dependency with pip install "plugp100[example]" (or uv sync --extra example when developing).

Authentication

Before using the library, make sure to have your Tapo credentials ready:

from plugp100.common.credentials import AuthCredential

credentials = AuthCredential("<tapo_username>", "<tapo_password>")

Example: Discovery

Use the library to discover Tapo devices on the network:

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:

import asyncio
from plugp100.common.credentials import AuthCredential
from plugp100.devices.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:

import asyncio
from plugp100.common.credentials import AuthCredential
from plugp100.devices.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)

Metadata

Release files for plugp100 6.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plugp100 6.0.1
File Size Uploaded
plugp100-6.0.1.tar.gz 75.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plugp100 6.0.1
File Interpreter ABI Platform
plugp100-6.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 187.2 kB

Release files / plugp100-6.0.1.tar.gz

Download URL plugp100-6.0.1.tar.gz
Size 75.9 kB
Tags Source
SHA-256 checksum
How to use checksums
91d3816b4ec12d70285ae40dab5dd972236e050e5ed94c1978d7a906d29c80e2
BLAKE2b-256 checksum
How to use checksums
84fa6ecadde6c0671219d36064c22c083ba0ab4f61a3e5cdc51181baef34cf05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / plugp100-6.0.1-py3-none-any.whl

Download URL plugp100-6.0.1-py3-none-any.whl
Size 111.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bf3ba60c1e295cf81df9ab009b041d16cda4396814b719ef132422d983406b0
BLAKE2b-256 checksum
How to use checksums
5cc71ec69f52a833f76b54de23f16d5ac91e26c6390a8456e070c960d78c1370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

6.0.1 This release

2 release files

6.0.0

2 release files

5.2.0

2 release files

5.1.7

2 release files

5.1.6

2 release files

5.1.5

2 release files

5.1.4

2 release files

5.1.3

2 release files

5.1.2

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.14.1

2 release files

3.14.0

2 release files

3.12.0

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.4

8 release files

2.2.3

8 release files

2.2.2

8 release files

2.2.1

8 release files

2.2.0

8 release files

2.1.21

8 release files

2.1.20

8 release files

2.1.19

8 release files

2.1.18

8 release files

2.1.14

4 release files

2.1.12

1 release file

2.1.11

1 release file

2.1.10

1 release file

2.1.9

2 release files

2.1.7

2 release files

2.1.6

8 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.1

2 release files

2.1

2 release files

2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page