mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-17 21:08:03 +00:00
Add klap support for TAPO protocol by splitting out Transports and Protocols (#557)
* Add support for TAPO/SMART KLAP and seperate transports from protocols * Add tests and some review changes * Update following review * Updates following review
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import copy
|
||||
import logging
|
||||
import re
|
||||
from json import loads as json_loads
|
||||
|
||||
from voluptuous import (
|
||||
REMOVE_EXTRA,
|
||||
@@ -13,7 +14,8 @@ from voluptuous import (
|
||||
Schema,
|
||||
)
|
||||
|
||||
from ..protocol import TPLinkSmartHomeProtocol
|
||||
from ..protocol import BaseTransport, TPLinkSmartHomeProtocol
|
||||
from ..smartprotocol import SmartProtocol
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -285,6 +287,41 @@ TIME_MODULE = {
|
||||
}
|
||||
|
||||
|
||||
class FakeSmartProtocol(SmartProtocol):
|
||||
def __init__(self, info):
|
||||
super().__init__("127.0.0.123", transport=FakeSmartTransport(info))
|
||||
|
||||
|
||||
class FakeSmartTransport(BaseTransport):
|
||||
def __init__(self, info):
|
||||
self.info = info
|
||||
|
||||
@property
|
||||
def needs_handshake(self) -> bool:
|
||||
return False
|
||||
|
||||
@property
|
||||
def needs_login(self) -> bool:
|
||||
return False
|
||||
|
||||
async def login(self, request: str) -> None:
|
||||
pass
|
||||
|
||||
async def handshake(self) -> None:
|
||||
pass
|
||||
|
||||
async def send(self, request: str):
|
||||
request_dict = json_loads(request)
|
||||
method = request_dict["method"]
|
||||
if method == "component_nego" or method[:4] == "get_":
|
||||
return self.info[method]
|
||||
elif method[:4] == "set_":
|
||||
_LOGGER.debug("Call %s not implemented, doing nothing", method)
|
||||
|
||||
async def close(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class FakeTransportProtocol(TPLinkSmartHomeProtocol):
|
||||
def __init__(self, info):
|
||||
self.discovery_data = info
|
||||
|
Reference in New Issue
Block a user