mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Move protocol modules into protocols package (#1254)
This commit is contained in:
@@ -36,13 +36,9 @@ from kasa.exceptions import (
|
||||
)
|
||||
from kasa.feature import Feature
|
||||
from kasa.interfaces.light import HSV, ColorTempRange, Light, LightState
|
||||
from kasa.iotprotocol import (
|
||||
IotProtocol,
|
||||
_deprecated_TPLinkSmartHomeProtocol, # noqa: F401
|
||||
)
|
||||
from kasa.module import Module
|
||||
from kasa.protocol import BaseProtocol
|
||||
from kasa.smartprotocol import SmartProtocol
|
||||
from kasa.protocols import BaseProtocol, IotProtocol, SmartProtocol
|
||||
from kasa.protocols.iotprotocol import _deprecated_TPLinkSmartHomeProtocol # noqa: F401
|
||||
from kasa.transports import BaseTransport
|
||||
|
||||
__version__ = version("python-kasa")
|
||||
|
@@ -1,5 +1,8 @@
|
||||
"""Credentials class for username / passwords."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
@@ -11,3 +14,17 @@ class Credentials:
|
||||
username: str = field(default="", repr=False)
|
||||
#: Password of the cloud account
|
||||
password: str = field(default="", repr=False)
|
||||
|
||||
|
||||
def get_default_credentials(tuple: tuple[str, str]) -> Credentials:
|
||||
"""Return decoded default credentials."""
|
||||
un = base64.b64decode(tuple[0].encode()).decode()
|
||||
pw = base64.b64decode(tuple[1].encode()).decode()
|
||||
return Credentials(un, pw)
|
||||
|
||||
|
||||
DEFAULT_CREDENTIALS = {
|
||||
"KASA": ("a2FzYUB0cC1saW5rLm5ldA==", "a2FzYVNldHVw"),
|
||||
"TAPO": ("dGVzdEB0cC1saW5rLm5ldA==", "dGVzdA=="),
|
||||
"TAPOCAMERA": ("YWRtaW4=", "YWRtaW4="),
|
||||
}
|
||||
|
@@ -125,9 +125,8 @@ from .deviceconfig import (
|
||||
)
|
||||
from .exceptions import KasaException
|
||||
from .feature import Feature
|
||||
from .iotprotocol import IotProtocol
|
||||
from .module import Module
|
||||
from .protocol import BaseProtocol
|
||||
from .protocols import BaseProtocol, IotProtocol
|
||||
from .transports import XorTransport
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
@@ -22,12 +22,12 @@ from .iot import (
|
||||
IotStrip,
|
||||
IotWallSwitch,
|
||||
)
|
||||
from .iotprotocol import IotProtocol
|
||||
from .protocol import (
|
||||
from .protocols import (
|
||||
BaseProtocol,
|
||||
IotProtocol,
|
||||
SmartProtocol,
|
||||
)
|
||||
from .smart import SmartDevice
|
||||
from .smartprotocol import SmartProtocol
|
||||
from .transports import (
|
||||
AesTransport,
|
||||
BaseTransport,
|
||||
|
@@ -131,11 +131,11 @@ from kasa.exceptions import (
|
||||
)
|
||||
from kasa.experimental import Experimental
|
||||
from kasa.iot.iotdevice import IotDevice
|
||||
from kasa.iotprotocol import REDACTORS as IOT_REDACTORS
|
||||
from kasa.json import DataClassJSONMixin
|
||||
from kasa.json import dumps as json_dumps
|
||||
from kasa.json import loads as json_loads
|
||||
from kasa.protocol import mask_mac, redact_data
|
||||
from kasa.protocols.iotprotocol import REDACTORS as IOT_REDACTORS
|
||||
from kasa.protocols.protocol import mask_mac, redact_data
|
||||
from kasa.transports.aestransport import AesEncyptionSession, KeyPair
|
||||
from kasa.transports.xortransport import XorEncryption
|
||||
|
||||
|
@@ -14,7 +14,7 @@ from ..exceptions import (
|
||||
_RetryableError,
|
||||
)
|
||||
from ..json import dumps as json_dumps
|
||||
from ..smartprotocol import SmartProtocol
|
||||
from ..protocols import SmartProtocol
|
||||
from .sslaestransport import (
|
||||
SMART_AUTHENTICATION_ERRORS,
|
||||
SMART_RETRYABLE_ERRORS,
|
||||
|
@@ -13,7 +13,7 @@ from typing import TYPE_CHECKING, Any, Dict, cast
|
||||
|
||||
from yarl import URL
|
||||
|
||||
from ..credentials import Credentials
|
||||
from ..credentials import DEFAULT_CREDENTIALS, Credentials, get_default_credentials
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..exceptions import (
|
||||
SMART_AUTHENTICATION_ERRORS,
|
||||
@@ -27,7 +27,6 @@ from ..exceptions import (
|
||||
from ..httpclient import HttpClient
|
||||
from ..json import dumps as json_dumps
|
||||
from ..json import loads as json_loads
|
||||
from ..protocol import DEFAULT_CREDENTIALS, get_default_credentials
|
||||
from ..transports import AesEncyptionSession, BaseTransport
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@@ -13,7 +13,7 @@ from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..interfaces.light import HSV, ColorTempRange
|
||||
from ..module import Module
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotdevice import IotDevice, KasaException, requires_update
|
||||
from .modules import (
|
||||
Antitheft,
|
||||
|
@@ -28,7 +28,7 @@ from ..exceptions import KasaException
|
||||
from ..feature import Feature
|
||||
from ..module import Module
|
||||
from ..modulemapping import ModuleMapping, ModuleName
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotmodule import IotModule, merge
|
||||
from .modules import Emeter
|
||||
|
||||
|
@@ -8,7 +8,7 @@ from typing import Any
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..module import Module
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotdevice import KasaException, requires_update
|
||||
from .iotplug import IotPlug
|
||||
from .modules import AmbientLight, Light, Motion
|
||||
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..module import Module
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotbulb import IotBulb
|
||||
from .iotdevice import requires_update
|
||||
from .modules.lighteffect import LightEffect
|
||||
|
@@ -8,7 +8,7 @@ from typing import Any
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..module import Module
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotdevice import IotDevice, requires_update
|
||||
from .modules import AmbientLight, Antitheft, Cloud, Led, Motion, Schedule, Time, Usage
|
||||
|
||||
|
@@ -14,7 +14,7 @@ from ..exceptions import KasaException
|
||||
from ..feature import Feature
|
||||
from ..interfaces import Energy
|
||||
from ..module import Module
|
||||
from ..protocol import BaseProtocol
|
||||
from ..protocols import BaseProtocol
|
||||
from .iotdevice import (
|
||||
IotDevice,
|
||||
requires_update,
|
||||
|
12
kasa/protocols/__init__.py
Normal file
12
kasa/protocols/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
"""Package containing all supported protocols."""
|
||||
|
||||
from .iotprotocol import IotProtocol
|
||||
from .protocol import BaseProtocol
|
||||
from .smartprotocol import SmartErrorCode, SmartProtocol
|
||||
|
||||
__all__ = [
|
||||
"BaseProtocol",
|
||||
"IotProtocol",
|
||||
"SmartErrorCode",
|
||||
"SmartProtocol",
|
||||
]
|
@@ -7,20 +7,20 @@ import logging
|
||||
from pprint import pformat as pf
|
||||
from typing import TYPE_CHECKING, Any, Callable
|
||||
|
||||
from .deviceconfig import DeviceConfig
|
||||
from .exceptions import (
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..exceptions import (
|
||||
AuthenticationError,
|
||||
KasaException,
|
||||
TimeoutError,
|
||||
_ConnectionError,
|
||||
_RetryableError,
|
||||
)
|
||||
from .json import dumps as json_dumps
|
||||
from ..json import dumps as json_dumps
|
||||
from ..transports import XorEncryption, XorTransport
|
||||
from .protocol import BaseProtocol, mask_mac, redact_data
|
||||
from .transports import XorEncryption, XorTransport
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .transports import BaseTransport
|
||||
from ..transports import BaseTransport
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@@ -12,7 +12,6 @@ http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import errno
|
||||
import hashlib
|
||||
import logging
|
||||
@@ -22,8 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
|
||||
|
||||
# When support for cpython older than 3.11 is dropped
|
||||
# async_timeout can be replaced with asyncio.timeout
|
||||
from .credentials import Credentials
|
||||
from .deviceconfig import DeviceConfig
|
||||
from ..deviceconfig import DeviceConfig
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_NO_RETRY_ERRORS = {errno.EHOSTDOWN, errno.EHOSTUNREACH, errno.ECONNREFUSED}
|
||||
@@ -33,7 +31,7 @@ _T = TypeVar("_T")
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .transports import BaseTransport
|
||||
from ..transports import BaseTransport
|
||||
|
||||
|
||||
def redact_data(data: _T, redactors: dict[str, Callable[[Any], Any] | None]) -> _T:
|
||||
@@ -106,17 +104,3 @@ class BaseProtocol(ABC):
|
||||
@abstractmethod
|
||||
async def close(self) -> None:
|
||||
"""Close the protocol. Abstract method to be overriden."""
|
||||
|
||||
|
||||
def get_default_credentials(tuple: tuple[str, str]) -> Credentials:
|
||||
"""Return decoded default credentials."""
|
||||
un = base64.b64decode(tuple[0].encode()).decode()
|
||||
pw = base64.b64decode(tuple[1].encode()).decode()
|
||||
return Credentials(un, pw)
|
||||
|
||||
|
||||
DEFAULT_CREDENTIALS = {
|
||||
"KASA": ("a2FzYUB0cC1saW5rLm5ldA==", "a2FzYVNldHVw"),
|
||||
"TAPO": ("dGVzdEB0cC1saW5rLm5ldA==", "dGVzdA=="),
|
||||
"TAPOCAMERA": ("YWRtaW4=", "YWRtaW4="),
|
||||
}
|
@@ -14,7 +14,7 @@ import uuid
|
||||
from pprint import pformat as pf
|
||||
from typing import TYPE_CHECKING, Any, Callable
|
||||
|
||||
from .exceptions import (
|
||||
from ..exceptions import (
|
||||
SMART_AUTHENTICATION_ERRORS,
|
||||
SMART_RETRYABLE_ERRORS,
|
||||
AuthenticationError,
|
||||
@@ -25,11 +25,11 @@ from .exceptions import (
|
||||
_ConnectionError,
|
||||
_RetryableError,
|
||||
)
|
||||
from .json import dumps as json_dumps
|
||||
from ..json import dumps as json_dumps
|
||||
from .protocol import BaseProtocol, mask_mac, md5, redact_data
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .transports import BaseTransport
|
||||
from ..transports import BaseTransport
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
@@ -8,7 +8,7 @@ from typing import Any
|
||||
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper
|
||||
from ..protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper
|
||||
from .smartdevice import SmartDevice
|
||||
from .smartmodule import SmartModule
|
||||
|
||||
|
@@ -16,7 +16,7 @@ from ..exceptions import AuthenticationError, DeviceError, KasaException, SmartE
|
||||
from ..feature import Feature
|
||||
from ..module import Module
|
||||
from ..modulemapping import ModuleMapping, ModuleName
|
||||
from ..smartprotocol import SmartProtocol
|
||||
from ..protocols import SmartProtocol
|
||||
from ..transports import AesTransport
|
||||
from .modules import (
|
||||
ChildDevice,
|
||||
|
@@ -20,7 +20,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from yarl import URL
|
||||
|
||||
from kasa.credentials import Credentials
|
||||
from kasa.credentials import DEFAULT_CREDENTIALS, Credentials, get_default_credentials
|
||||
from kasa.deviceconfig import DeviceConfig
|
||||
from kasa.exceptions import (
|
||||
SMART_AUTHENTICATION_ERRORS,
|
||||
@@ -36,7 +36,6 @@ from kasa.exceptions import (
|
||||
from kasa.httpclient import HttpClient
|
||||
from kasa.json import dumps as json_dumps
|
||||
from kasa.json import loads as json_loads
|
||||
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
|
||||
|
||||
from .basetransport import BaseTransport
|
||||
|
||||
|
@@ -57,16 +57,12 @@ from cryptography.hazmat.primitives import padding
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||
from yarl import URL
|
||||
|
||||
from kasa.credentials import Credentials
|
||||
from kasa.credentials import DEFAULT_CREDENTIALS, Credentials, get_default_credentials
|
||||
from kasa.deviceconfig import DeviceConfig
|
||||
from kasa.exceptions import AuthenticationError, KasaException, _RetryableError
|
||||
from kasa.httpclient import HttpClient
|
||||
from kasa.json import loads as json_loads
|
||||
from kasa.protocol import (
|
||||
DEFAULT_CREDENTIALS,
|
||||
get_default_credentials,
|
||||
md5,
|
||||
)
|
||||
from kasa.protocols.protocol import md5
|
||||
|
||||
from .basetransport import BaseTransport
|
||||
|
||||
|
Reference in New Issue
Block a user