mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Use credentials_hash for smartcamera rtsp url (#1293)
This commit is contained in:
@@ -2,13 +2,18 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import logging
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
from ...credentials import Credentials
|
||||
from ...device_type import DeviceType
|
||||
from ...feature import Feature
|
||||
from ...json import loads as json_loads
|
||||
from ..smartcameramodule import SmartCameraModule
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
LOCAL_STREAMING_PORT = 554
|
||||
|
||||
|
||||
@@ -38,6 +43,27 @@ class Camera(SmartCameraModule):
|
||||
"""Return the device id."""
|
||||
return self.data["lens_mask_info"]["enabled"] == "off"
|
||||
|
||||
def _get_credentials(self) -> Credentials | None:
|
||||
"""Get credentials from ."""
|
||||
config = self._device.config
|
||||
if credentials := config.credentials:
|
||||
return credentials
|
||||
|
||||
if credentials_hash := config.credentials_hash:
|
||||
try:
|
||||
decoded = json_loads(
|
||||
base64.b64decode(credentials_hash.encode()).decode()
|
||||
)
|
||||
except Exception:
|
||||
_LOGGER.warning(
|
||||
"Unable to deserialize credentials_hash: %s", credentials_hash
|
||||
)
|
||||
return None
|
||||
if (username := decoded.get("un")) and (password := decoded.get("pwd")):
|
||||
return Credentials(username, password)
|
||||
|
||||
return None
|
||||
|
||||
def stream_rtsp_url(self, credentials: Credentials | None = None) -> str | None:
|
||||
"""Return the local rtsp streaming url.
|
||||
|
||||
@@ -51,7 +77,8 @@ class Camera(SmartCameraModule):
|
||||
return None
|
||||
dev = self._device
|
||||
if not credentials:
|
||||
credentials = dev.credentials
|
||||
credentials = self._get_credentials()
|
||||
|
||||
if not credentials or not credentials.username or not credentials.password:
|
||||
return None
|
||||
username = quote_plus(credentials.username)
|
||||
|
Reference in New Issue
Block a user