mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Rename base TPLinkProtocol to BaseProtocol (#669)
This commit is contained in:
parent
b784d891ff
commit
14acc8550e
@ -29,7 +29,7 @@ from kasa.exceptions import (
|
||||
UnsupportedDeviceException,
|
||||
)
|
||||
from kasa.iotprotocol import IotProtocol
|
||||
from kasa.protocol import TPLinkProtocol, TPLinkSmartHomeProtocol
|
||||
from kasa.protocol import BaseProtocol, TPLinkSmartHomeProtocol
|
||||
from kasa.smartbulb import SmartBulb, SmartBulbPreset, TurnOnBehavior, TurnOnBehaviors
|
||||
from kasa.smartdevice import DeviceType, SmartDevice
|
||||
from kasa.smartdimmer import SmartDimmer
|
||||
@ -44,7 +44,7 @@ __version__ = version("python-kasa")
|
||||
__all__ = [
|
||||
"Discover",
|
||||
"TPLinkSmartHomeProtocol",
|
||||
"TPLinkProtocol",
|
||||
"BaseProtocol",
|
||||
"IotProtocol",
|
||||
"SmartProtocol",
|
||||
"SmartBulb",
|
||||
|
@ -9,8 +9,8 @@ from .exceptions import SmartDeviceException, UnsupportedDeviceException
|
||||
from .iotprotocol import IotProtocol
|
||||
from .klaptransport import KlapTransport, KlapTransportV2
|
||||
from .protocol import (
|
||||
BaseProtocol,
|
||||
BaseTransport,
|
||||
TPLinkProtocol,
|
||||
TPLinkSmartHomeProtocol,
|
||||
_XorTransport,
|
||||
)
|
||||
@ -141,14 +141,14 @@ def get_device_class_from_family(device_type: str) -> Optional[Type[SmartDevice]
|
||||
|
||||
def get_protocol(
|
||||
config: DeviceConfig,
|
||||
) -> Optional[TPLinkProtocol]:
|
||||
) -> Optional[BaseProtocol]:
|
||||
"""Return the protocol from the connection name."""
|
||||
protocol_name = config.connection_type.device_family.value.split(".")[0]
|
||||
protocol_transport_key = (
|
||||
protocol_name + "." + config.connection_type.encryption_type.value
|
||||
)
|
||||
supported_device_protocols: Dict[
|
||||
str, Tuple[Type[TPLinkProtocol], Type[BaseTransport]]
|
||||
str, Tuple[Type[BaseProtocol], Type[BaseTransport]]
|
||||
] = {
|
||||
"IOT.XOR": (TPLinkSmartHomeProtocol, _XorTransport),
|
||||
"IOT.KLAP": (IotProtocol, KlapTransport),
|
||||
|
@ -11,12 +11,12 @@ from .exceptions import (
|
||||
TimeoutException,
|
||||
)
|
||||
from .json import dumps as json_dumps
|
||||
from .protocol import BaseTransport, TPLinkProtocol
|
||||
from .protocol import BaseProtocol, BaseTransport
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IotProtocol(TPLinkProtocol):
|
||||
class IotProtocol(BaseProtocol):
|
||||
"""Class for the legacy TPLink IOT KASA Protocol."""
|
||||
|
||||
BACKOFF_SECONDS_AFTER_TIMEOUT = 1
|
||||
|
@ -79,7 +79,7 @@ class BaseTransport(ABC):
|
||||
"""Close the transport. Abstract method to be overriden."""
|
||||
|
||||
|
||||
class TPLinkProtocol(ABC):
|
||||
class BaseProtocol(ABC):
|
||||
"""Base class for all TP-Link Smart Home communication."""
|
||||
|
||||
def __init__(
|
||||
@ -140,7 +140,7 @@ class _XorTransport(BaseTransport):
|
||||
"""Close the transport. Abstract method to be overriden."""
|
||||
|
||||
|
||||
class TPLinkSmartHomeProtocol(TPLinkProtocol):
|
||||
class TPLinkSmartHomeProtocol(BaseProtocol):
|
||||
"""Implementation of the TP-Link Smart Home protocol."""
|
||||
|
||||
INITIALIZATION_VECTOR = 171
|
||||
|
@ -11,7 +11,7 @@ except ImportError:
|
||||
|
||||
from .deviceconfig import DeviceConfig
|
||||
from .modules import Antitheft, Cloud, Countdown, Emeter, Schedule, Time, Usage
|
||||
from .protocol import TPLinkProtocol
|
||||
from .protocol import BaseProtocol
|
||||
from .smartdevice import DeviceType, SmartDevice, SmartDeviceException, requires_update
|
||||
|
||||
|
||||
@ -222,7 +222,7 @@ class SmartBulb(SmartDevice):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.Bulb
|
||||
|
@ -25,7 +25,7 @@ from .deviceconfig import DeviceConfig
|
||||
from .emeterstatus import EmeterStatus
|
||||
from .exceptions import SmartDeviceException
|
||||
from .modules import Emeter, Module
|
||||
from .protocol import TPLinkProtocol, TPLinkSmartHomeProtocol, _XorTransport
|
||||
from .protocol import BaseProtocol, TPLinkSmartHomeProtocol, _XorTransport
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -196,7 +196,7 @@ class SmartDevice:
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
"""Create a new SmartDevice instance.
|
||||
|
||||
@ -204,7 +204,7 @@ class SmartDevice:
|
||||
"""
|
||||
if config and protocol:
|
||||
protocol._transport._config = config
|
||||
self.protocol: TPLinkProtocol = protocol or TPLinkSmartHomeProtocol(
|
||||
self.protocol: BaseProtocol = protocol or TPLinkSmartHomeProtocol(
|
||||
transport=_XorTransport(config=config or DeviceConfig(host=host)),
|
||||
)
|
||||
_LOGGER.debug("Initializing %s of type %s", self.host, type(self))
|
||||
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
|
||||
|
||||
from kasa.deviceconfig import DeviceConfig
|
||||
from kasa.modules import AmbientLight, Motion
|
||||
from kasa.protocol import TPLinkProtocol
|
||||
from kasa.protocol import BaseProtocol
|
||||
from kasa.smartdevice import DeviceType, SmartDeviceException, requires_update
|
||||
from kasa.smartplug import SmartPlug
|
||||
|
||||
@ -70,7 +70,7 @@ class SmartDimmer(SmartPlug):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.Dimmer
|
||||
|
@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from .deviceconfig import DeviceConfig
|
||||
from .effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
|
||||
from .protocol import TPLinkProtocol
|
||||
from .protocol import BaseProtocol
|
||||
from .smartbulb import SmartBulb
|
||||
from .smartdevice import DeviceType, SmartDeviceException, requires_update
|
||||
|
||||
@ -48,7 +48,7 @@ class SmartLightStrip(SmartBulb):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.LightStrip
|
||||
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
|
||||
|
||||
from kasa.deviceconfig import DeviceConfig
|
||||
from kasa.modules import Antitheft, Cloud, Schedule, Time, Usage
|
||||
from kasa.protocol import TPLinkProtocol
|
||||
from kasa.protocol import BaseProtocol
|
||||
from kasa.smartdevice import DeviceType, SmartDevice, requires_update
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -45,7 +45,7 @@ class SmartPlug(SmartDevice):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.Plug
|
||||
|
@ -24,12 +24,12 @@ from .exceptions import (
|
||||
TimeoutException,
|
||||
)
|
||||
from .json import dumps as json_dumps
|
||||
from .protocol import BaseTransport, TPLinkProtocol, md5
|
||||
from .protocol import BaseProtocol, BaseTransport, md5
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SmartProtocol(TPLinkProtocol):
|
||||
class SmartProtocol(BaseProtocol):
|
||||
"""Class for the new TPLink SMART protocol."""
|
||||
|
||||
BACKOFF_SECONDS_AFTER_TIMEOUT = 1
|
||||
|
@ -16,7 +16,7 @@ from kasa.smartplug import SmartPlug
|
||||
|
||||
from .deviceconfig import DeviceConfig
|
||||
from .modules import Antitheft, Countdown, Emeter, Schedule, Time, Usage
|
||||
from .protocol import TPLinkProtocol
|
||||
from .protocol import BaseProtocol
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -87,7 +87,7 @@ class SmartStrip(SmartDevice):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self.emeter_type = "emeter"
|
||||
|
@ -9,7 +9,7 @@ from ..deviceconfig import DeviceConfig
|
||||
from ..emeterstatus import EmeterStatus
|
||||
from ..exceptions import AuthenticationException, SmartDeviceException
|
||||
from ..modules import Emeter
|
||||
from ..protocol import TPLinkProtocol
|
||||
from ..protocol import BaseProtocol
|
||||
from ..smartdevice import SmartDevice, WifiNetwork
|
||||
from ..smartprotocol import SmartProtocol
|
||||
|
||||
@ -24,7 +24,7 @@ class TapoDevice(SmartDevice):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
_protocol = protocol or SmartProtocol(
|
||||
transport=AesTransport(config=config or DeviceConfig(host=host)),
|
||||
|
@ -4,7 +4,7 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, Optional, cast
|
||||
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..protocol import TPLinkProtocol
|
||||
from ..protocol import BaseProtocol
|
||||
from ..smartdevice import DeviceType
|
||||
from .tapodevice import TapoDevice
|
||||
|
||||
@ -19,7 +19,7 @@ class TapoPlug(TapoDevice):
|
||||
host: str,
|
||||
*,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
protocol: Optional[BaseProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.Plug
|
||||
|
@ -16,8 +16,8 @@ from ..deviceconfig import DeviceConfig
|
||||
from ..exceptions import SmartDeviceException
|
||||
from ..klaptransport import KlapTransport, KlapTransportV2
|
||||
from ..protocol import (
|
||||
BaseProtocol,
|
||||
BaseTransport,
|
||||
TPLinkProtocol,
|
||||
TPLinkSmartHomeProtocol,
|
||||
_XorTransport,
|
||||
)
|
||||
@ -345,7 +345,7 @@ def _get_subclasses(of_class):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"class_name_obj", _get_subclasses(TPLinkProtocol), ids=lambda t: t[0]
|
||||
"class_name_obj", _get_subclasses(BaseProtocol), ids=lambda t: t[0]
|
||||
)
|
||||
def test_protocol_init_signature(class_name_obj):
|
||||
params = list(inspect.signature(class_name_obj[1].__init__).parameters.values())
|
||||
|
Loading…
Reference in New Issue
Block a user