Move protocol modules into protocols package (#1254)

This commit is contained in:
Steven B. 2024-11-13 17:50:21 +00:00 committed by GitHub
parent 1eaae37c55
commit e55731c110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 94 additions and 94 deletions

View File

@ -44,8 +44,8 @@ from kasa.experimental.smartcameraprotocol import (
SmartCameraProtocol, SmartCameraProtocol,
_ChildCameraProtocolWrapper, _ChildCameraProtocolWrapper,
) )
from kasa.protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper
from kasa.smart import SmartChildDevice from kasa.smart import SmartChildDevice
from kasa.smartprotocol import SmartProtocol, _ChildProtocolWrapper
Call = namedtuple("Call", "module method") Call = namedtuple("Call", "module method")
FixtureResult = namedtuple("FixtureResult", "filename, folder, data") FixtureResult = namedtuple("FixtureResult", "filename, folder, data")

View File

@ -18,14 +18,13 @@ import asyncclick as click
import pyshark import pyshark
from cryptography.hazmat.primitives import padding from cryptography.hazmat.primitives import padding
from kasa.credentials import Credentials from kasa.credentials import DEFAULT_CREDENTIALS, Credentials, get_default_credentials
from kasa.deviceconfig import ( from kasa.deviceconfig import (
DeviceConfig, DeviceConfig,
DeviceConnectionParameters, DeviceConnectionParameters,
DeviceEncryptionType, DeviceEncryptionType,
DeviceFamily, DeviceFamily,
) )
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
from kasa.transports.klaptransport import KlapEncryptionSession, KlapTransportV2 from kasa.transports.klaptransport import KlapEncryptionSession, KlapTransportV2

View File

@ -86,21 +86,21 @@
## Protocols and transports ## Protocols and transports
```{eval-rst} ```{eval-rst}
.. autoclass:: kasa.protocol.BaseProtocol .. autoclass:: kasa.protocols.BaseProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
``` ```
```{eval-rst} ```{eval-rst}
.. autoclass:: kasa.iotprotocol.IotProtocol .. autoclass:: kasa.protocols.IotProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
``` ```
```{eval-rst} ```{eval-rst}
.. autoclass:: kasa.smartprotocol.SmartProtocol .. autoclass:: kasa.protocols.SmartProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:

View File

@ -116,15 +116,15 @@ In order to support these different configurations the library migrated from a s
to support pluggable transports and protocols. to support pluggable transports and protocols.
The classes providing this functionality are: The classes providing this functionality are:
- {class}`BaseProtocol <kasa.protocol.BaseProtocol>` - {class}`BaseProtocol <kasa.protocols.BaseProtocol>`
- {class}`IotProtocol <kasa.iotprotocol.IotProtocol>` - {class}`IotProtocol <kasa.protocols.IotProtocol>`
- {class}`SmartProtocol <kasa.smartprotocol.SmartProtocol>` - {class}`SmartProtocol <kasa.protocols.SmartProtocol>`
- {class}`BaseTransport <kasa.protocol.BaseTransport>` - {class}`BaseTransport <kasa.transports.BaseTransport>`
- {class}`XorTransport <kasa.xortransport.XorTransport>` - {class}`XorTransport <kasa.transports.XorTransport>`
- {class}`AesTransport <kasa.aestransport.AesTransport>` - {class}`AesTransport <kasa.transports.AesTransport>`
- {class}`KlapTransport <kasa.klaptransport.KlapTransport>` - {class}`KlapTransport <kasa.transports.KlapTransport>`
- {class}`KlapTransportV2 <kasa.klaptransport.KlapTransportV2>` - {class}`KlapTransportV2 <kasa.transports.KlapTransportV2>`
(topics-errors-and-exceptions)= (topics-errors-and-exceptions)=
## Errors and Exceptions ## Errors and Exceptions
@ -166,42 +166,42 @@ API documentation for modules and features
API documentation for protocols and transports API documentation for protocols and transports
********************************************** **********************************************
.. autoclass:: kasa.protocol.BaseProtocol .. autoclass:: kasa.protocols.BaseProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.iotprotocol.IotProtocol .. autoclass:: kasa.protocols.IotProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.smartprotocol.SmartProtocol .. autoclass:: kasa.protocols.SmartProtocol
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.protocol.BaseTransport .. autoclass:: kasa.transports.BaseTransport
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.xortransport.XorTransport .. autoclass:: kasa.transports.XorTransport
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.klaptransport.KlapTransport .. autoclass:: kasa.transports.KlapTransport
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.klaptransport.KlapTransportV2 .. autoclass:: kasa.transports.KlapTransportV2
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:
.. autoclass:: kasa.aestransport.AesTransport .. autoclass:: kasa.transports.AesTransport
:members: :members:
:inherited-members: :inherited-members:
:undoc-members: :undoc-members:

