Rename base TPLinkProtocol to BaseProtocol (#669)

This commit is contained in:
Steven B 2024-01-22 15:28:30 +00:00 committed by GitHub
parent b784d891ff
commit 14acc8550e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 30 additions and 30 deletions

View File

@ -29,7 +29,7 @@ from kasa.exceptions import (
UnsupportedDeviceException, UnsupportedDeviceException,
) )
from kasa.iotprotocol import IotProtocol 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.smartbulb import SmartBulb, SmartBulbPreset, TurnOnBehavior, TurnOnBehaviors
from kasa.smartdevice import DeviceType, SmartDevice from kasa.smartdevice import DeviceType, SmartDevice
from kasa.smartdimmer import SmartDimmer from kasa.smartdimmer import SmartDimmer
@ -44,7 +44,7 @@ __version__ = version("python-kasa")
__all__ = [ __all__ = [
"Discover", "Discover",
"TPLinkSmartHomeProtocol", "TPLinkSmartHomeProtocol",
"TPLinkProtocol", "BaseProtocol",
"IotProtocol", "IotProtocol",
"SmartProtocol", "SmartProtocol",
"SmartBulb", "SmartBulb",

View File

@ -9,8 +9,8 @@ from .exceptions import SmartDeviceException, UnsupportedDeviceException
from .iotprotocol import IotProtocol from .iotprotocol import IotProtocol
from .klaptransport import KlapTransport, KlapTransportV2 from .klaptransport import KlapTransport, KlapTransportV2
from .protocol import ( from .protocol import (
BaseProtocol,
BaseTransport, BaseTransport,
TPLinkProtocol,
TPLinkSmartHomeProtocol, TPLinkSmartHomeProtocol,
_XorTransport, _XorTransport,
) )
@ -141,14 +141,14 @@ def get_device_class_from_family(device_type: str) -> Optional[Type[SmartDevice]
def get_protocol( def get_protocol(
config: DeviceConfig, config: DeviceConfig,
) -> Optional[TPLinkProtocol]: ) -> Optional[BaseProtocol]:
"""Return the protocol from the connection name.""" """Return the protocol from the connection name."""
protocol_name = config.connection_type.device_family.value.split(".")[0] protocol_name = config.connection_type.device_family.value.split(".")[0]
protocol_transport_key = ( protocol_transport_key = (
protocol_name + "." + config.connection_type.encryption_type.value protocol_name + "." + config.connection_type.encryption_type.value
) )
supported_device_protocols: Dict[ supported_device_protocols: Dict[
str, Tuple[Type[TPLinkProtocol], Type[BaseTransport]] str, Tuple[Type[BaseProtocol], Type[BaseTransport]]
] = { ] = {
"IOT.XOR": (TPLinkSmartHomeProtocol, _XorTransport), "IOT.XOR": (TPLinkSmartHomeProtocol, _XorTransport),
"IOT.KLAP": (IotProtocol, KlapTransport), "IOT.KLAP": (IotProtocol, KlapTransport),

View File

@ -11,12 +11,12 @@ from .exceptions import (
TimeoutException, TimeoutException,
) )
from .json import dumps as json_dumps from .json import dumps as json_dumps
from .protocol import BaseTransport, TPLinkProtocol from .protocol import BaseProtocol, BaseTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class IotProtocol(TPLinkProtocol): class IotProtocol(BaseProtocol):
"""Class for the legacy TPLink IOT KASA Protocol.""" """Class for the legacy TPLink IOT KASA Protocol."""
BACKOFF_SECONDS_AFTER_TIMEOUT = 1 BACKOFF_SECONDS_AFTER_TIMEOUT = 1

View File

@ -79,7 +79,7 @@ class BaseTransport(ABC):
"""Close the transport. Abstract method to be overriden.""" """Close the transport. Abstract method to be overriden."""
class TPLinkProtocol(ABC): class BaseProtocol(ABC):
"""Base class for all TP-Link Smart Home communication.""" """Base class for all TP-Link Smart Home communication."""
def __init__( def __init__(
@ -140,7 +140,7 @@ class _XorTransport(BaseTransport):
"""Close the transport. Abstract method to be overriden.""" """Close the transport. Abstract method to be overriden."""
class TPLinkSmartHomeProtocol(TPLinkProtocol): class TPLinkSmartHomeProtocol(BaseProtocol):
"""Implementation of the TP-Link Smart Home protocol.""" """Implementation of the TP-Link Smart Home protocol."""
INITIALIZATION_VECTOR = 171 INITIALIZATION_VECTOR = 171

View File

@ -11,7 +11,7 @@ except ImportError:
from .deviceconfig import DeviceConfig from .deviceconfig import DeviceConfig
from .modules import Antitheft, Cloud, Countdown, Emeter, Schedule, Time, Usage 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 from .smartdevice import DeviceType, SmartDevice, SmartDeviceException, requires_update
@ -222,7 +222,7 @@ class SmartBulb(SmartDevice):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.Bulb self._device_type = DeviceType.Bulb

View File

@ -25,7 +25,7 @@ from .deviceconfig import DeviceConfig
from .emeterstatus import EmeterStatus from .emeterstatus import EmeterStatus
from .exceptions import SmartDeviceException from .exceptions import SmartDeviceException
from .modules import Emeter, Module from .modules import Emeter, Module
from .protocol import TPLinkProtocol, TPLinkSmartHomeProtocol, _XorTransport from .protocol import BaseProtocol, TPLinkSmartHomeProtocol, _XorTransport
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -196,7 +196,7 @@ class SmartDevice:
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
"""Create a new SmartDevice instance. """Create a new SmartDevice instance.
@ -204,7 +204,7 @@ class SmartDevice:
""" """
if config and protocol: if config and protocol:
protocol._transport._config = config protocol._transport._config = config
self.protocol: TPLinkProtocol = protocol or TPLinkSmartHomeProtocol( self.protocol: BaseProtocol = protocol or TPLinkSmartHomeProtocol(
transport=_XorTransport(config=config or DeviceConfig(host=host)), transport=_XorTransport(config=config or DeviceConfig(host=host)),
) )
_LOGGER.debug("Initializing %s of type %s", self.host, type(self)) _LOGGER.debug("Initializing %s of type %s", self.host, type(self))

View File

@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
from kasa.deviceconfig import DeviceConfig from kasa.deviceconfig import DeviceConfig
from kasa.modules import AmbientLight, Motion 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.smartdevice import DeviceType, SmartDeviceException, requires_update
from kasa.smartplug import SmartPlug from kasa.smartplug import SmartPlug
@ -70,7 +70,7 @@ class SmartDimmer(SmartPlug):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.Dimmer self._device_type = DeviceType.Dimmer

View File

@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional
from .deviceconfig import DeviceConfig from .deviceconfig import DeviceConfig
from .effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1 from .effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
from .protocol import TPLinkProtocol from .protocol import BaseProtocol
from .smartbulb import SmartBulb from .smartbulb import SmartBulb
from .smartdevice import DeviceType, SmartDeviceException, requires_update from .smartdevice import DeviceType, SmartDeviceException, requires_update
@ -48,7 +48,7 @@ class SmartLightStrip(SmartBulb):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.LightStrip self._device_type = DeviceType.LightStrip

View File

@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
from kasa.deviceconfig import DeviceConfig from kasa.deviceconfig import DeviceConfig
from kasa.modules import Antitheft, Cloud, Schedule, Time, Usage 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 from kasa.smartdevice import DeviceType, SmartDevice, requires_update
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -45,7 +45,7 @@ class SmartPlug(SmartDevice):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.Plug self._device_type = DeviceType.Plug

View File

@ -24,12 +24,12 @@ from .exceptions import (
TimeoutException, TimeoutException,
) )
from .json import dumps as json_dumps from .json import dumps as json_dumps
from .protocol import BaseTransport, TPLinkProtocol, md5 from .protocol import BaseProtocol, BaseTransport, md5
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
class SmartProtocol(TPLinkProtocol): class SmartProtocol(BaseProtocol):
"""Class for the new TPLink SMART protocol.""" """Class for the new TPLink SMART protocol."""
BACKOFF_SECONDS_AFTER_TIMEOUT = 1 BACKOFF_SECONDS_AFTER_TIMEOUT = 1

View File

@ -16,7 +16,7 @@ from kasa.smartplug import SmartPlug
from .deviceconfig import DeviceConfig from .deviceconfig import DeviceConfig
from .modules import Antitheft, Countdown, Emeter, Schedule, Time, Usage from .modules import Antitheft, Countdown, Emeter, Schedule, Time, Usage
from .protocol import TPLinkProtocol from .protocol import BaseProtocol
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -87,7 +87,7 @@ class SmartStrip(SmartDevice):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self.emeter_type = "emeter" self.emeter_type = "emeter"

View File

@ -9,7 +9,7 @@ from ..deviceconfig import DeviceConfig
from ..emeterstatus import EmeterStatus from ..emeterstatus import EmeterStatus
from ..exceptions import AuthenticationException, SmartDeviceException from ..exceptions import AuthenticationException, SmartDeviceException
from ..modules import Emeter from ..modules import Emeter
from ..protocol import TPLinkProtocol from ..protocol import BaseProtocol
from ..smartdevice import SmartDevice, WifiNetwork from ..smartdevice import SmartDevice, WifiNetwork
from ..smartprotocol import SmartProtocol from ..smartprotocol import SmartProtocol
@ -24,7 +24,7 @@ class TapoDevice(SmartDevice):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
_protocol = protocol or SmartProtocol( _protocol = protocol or SmartProtocol(
transport=AesTransport(config=config or DeviceConfig(host=host)), transport=AesTransport(config=config or DeviceConfig(host=host)),

View File

@ -4,7 +4,7 @@ from datetime import datetime, timedelta
from typing import Any, Dict, Optional, cast from typing import Any, Dict, Optional, cast
from ..deviceconfig import DeviceConfig from ..deviceconfig import DeviceConfig
from ..protocol import TPLinkProtocol from ..protocol import BaseProtocol
from ..smartdevice import DeviceType from ..smartdevice import DeviceType
from .tapodevice import TapoDevice from .tapodevice import TapoDevice
@ -19,7 +19,7 @@ class TapoPlug(TapoDevice):
host: str, host: str,
*, *,
config: Optional[DeviceConfig] = None, config: Optional[DeviceConfig] = None,
protocol: Optional[TPLinkProtocol] = None, protocol: Optional[BaseProtocol] = None,
) -> None: ) -> None:
super().__init__(host=host, config=config, protocol=protocol) super().__init__(host=host, config=config, protocol=protocol)
self._device_type = DeviceType.Plug self._device_type = DeviceType.Plug

View File

@ -16,8 +16,8 @@ from ..deviceconfig import DeviceConfig
from ..exceptions import SmartDeviceException from ..exceptions import SmartDeviceException
from ..klaptransport import KlapTransport, KlapTransportV2 from ..klaptransport import KlapTransport, KlapTransportV2
from ..protocol import ( from ..protocol import (
BaseProtocol,
BaseTransport, BaseTransport,
TPLinkProtocol,
TPLinkSmartHomeProtocol, TPLinkSmartHomeProtocol,
_XorTransport, _XorTransport,
) )
@ -345,7 +345,7 @@ def _get_subclasses(of_class):
@pytest.mark.parametrize( @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): def test_protocol_init_signature(class_name_obj):
params = list(inspect.signature(class_name_obj[1].__init__).parameters.values()) params = list(inspect.signature(class_name_obj[1].__init__).parameters.values())