From 14acc8550e2ad342602c4423141f5ccd32fc6b4a Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:28:30 +0000 Subject: [PATCH] Rename base TPLinkProtocol to BaseProtocol (#669) --- kasa/__init__.py | 4 ++-- kasa/device_factory.py | 6 +++--- kasa/iotprotocol.py | 4 ++-- kasa/protocol.py | 4 ++-- kasa/smartbulb.py | 4 ++-- kasa/smartdevice.py | 6 +++--- kasa/smartdimmer.py | 4 ++-- kasa/smartlightstrip.py | 4 ++-- kasa/smartplug.py | 4 ++-- kasa/smartprotocol.py | 4 ++-- kasa/smartstrip.py | 4 ++-- kasa/tapo/tapodevice.py | 4 ++-- kasa/tapo/tapoplug.py | 4 ++-- kasa/tests/test_protocol.py | 4 ++-- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/kasa/__init__.py b/kasa/__init__.py index 3465147a..a8101ae3 100755 --- a/kasa/__init__.py +++ b/kasa/__init__.py @@ -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", diff --git a/kasa/device_factory.py b/kasa/device_factory.py index 757f0c33..83db093f 100755 --- a/kasa/device_factory.py +++ b/kasa/device_factory.py @@ -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), diff --git a/kasa/iotprotocol.py b/kasa/iotprotocol.py index 9f72bbc0..c58cc880 100755 --- a/kasa/iotprotocol.py +++ b/kasa/iotprotocol.py @@ -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 diff --git a/kasa/protocol.py b/kasa/protocol.py index 74023e01..a63250fa 100755 --- a/kasa/protocol.py +++ b/kasa/protocol.py @@ -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 diff --git a/kasa/smartbulb.py b/kasa/smartbulb.py index 8897cece..5b5ae573 100644 --- a/kasa/smartbulb.py +++ b/kasa/smartbulb.py @@ -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 diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 54e7c449..08a6bfb6 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -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)) diff --git a/kasa/smartdimmer.py b/kasa/smartdimmer.py index ca0960f1..97738cc4 100644 --- a/kasa/smartdimmer.py +++ b/kasa/smartdimmer.py @@ -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 diff --git a/kasa/smartlightstrip.py b/kasa/smartlightstrip.py index 27ebf838..103ecfa8 100644 --- a/kasa/smartlightstrip.py +++ b/kasa/smartlightstrip.py @@ -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 diff --git a/kasa/smartplug.py b/kasa/smartplug.py index d9ac0c86..e8251b68 100644 --- a/kasa/smartplug.py +++ b/kasa/smartplug.py @@ -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 diff --git a/kasa/smartprotocol.py b/kasa/smartprotocol.py index c50c511f..c28db948 100644 --- a/kasa/smartprotocol.py +++ b/kasa/smartprotocol.py @@ -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 diff --git a/kasa/smartstrip.py b/kasa/smartstrip.py index 79393132..b1e967c4 100755 --- a/kasa/smartstrip.py +++ b/kasa/smartstrip.py @@ -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" diff --git a/kasa/tapo/tapodevice.py b/kasa/tapo/tapodevice.py index 8edec611..ff8bdaea 100644 --- a/kasa/tapo/tapodevice.py +++ b/kasa/tapo/tapodevice.py @@ -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)), diff --git a/kasa/tapo/tapoplug.py b/kasa/tapo/tapoplug.py index bb20f5cc..1bd90fd3 100644 --- a/kasa/tapo/tapoplug.py +++ b/kasa/tapo/tapoplug.py @@ -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 diff --git a/kasa/tests/test_protocol.py b/kasa/tests/test_protocol.py index 563b8176..f623b597 100644 --- a/kasa/tests/test_protocol.py +++ b/kasa/tests/test_protocol.py @@ -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())