View File

@ -36,13 +36,9 @@ from kasa.exceptions import (
) )
from kasa.feature import Feature from kasa.feature import Feature
from kasa.interfaces.light import HSV, ColorTempRange, Light, LightState 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.module import Module
from kasa.protocol import BaseProtocol from kasa.protocols import BaseProtocol, IotProtocol, SmartProtocol
from kasa.smartprotocol import SmartProtocol from kasa.protocols.iotprotocol import _deprecated_TPLinkSmartHomeProtocol # noqa: F401
from kasa.transports import BaseTransport from kasa.transports import BaseTransport
__version__ = version("python-kasa") __version__ = version("python-kasa")

View File

@ -1,5 +1,8 @@
"""Credentials class for username / passwords.""" """Credentials class for username / passwords."""
from __future__ import annotations
import base64
from dataclasses import dataclass, field from dataclasses import dataclass, field
@ -11,3 +14,17 @@ class Credentials:
username: str = field(default="", repr=False) username: str = field(default="", repr=False)
#: Password of the cloud account #: Password of the cloud account
password: str = field(default="", repr=False) 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="),
}

View File

@ -125,9 +125,8 @@ from .deviceconfig import (
) )
from .exceptions import KasaException from .exceptions import KasaException
from .feature import Feature from .feature import Feature
from .iotprotocol import IotProtocol
from .module import Module from .module import Module
from .protocol import BaseProtocol from .protocols import BaseProtocol, IotProtocol
from .transports import XorTransport from .transports import XorTransport
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -22,12 +22,12 @@ from .iot import (
IotStrip, IotStrip,
IotWallSwitch, IotWallSwitch,
) )
from .iotprotocol import IotProtocol from .protocols import (
from .protocol import (
BaseProtocol, BaseProtocol,
IotProtocol,
SmartProtocol,
) )
from .smart import SmartDevice from .smart import SmartDevice
from .smartprotocol import SmartProtocol
from .transports import ( from .transports import (
AesTransport, AesTransport,
BaseTransport, BaseTransport,

View File

@ -131,11 +131,11 @@ from kasa.exceptions import (
) )
from kasa.experimental import Experimental from kasa.experimental import Experimental
from kasa.iot.iotdevice import IotDevice from kasa.iot.iotdevice import IotDevice
from kasa.iotprotocol import REDACTORS as IOT_REDACTORS
from kasa.json import DataClassJSONMixin from kasa.json import DataClassJSONMixin
from kasa.json import dumps as json_dumps from kasa.json import dumps as json_dumps
from kasa.json import loads as json_loads 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.aestransport import AesEncyptionSession, KeyPair
from kasa.transports.xortransport import XorEncryption from kasa.transports.xortransport import XorEncryption

View File

@ -14,7 +14,7 @@ from ..exceptions import (
_RetryableError, _RetryableError,
) )
from ..json import dumps as json_dumps from ..json import dumps as json_dumps
from ..smartprotocol import SmartProtocol from ..protocols import SmartProtocol
from .sslaestransport import ( from .sslaestransport import (
SMART_AUTHENTICATION_ERRORS, SMART_AUTHENTICATION_ERRORS,
SMART_RETRYABLE_ERRORS, SMART_RETRYABLE_ERRORS,

View File

@ -13,7 +13,7 @@ from typing import TYPE_CHECKING, Any, Dict, cast
from yarl import URL from yarl import URL
from ..credentials import Credentials from ..credentials import DEFAULT_CREDENTIALS, Credentials, get_default_credentials
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..exceptions import ( from ..exceptions import (
SMART_AUTHENTICATION_ERRORS, SMART_AUTHENTICATION_ERRORS,
@ -27,7 +27,6 @@ from ..exceptions import (
from ..httpclient import HttpClient from ..httpclient import HttpClient
from ..json import dumps as json_dumps from ..json import dumps as json_dumps
from ..json import loads as json_loads from ..json import loads as json_loads
from ..protocol import DEFAULT_CREDENTIALS, get_default_credentials
from ..transports import AesEncyptionSession, BaseTransport from ..transports import AesEncyptionSession, BaseTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -13,7 +13,7 @@ from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..interfaces.light import HSV, ColorTempRange from ..interfaces.light import HSV, ColorTempRange
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotdevice import IotDevice, KasaException, requires_update from .iotdevice import IotDevice, KasaException, requires_update
from .modules import ( from .modules import (
Antitheft, Antitheft,

View File

@ -28,7 +28,7 @@ from ..exceptions import KasaException
from ..feature import Feature from ..feature import Feature
from ..module import Module from ..module import Module
from ..modulemapping import ModuleMapping, ModuleName from ..modulemapping import ModuleMapping, ModuleName
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotmodule import IotModule, merge from .iotmodule import IotModule, merge
from .modules import Emeter from .modules import Emeter

View File

@ -8,7 +8,7 @@ from typing import Any
from ..device_type import DeviceType from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotdevice import KasaException, requires_update from .iotdevice import KasaException, requires_update
from .iotplug import IotPlug from .iotplug import IotPlug
from .modules import AmbientLight, Light, Motion from .modules import AmbientLight, Light, Motion

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from ..device_type import DeviceType from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotbulb import IotBulb from .iotbulb import IotBulb
from .iotdevice import requires_update from .iotdevice import requires_update
from .modules.lighteffect import LightEffect from .modules.lighteffect import LightEffect

View File

@ -8,7 +8,7 @@ from typing import Any
from ..device_type import DeviceType from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotdevice import IotDevice, requires_update from .iotdevice import IotDevice, requires_update
from .modules import AmbientLight, Antitheft, Cloud, Led, Motion, Schedule, Time, Usage from .modules import AmbientLight, Antitheft, Cloud, Led, Motion, Schedule, Time, Usage

View File

@ -14,7 +14,7 @@ from ..exceptions import KasaException
from ..feature import Feature from ..feature import Feature
from ..interfaces import Energy from ..interfaces import Energy
from ..module import Module from ..module import Module
from ..protocol import BaseProtocol from ..protocols import BaseProtocol
from .iotdevice import ( from .iotdevice import (
IotDevice, IotDevice,
requires_update, requires_update,

View 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",
]

View File

@ -7,20 +7,20 @@ import logging
from pprint import pformat as pf from pprint import pformat as pf
from typing import TYPE_CHECKING, Any, Callable from typing import TYPE_CHECKING, Any, Callable
from .deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from .exceptions import ( from ..exceptions import (
AuthenticationError, AuthenticationError,
KasaException, KasaException,
TimeoutError, TimeoutError,
_ConnectionError, _ConnectionError,
_RetryableError, _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 .protocol import BaseProtocol, mask_mac, redact_data
from .transports import XorEncryption, XorTransport
if TYPE_CHECKING: if TYPE_CHECKING:
from .transports import BaseTransport from ..transports import BaseTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -12,7 +12,6 @@ http://www.apache.org/licenses/LICENSE-2.0
from __future__ import annotations from __future__ import annotations
import base64
import errno import errno
import hashlib import hashlib
import logging 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 # When support for cpython older than 3.11 is dropped
# async_timeout can be replaced with asyncio.timeout # async_timeout can be replaced with asyncio.timeout
from .credentials import Credentials from ..deviceconfig import DeviceConfig
from .deviceconfig import DeviceConfig
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
_NO_RETRY_ERRORS = {errno.EHOSTDOWN, errno.EHOSTUNREACH, errno.ECONNREFUSED} _NO_RETRY_ERRORS = {errno.EHOSTDOWN, errno.EHOSTUNREACH, errno.ECONNREFUSED}
@ -33,7 +31,7 @@ _T = TypeVar("_T")
if TYPE_CHECKING: if TYPE_CHECKING:
from .transports import BaseTransport from ..transports import BaseTransport
def redact_data(data: _T, redactors: dict[str, Callable[[Any], Any] | None]) -> _T: def redact_data(data: _T, redactors: dict[str, Callable[[Any], Any] | None]) -> _T:
@ -106,17 +104,3 @@ class BaseProtocol(ABC):
@abstractmethod @abstractmethod
async def close(self) -> None: async def close(self) -> None:
"""Close the protocol. Abstract method to be overriden.""" """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="),
}

View File

@ -14,7 +14,7 @@ import uuid
from pprint import pformat as pf from pprint import pformat as pf
from typing import TYPE_CHECKING, Any, Callable from typing import TYPE_CHECKING, Any, Callable
from .exceptions import ( from ..exceptions import (
SMART_AUTHENTICATION_ERRORS, SMART_AUTHENTICATION_ERRORS,
SMART_RETRYABLE_ERRORS, SMART_RETRYABLE_ERRORS,
AuthenticationError, AuthenticationError,
@ -25,11 +25,11 @@ from .exceptions import (
_ConnectionError, _ConnectionError,
_RetryableError, _RetryableError,
) )
from .json import dumps as json_dumps from ..json import dumps as json_dumps
from .protocol import BaseProtocol, mask_mac, md5, redact_data from .protocol import BaseProtocol, mask_mac, md5, redact_data
if TYPE_CHECKING: if TYPE_CHECKING:
from .transports import BaseTransport from ..transports import BaseTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -8,7 +8,7 @@ from typing import Any
from ..device_type import DeviceType from ..device_type import DeviceType
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper from ..protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper
from .smartdevice import SmartDevice from .smartdevice import SmartDevice
from .smartmodule import SmartModule from .smartmodule import SmartModule

View File

@ -16,7 +16,7 @@ from ..exceptions import AuthenticationError, DeviceError, KasaException, SmartE
from ..feature import Feature from ..feature import Feature
from ..module import Module from ..module import Module
from ..modulemapping import ModuleMapping, ModuleName from ..modulemapping import ModuleMapping, ModuleName
from ..smartprotocol import SmartProtocol from ..protocols import SmartProtocol
from ..transports import AesTransport from ..transports import AesTransport
from .modules import ( from .modules import (
ChildDevice, ChildDevice,

View File

@ -20,7 +20,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from yarl import URL 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.deviceconfig import DeviceConfig
from kasa.exceptions import ( from kasa.exceptions import (
SMART_AUTHENTICATION_ERRORS, SMART_AUTHENTICATION_ERRORS,
@ -36,7 +36,6 @@ from kasa.exceptions import (
from kasa.httpclient import HttpClient from kasa.httpclient import HttpClient
from kasa.json import dumps as json_dumps from kasa.json import dumps as json_dumps
from kasa.json import loads as json_loads from kasa.json import loads as json_loads
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
from .basetransport import BaseTransport from .basetransport import BaseTransport

View File

@ -57,16 +57,12 @@ from cryptography.hazmat.primitives import padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from yarl import URL 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.deviceconfig import DeviceConfig
from kasa.exceptions import AuthenticationError, KasaException, _RetryableError from kasa.exceptions import AuthenticationError, KasaException, _RetryableError
from kasa.httpclient import HttpClient from kasa.httpclient import HttpClient
from kasa.json import loads as json_loads from kasa.json import loads as json_loads
from kasa.protocol import ( from kasa.protocols.protocol import md5
DEFAULT_CREDENTIALS,
get_default_credentials,
md5,
)
from .basetransport import BaseTransport from .basetransport import BaseTransport

View File

@ -2,7 +2,7 @@ import copy
import logging import logging
from kasa.deviceconfig import DeviceConfig from kasa.deviceconfig import DeviceConfig
from kasa.iotprotocol import IotProtocol from kasa.protocols import IotProtocol
from kasa.transports.basetransport import BaseTransport from kasa.transports.basetransport import BaseTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -7,9 +7,9 @@ from freezegun.api import FrozenDateTimeFactory
from kasa import Device from kasa import Device
from kasa.device_type import DeviceType from kasa.device_type import DeviceType
from kasa.protocols.smartprotocol import _ChildProtocolWrapper
from kasa.smart.smartchilddevice import SmartChildDevice from kasa.smart.smartchilddevice import SmartChildDevice
from kasa.smart.smartdevice import NON_HUB_PARENT_ONLY_MODULES from kasa.smart.smartdevice import NON_HUB_PARENT_ONLY_MODULES
from kasa.smartprotocol import _ChildProtocolWrapper
from .conftest import ( from .conftest import (
parametrize, parametrize,

View File

@ -9,7 +9,7 @@ import aiohttp
import pytest import pytest
from yarl import URL 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.deviceconfig import DeviceConfig
from kasa.exceptions import ( from kasa.exceptions import (
AuthenticationError, AuthenticationError,
@ -19,9 +19,7 @@ from kasa.exceptions import (
_RetryableError, _RetryableError,
) )
from kasa.httpclient import HttpClient from kasa.httpclient import HttpClient
from kasa.iotprotocol import IotProtocol from kasa.protocols import IotProtocol, SmartProtocol
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
from kasa.smartprotocol import SmartProtocol
from kasa.transports.aestransport import AesTransport from kasa.transports.aestransport import AesTransport
from kasa.transports.klaptransport import ( from kasa.transports.klaptransport import (
KlapEncryptionSession, KlapEncryptionSession,

View File

@ -18,8 +18,8 @@ from kasa.device import Device
from kasa.deviceconfig import DeviceConfig from kasa.deviceconfig import DeviceConfig
from kasa.exceptions import KasaException from kasa.exceptions import KasaException
from kasa.iot import IotDevice from kasa.iot import IotDevice
from kasa.iotprotocol import IotProtocol, _deprecated_TPLinkSmartHomeProtocol from kasa.protocols.iotprotocol import IotProtocol, _deprecated_TPLinkSmartHomeProtocol
from kasa.protocol import ( from kasa.protocols.protocol import (
BaseProtocol, BaseProtocol,
mask_mac, mask_mac,
redact_data, redact_data,

View File

@ -13,10 +13,10 @@ from pytest_mock import MockerFixture
from kasa import Device, KasaException, Module from kasa import Device, KasaException, Module
from kasa.exceptions import DeviceError, SmartErrorCode from kasa.exceptions import DeviceError, SmartErrorCode
from kasa.protocols.smartprotocol import _ChildProtocolWrapper
from kasa.smart import SmartDevice from kasa.smart import SmartDevice
from kasa.smart.modules.energy import Energy from kasa.smart.modules.energy import Energy
from kasa.smart.smartmodule import SmartModule from kasa.smart.smartmodule import SmartModule
from kasa.smartprotocol import _ChildProtocolWrapper
from .conftest import ( from .conftest import (
device_smart, device_smart,
@ -266,7 +266,9 @@ async def test_update_module_query_errors(
mocker.patch.object(new_dev.protocol, "query", side_effect=_query) mocker.patch.object(new_dev.protocol, "query", side_effect=_query)
# children not created yet so cannot patch.object # children not created yet so cannot patch.object
mocker.patch("kasa.smartprotocol._ChildProtocolWrapper.query", new=_child_query) mocker.patch(
"kasa.protocols.smartprotocol._ChildProtocolWrapper.query", new=_child_query
)
await new_dev.update() await new_dev.update()
@ -297,7 +299,7 @@ async def test_update_module_query_errors(
new_dev.protocol, "query", side_effect=new_dev.protocol._query new_dev.protocol, "query", side_effect=new_dev.protocol._query
) )
mocker.patch( mocker.patch(
"kasa.smartprotocol._ChildProtocolWrapper.query", "kasa.protocols.smartprotocol._ChildProtocolWrapper.query",
new=_ChildProtocolWrapper._query, new=_ChildProtocolWrapper._query,
) )

View File

@ -9,8 +9,8 @@ from kasa.exceptions import (
KasaException, KasaException,
SmartErrorCode, SmartErrorCode,
) )
from kasa.protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper
from kasa.smart import SmartDevice from kasa.smart import SmartDevice
from kasa.smartprotocol import SmartProtocol, _ChildProtocolWrapper
from .conftest import device_smart from .conftest import device_smart
from .fakeprotocol_smart import FakeSmartTransport from .fakeprotocol_smart import FakeSmartTransport

View File

@ -11,7 +11,7 @@ import aiohttp
import pytest import pytest
from yarl import URL 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.deviceconfig import DeviceConfig
from kasa.exceptions import ( from kasa.exceptions import (
AuthenticationError, AuthenticationError,
@ -24,7 +24,6 @@ from kasa.experimental.sslaestransport import (
_sha256_hash, _sha256_hash,
) )
from kasa.httpclient import HttpClient from kasa.httpclient import HttpClient
from kasa.protocol import DEFAULT_CREDENTIALS, get_default_credentials
from kasa.transports.aestransport import AesEncyptionSession from kasa.transports.aestransport import AesEncyptionSession
# Transport tests are not designed for real devices # Transport tests are not designed for real devices