mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-12 02:18:02 +00:00
Enable dynamic hub child creation and deletion on update (#1454)
This commit is contained in:
@@ -188,6 +188,33 @@ class FakeSmartCamTransport(BaseTransport):
|
||||
next(it, None)
|
||||
return next(it)
|
||||
|
||||
def get_child_device_queries(self, method, params):
|
||||
return self._get_method_from_info(method, params)
|
||||
|
||||
def _get_method_from_info(self, method, params):
|
||||
result = copy.deepcopy(self.info[method])
|
||||
if "start_index" in result and "sum" in result:
|
||||
list_key = next(
|
||||
iter([key for key in result if isinstance(result[key], list)])
|
||||
)
|
||||
assert isinstance(params, dict)
|
||||
module_name = next(iter(params))
|
||||
|
||||
start_index = (
|
||||
start_index
|
||||
if (
|
||||
params
|
||||
and module_name
|
||||
and (start_index := params[module_name].get("start_index"))
|
||||
)
|
||||
else 0
|
||||
)
|
||||
|
||||
result[list_key] = result[list_key][
|
||||
start_index : start_index + self.list_return_size
|
||||
]
|
||||
return {"result": result, "error_code": 0}
|
||||
|
||||
async def _send_request(self, request_dict: dict):
|
||||
method = request_dict["method"]
|
||||
|
||||
@@ -257,30 +284,18 @@ class FakeSmartCamTransport(BaseTransport):
|
||||
result = {"device_info": {"basic_info": mapped}}
|
||||
return {"result": result, "error_code": 0}
|
||||
|
||||
# These methods are handled in get_child_device_query so it can be
|
||||
# patched for tests to simulate dynamic devices.
|
||||
if (
|
||||
method in ("getChildDeviceList", "getChildDeviceComponentList")
|
||||
and method in info
|
||||
):
|
||||
params = request_dict.get("params")
|
||||
return self.get_child_device_queries(method, params)
|
||||
|
||||
if method in info:
|
||||
params = request_dict.get("params")
|
||||
result = copy.deepcopy(info[method])
|
||||
if "start_index" in result and "sum" in result:
|
||||
list_key = next(
|
||||
iter([key for key in result if isinstance(result[key], list)])
|
||||
)
|
||||
assert isinstance(params, dict)
|
||||
module_name = next(iter(params))
|
||||
|
||||
start_index = (
|
||||
start_index
|
||||
if (
|
||||
params
|
||||
and module_name
|
||||
and (start_index := params[module_name].get("start_index"))
|
||||
)
|
||||
else 0
|
||||
)
|
||||
|
||||
result[list_key] = result[list_key][
|
||||
start_index : start_index + self.list_return_size
|
||||
]
|
||||
return {"result": result, "error_code": 0}
|
||||
return self._get_method_from_info(method, params)
|
||||
|
||||
if self.verbatim:
|
||||
return {"error_code": -1}
|
||||
|
Reference in New Issue
Block a user