mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-20 19:50:15 +00:00
Add test framework for smartcamera (#1192)
This commit is contained in:
@@ -4,10 +4,11 @@ import glob
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
from typing import Iterable, NamedTuple
|
||||
|
||||
from kasa.device_factory import _get_device_type_from_sys_info
|
||||
from kasa.device_type import DeviceType
|
||||
from kasa.experimental.smartcamera import SmartCamera
|
||||
from kasa.smart.smartdevice import SmartDevice
|
||||
|
||||
|
||||
@@ -48,9 +49,18 @@ SUPPORTED_SMART_CHILD_DEVICES = [
|
||||
)
|
||||
]
|
||||
|
||||
SUPPORTED_SMARTCAMERA_DEVICES = [
|
||||
(device, "SMARTCAMERA")
|
||||
for device in glob.glob(
|
||||
os.path.dirname(os.path.abspath(__file__)) + "/fixtures/smartcamera/*.json"
|
||||
)
|
||||
]
|
||||
|
||||
SUPPORTED_DEVICES = (
|
||||
SUPPORTED_IOT_DEVICES + SUPPORTED_SMART_DEVICES + SUPPORTED_SMART_CHILD_DEVICES
|
||||
SUPPORTED_IOT_DEVICES
|
||||
+ SUPPORTED_SMART_DEVICES
|
||||
+ SUPPORTED_SMART_CHILD_DEVICES
|
||||
+ SUPPORTED_SMARTCAMERA_DEVICES
|
||||
)
|
||||
|
||||
|
||||
@@ -95,7 +105,7 @@ def filter_fixtures(
|
||||
protocol_filter: set[str] | None = None,
|
||||
model_filter: set[str] | None = None,
|
||||
component_filter: str | ComponentFilter | None = None,
|
||||
device_type_filter: list[DeviceType] | None = None,
|
||||
device_type_filter: Iterable[DeviceType] | None = None,
|
||||
):
|
||||
"""Filter the fixtures based on supplied parameters.
|
||||
|
||||
@@ -107,7 +117,11 @@ def filter_fixtures(
|
||||
component in component_nego details.
|
||||
"""
|
||||
|
||||
def _model_match(fixture_data: FixtureInfo, model_filter):
|
||||
def _model_match(fixture_data: FixtureInfo, model_filter: set[str]):
|
||||
model_filter_list = [mf for mf in model_filter]
|
||||
if len(model_filter_list) == 1 and model_filter_list[0].split("_") == 3:
|
||||
# return exact match
|
||||
return fixture_data.name == model_filter_list[0]
|
||||
file_model_region = fixture_data.name.split("_")[0]
|
||||
file_model = file_model_region.split("(")[0]
|
||||
return file_model in model_filter
|
||||
@@ -134,16 +148,21 @@ def filter_fixtures(
|
||||
)
|
||||
|
||||
def _device_type_match(fixture_data: FixtureInfo, device_type):
|
||||
if (component_nego := fixture_data.data.get("component_nego")) is None:
|
||||
return _get_device_type_from_sys_info(fixture_data.data) in device_type
|
||||
components = [component["id"] for component in component_nego["component_list"]]
|
||||
if (info := fixture_data.data.get("get_device_info")) and (
|
||||
type_ := info.get("type")
|
||||
):
|
||||
if fixture_data.protocol in {"SMART", "SMART.CHILD"}:
|
||||
info = fixture_data.data["get_device_info"]
|
||||
component_nego = fixture_data.data["component_nego"]
|
||||
components = [
|
||||
component["id"] for component in component_nego["component_list"]
|
||||
]
|
||||
return (
|
||||
SmartDevice._get_device_type_from_components(components, type_)
|
||||
SmartDevice._get_device_type_from_components(components, info["type"])
|
||||
in device_type
|
||||
)
|
||||
elif fixture_data.protocol == "IOT":
|
||||
return _get_device_type_from_sys_info(fixture_data.data) in device_type
|
||||
elif fixture_data.protocol == "SMARTCAMERA":
|
||||
info = fixture_data.data["getDeviceInfo"]["device_info"]["basic_info"]
|
||||
return SmartCamera._get_device_type_from_sysinfo(info) in device_type
|
||||
return False
|
||||
|
||||
filtered = []
|
||||
|
||||
Reference in New Issue
Block a user