Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip h200 #166

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugp100/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from plugp100.api import *
from plugp100.common import *

__version__ = "4.0.0"
__version__ = "4.0.1"
17 changes: 15 additions & 2 deletions plugp100/common/utils/http_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ssl
from typing import Any

import aiohttp
from aiohttp.connector import SSLContext


class AsyncHttp:
Expand All @@ -12,18 +14,29 @@ def __init__(self, session: aiohttp.ClientSession):
"requestByApp": "true",
"Accept": "application/json",
}
ctx = ssl.create_default_context()
ctx.set_ciphers("DEFAULT")

ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
self.ctx = ctx

async def async_make_post(self, url, json: Any) -> aiohttp.ClientResponse:
self.session.cookie_jar.clear()

async with self.session.post(
url, json=json, headers=self.common_headers
url, json=json, headers=self.common_headers, ssl_context=self.ctx
) as response:
return await self._force_read_release(response)

async def async_make_post_cookie(self, url, json, cookie) -> aiohttp.ClientResponse:
self.session.cookie_jar.clear()
async with self.session.post(
url, json=json, cookies=cookie, headers=self.common_headers
url,
json=json,
cookies=cookie,
headers=self.common_headers,
ssl_context=self.ctx,
) as response:
return await self._force_read_release(response)

Expand Down
40 changes: 26 additions & 14 deletions plugp100/example.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import asyncio
import os

from plugp100.api.light_effect_preset import LightEffectPreset
import aiohttp

from plugp100.api.tapo_client import TapoClient
from plugp100.common.credentials import AuthCredential
from plugp100.discovery.tapo_discovery import TapoDeviceFinder
from plugp100.protocol.camera_like_protocol import CameraLikeProtocol
from plugp100.requests.tapo_request import TapoRequest


async def main():
print("Scanning network...")
print(TapoDeviceFinder.classify(TapoDeviceFinder.scan(5)))
# print("Scanning network...")
# print(TapoDeviceFinder.classify(TapoDeviceFinder.scan(5)))

# create generic tapo api
username = os.getenv("USERNAME", "<tapo_email>")
password = os.getenv("PASSWORD", "<tapo_password>")

credentials = AuthCredential(username, password)
client = TapoClient.create(credentials, "<tapo_device_ip>")

print(await client.get_device_info())
print(await client.get_energy_usage())
print(await client.get_current_power())
print(await client.get_child_device_list())
print(await client.get_child_device_component_list())
print(await client.set_lighting_effect(LightEffectPreset.Aurora.to_effect()))
credentials = AuthCredential("admin", "")
# client = TapoClient.create(credentials, "192.168.1.10")
# print(await client.execute_raw_request(TapoRequest(method="get_sysinfo", params=None)))

protocol = CameraLikeProtocol(
credentials, "4.tcp.eu.ngrok.io", 18938, aiohttp.ClientSession()
)

print(await protocol.send_request(TapoRequest.get_device_info()))

#
# components = await client.get_component_negotiation()
# print(components)

# print(await client.get_device_info())
# print(await client.get_energy_usage())
# print(await client.get_current_power())
# print(await client.get_child_device_list())
# print(await client.get_child_device_component_list())
# print(await client.set_lighting_effect(LightEffectPreset.Aurora.to_effect()))
# plug = PlugDevice(TapoClient(username, password), "<tapo_device_ip>")
# light = LightDevice(TapoClient(username, password), "<tapo_device_ip>")
# ledstrip = LedStripDevice(TapoClient(username, password), "<tapo_device_ip>")
Expand Down
Loading