mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 02:18:02 +00:00
Add common childsetup interface (#1470)
Add a common interface for the `childsetup` module across `smart` and `smartcam` hubs. Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
@@ -9,12 +9,13 @@ import asyncio
|
||||
import logging
|
||||
|
||||
from ...feature import Feature
|
||||
from ...interfaces.childsetup import ChildSetup as ChildSetupInterface
|
||||
from ..smartcammodule import SmartCamModule
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ChildSetup(SmartCamModule):
|
||||
class ChildSetup(SmartCamModule, ChildSetupInterface):
|
||||
"""Implementation for child device setup."""
|
||||
|
||||
REQUIRED_COMPONENT = "childQuickSetup"
|
||||
@@ -22,6 +23,9 @@ class ChildSetup(SmartCamModule):
|
||||
QUERY_MODULE_NAME = "childControl"
|
||||
_categories: list[str] = []
|
||||
|
||||
# Supported child device categories will hardly ever change
|
||||
MINIMUM_UPDATE_INTERVAL_SECS = 60 * 60 * 24
|
||||
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
self._add_feature(
|
||||
@@ -37,19 +41,18 @@ class ChildSetup(SmartCamModule):
|
||||
)
|
||||
|
||||
async def _post_update_hook(self) -> None:
|
||||
if not self._categories:
|
||||
self._categories = [
|
||||
cat["category"].replace("ipcamera", "camera")
|
||||
for cat in self.data["device_category_list"]
|
||||
]
|
||||
self._categories = [
|
||||
cat["category"].replace("ipcamera", "camera")
|
||||
for cat in self.data["device_category_list"]
|
||||
]
|
||||
|
||||
@property
|
||||
def supported_child_device_categories(self) -> list[str]:
|
||||
def supported_categories(self) -> list[str]:
|
||||
"""Supported child device categories."""
|
||||
return self._categories
|
||||
|
||||
async def pair(self, *, timeout: int = 10) -> list[dict]:
|
||||
"""Scan for new devices and pair after discovering first new device."""
|
||||
"""Scan for new devices and pair them."""
|
||||
await self.call(
|
||||
"startScanChildDevice", {"childControl": {"category": self._categories}}
|
||||
)
|
||||
@@ -76,7 +79,7 @@ class ChildSetup(SmartCamModule):
|
||||
)
|
||||
return await self._add_devices(detected_list)
|
||||
|
||||
async def _add_devices(self, detected_list: list[dict]) -> list:
|
||||
async def _add_devices(self, detected_list: list[dict]) -> list[dict]:
|
||||
"""Add devices based on getScanChildDeviceList response."""
|
||||
await self.call(
|
||||
"addScanChildDeviceList",
|
||||
@@ -104,4 +107,6 @@ class ChildSetup(SmartCamModule):
|
||||
_LOGGER.info("Going to unpair %s from %s", device_id, self)
|
||||
|
||||
payload = {"childControl": {"child_device_list": [{"device_id": device_id}]}}
|
||||
return await self.call("removeChildDeviceList", payload)
|
||||
res = await self.call("removeChildDeviceList", payload)
|
||||
await self._device.update()
|
||||
return res
|
||||
|
Reference in New Issue
Block a user