mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-01 13:48:15 +00:00
Update to use http port from discovery if present
This commit is contained in:
@@ -205,11 +205,11 @@ def get_protocol(config: DeviceConfig, *, strict: bool = False) -> BaseProtocol
|
||||
return IotProtocol(transport=LinkieTransportV2(config=config))
|
||||
|
||||
# Older FW used a different transport
|
||||
if ctype.device_family is DeviceFamily.SmartTapoRobovac:
|
||||
if strict and ctype.encryption_type is not DeviceEncryptionType.Aes:
|
||||
return None
|
||||
if ctype.encryption_type is DeviceEncryptionType.Aes:
|
||||
return SmartProtocol(transport=SslTransport(config=config))
|
||||
if (
|
||||
ctype.device_family is DeviceFamily.SmartTapoRobovac
|
||||
and ctype.encryption_type is DeviceEncryptionType.Aes
|
||||
):
|
||||
return SmartProtocol(transport=SslTransport(config=config))
|
||||
|
||||
protocol_transport_key = (
|
||||
protocol_name
|
||||
|
||||
@@ -20,7 +20,7 @@ None
|
||||
{'host': '127.0.0.3', 'timeout': 5, 'credentials': {'username': 'user@example.com', \
|
||||
'password': 'great_password'}, 'connection_type'\
|
||||
: {'device_family': 'SMART.TAPOBULB', 'encryption_type': 'KLAP', 'login_version': 2, \
|
||||
'https': False}}
|
||||
'https': False, 'http_port': 80}}
|
||||
|
||||
>>> later_device = await Device.connect(config=Device.Config.from_dict(config_dict))
|
||||
>>> print(later_device.alias) # Alias is available as connect() calls update()
|
||||
@@ -98,13 +98,16 @@ class DeviceConnectionParameters(_DeviceConfigBaseMixin):
|
||||
encryption_type: DeviceEncryptionType
|
||||
login_version: int | None = None
|
||||
https: bool = False
|
||||
http_port: int | None = None
|
||||
|
||||
@staticmethod
|
||||
def from_values(
|
||||
device_family: str,
|
||||
encryption_type: str,
|
||||
*,
|
||||
login_version: int | None = None,
|
||||
https: bool | None = None,
|
||||
http_port: int | None = None,
|
||||
) -> DeviceConnectionParameters:
|
||||
"""Return connection parameters from string values."""
|
||||
try:
|
||||
@@ -115,6 +118,7 @@ class DeviceConnectionParameters(_DeviceConfigBaseMixin):
|
||||
DeviceEncryptionType(encryption_type),
|
||||
login_version,
|
||||
https,
|
||||
http_port=http_port,
|
||||
)
|
||||
except (ValueError, TypeError) as ex:
|
||||
raise KasaException(
|
||||
|
||||
@@ -637,10 +637,10 @@ class Discover:
|
||||
Device.Family.IotIpCamera,
|
||||
}
|
||||
candidates: dict[
|
||||
tuple[type[BaseProtocol], type[BaseTransport], type[Device]],
|
||||
tuple[type[BaseProtocol], type[BaseTransport], type[Device], bool],
|
||||
tuple[BaseProtocol, DeviceConfig],
|
||||
] = {
|
||||
(type(protocol), type(protocol._transport), device_class): (
|
||||
(type(protocol), type(protocol._transport), device_class, https): (
|
||||
protocol,
|
||||
config,
|
||||
)
|
||||
@@ -870,8 +870,9 @@ class Discover:
|
||||
config.connection_type = DeviceConnectionParameters.from_values(
|
||||
type_,
|
||||
encrypt_type,
|
||||
login_version,
|
||||
encrypt_schm.is_support_https,
|
||||
login_version=login_version,
|
||||
https=encrypt_schm.is_support_https,
|
||||
http_port=encrypt_schm.http_port,
|
||||
)
|
||||
except KasaException as ex:
|
||||
raise UnsupportedDeviceError(
|
||||
|
||||
@@ -120,6 +120,8 @@ class AesTransport(BaseTransport):
|
||||
@property
|
||||
def default_port(self) -> int:
|
||||
"""Default port for the transport."""
|
||||
if port := self._config.connection_type.http_port:
|
||||
return port
|
||||
return self.DEFAULT_PORT
|
||||
|
||||
@property
|
||||
|
||||
@@ -93,6 +93,8 @@ class KlapTransport(BaseTransport):
|
||||
"""
|
||||
|
||||
DEFAULT_PORT: int = 80
|
||||
DEFAULT_HTTPS_PORT: int = 4433
|
||||
|
||||
SESSION_COOKIE_NAME = "TP_SESSIONID"
|
||||
TIMEOUT_COOKIE_NAME = "TIMEOUT"
|
||||
# Copy & paste from sslaestransport
|
||||
@@ -144,6 +146,13 @@ class KlapTransport(BaseTransport):
|
||||
@property
|
||||
def default_port(self) -> int:
|
||||
"""Default port for the transport."""
|
||||
config = self._config
|
||||
if port := config.connection_type.http_port:
|
||||
return port
|
||||
|
||||
if config.connection_type.https:
|
||||
return self.DEFAULT_HTTPS_PORT
|
||||
|
||||
return self.DEFAULT_PORT
|
||||
|
||||
@property
|
||||
|
||||
@@ -55,6 +55,8 @@ class LinkieTransportV2(BaseTransport):
|
||||
@property
|
||||
def default_port(self) -> int:
|
||||
"""Default port for the transport."""
|
||||
if port := self._config.connection_type.http_port:
|
||||
return port
|
||||
return self.DEFAULT_PORT
|
||||
|
||||
@property
|
||||
|
||||
@@ -133,6 +133,8 @@ class SslAesTransport(BaseTransport):
|
||||
@property
|
||||
def default_port(self) -> int:
|
||||
"""Default port for the transport."""
|
||||
if port := self._config.connection_type.http_port:
|
||||
return port
|
||||
return self.DEFAULT_PORT
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -94,6 +94,8 @@ class SslTransport(BaseTransport):
|
||||
@property
|
||||
def default_port(self) -> int:
|
||||
"""Default port for the transport."""
|
||||
if port := self._config.connection_type.http_port:
|
||||
return port
|
||||
return self.DEFAULT_PORT
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user