From 2bda54fcb15ecb8d590b4c5046daea04951c0ba7 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Sat, 23 Nov 2024 08:07:47 +0000 Subject: [PATCH] Rename smartcamera to smartcam (#1300) --- devtools/dump_devinfo.py | 24 ++++++------- devtools/generate_supported.py | 8 ++--- ...tcamerarequests.py => smartcamrequests.py} | 2 +- kasa/device_factory.py | 10 +++--- kasa/module.py | 6 ++-- ...tcameraprotocol.py => smartcamprotocol.py} | 8 ++--- kasa/protocols/smartprotocol.py | 2 +- kasa/smartcam/__init__.py | 5 +++ .../modules/__init__.py | 2 +- .../modules/alarm.py | 6 ++-- .../modules/camera.py | 4 +-- .../modules/childdevice.py | 4 +-- .../modules/device.py | 4 +-- kasa/{smartcamera => smartcam}/modules/led.py | 4 +-- .../modules/pantilt.py | 4 +-- .../{smartcamera => smartcam}/modules/time.py | 4 +-- .../smartcamdevice.py} | 14 ++++---- .../smartcammodule.py} | 10 +++--- kasa/smartcamera/__init__.py | 5 --- tests/device_fixtures.py | 34 +++++++++---------- tests/discovery_fixtures.py | 10 +++--- ...martcamera.py => fakeprotocol_smartcam.py} | 8 ++--- tests/fixtureinfo.py | 16 ++++----- .../C210(EU)_2.0_1.4.2.json | 0 .../C210(EU)_2.0_1.4.3.json | 0 .../H200(EU)_1.0_1.3.2.json | 0 .../H200(US)_1.0_1.3.6.json | 0 .../TC65_1.0_1.3.9.json | 0 tests/smartcamera/modules/test_alarm.py | 18 +++++----- tests/smartcamera/test_smartcamera.py | 12 +++---- tests/test_cli.py | 8 ++--- tests/test_device.py | 4 +-- tests/test_device_factory.py | 6 ++-- tests/test_devtools.py | 18 +++++----- 34 files changed, 130 insertions(+), 130 deletions(-) rename devtools/helpers/{smartcamerarequests.py => smartcamrequests.py} (98%) rename kasa/protocols/{smartcameraprotocol.py => smartcamprotocol.py} (97%) create mode 100644 kasa/smartcam/__init__.py rename kasa/{smartcamera => smartcam}/modules/__init__.py (88%) rename kasa/{smartcamera => smartcam}/modules/alarm.py (97%) rename kasa/{smartcamera => smartcam}/modules/camera.py (97%) rename kasa/{smartcamera => smartcam}/modules/childdevice.py (90%) rename kasa/{smartcamera => smartcam}/modules/device.py (92%) rename kasa/{smartcamera => smartcam}/modules/led.py (88%) rename kasa/{smartcamera => smartcam}/modules/pantilt.py (97%) rename kasa/{smartcamera => smartcam}/modules/time.py (96%) rename kasa/{smartcamera/smartcamera.py => smartcam/smartcamdevice.py} (96%) rename kasa/{smartcamera/smartcameramodule.py => smartcam/smartcammodule.py} (92%) delete mode 100644 kasa/smartcamera/__init__.py rename tests/{fakeprotocol_smartcamera.py => fakeprotocol_smartcam.py} (97%) rename tests/fixtures/{smartcamera => smartcam}/C210(EU)_2.0_1.4.2.json (100%) rename tests/fixtures/{smartcamera => smartcam}/C210(EU)_2.0_1.4.3.json (100%) rename tests/fixtures/{smartcamera => smartcam}/H200(EU)_1.0_1.3.2.json (100%) rename tests/fixtures/{smartcamera => smartcam}/H200(US)_1.0_1.3.6.json (100%) rename tests/fixtures/{smartcamera => smartcam}/TC65_1.0_1.3.9.json (100%) diff --git a/devtools/dump_devinfo.py b/devtools/dump_devinfo.py index 3306387a..18005990 100644 --- a/devtools/dump_devinfo.py +++ b/devtools/dump_devinfo.py @@ -25,7 +25,7 @@ from typing import Any import asyncclick as click -from devtools.helpers.smartcamerarequests import SMARTCAMERA_REQUESTS +from devtools.helpers.smartcamrequests import SMARTCAM_REQUESTS from devtools.helpers.smartrequests import SmartRequest, get_component_requests from kasa import ( AuthenticationError, @@ -42,19 +42,19 @@ from kasa.deviceconfig import DeviceEncryptionType, DeviceFamily from kasa.discover import DiscoveryResult from kasa.exceptions import SmartErrorCode from kasa.protocols import IotProtocol -from kasa.protocols.smartcameraprotocol import ( - SmartCameraProtocol, +from kasa.protocols.smartcamprotocol import ( + SmartCamProtocol, _ChildCameraProtocolWrapper, ) from kasa.protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper from kasa.smart import SmartChildDevice, SmartDevice -from kasa.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice Call = namedtuple("Call", "module method") FixtureResult = namedtuple("FixtureResult", "filename, folder, data") SMART_FOLDER = "tests/fixtures/smart/" -SMARTCAMERA_FOLDER = "tests/fixtures/smartcamera/" +SMARTCAM_FOLDER = "tests/fixtures/smartcam/" SMART_CHILD_FOLDER = "tests/fixtures/smart/child/" IOT_FOLDER = "tests/fixtures/iot/" @@ -65,7 +65,7 @@ _LOGGER = logging.getLogger(__name__) @dataclasses.dataclass class SmartCall: - """Class for smart and smartcamera calls.""" + """Class for smart and smartcam calls.""" module: str request: dict @@ -562,7 +562,7 @@ async def _make_requests_or_exit( # Calling close on child protocol wrappers is a noop protocol_to_close = protocol if child_device_id: - if isinstance(protocol, SmartCameraProtocol): + if isinstance(protocol, SmartCamProtocol): protocol = _ChildCameraProtocolWrapper(child_device_id, protocol) else: protocol = _ChildProtocolWrapper(child_device_id, protocol) @@ -608,7 +608,7 @@ async def get_smart_camera_test_calls(protocol: SmartProtocol): successes: list[SmartCall] = [] test_calls = [] - for request in SMARTCAMERA_REQUESTS: + for request in SMARTCAM_REQUESTS: method = next(iter(request)) if method == "get": module = method + "_" + next(iter(request[method])) @@ -693,7 +693,7 @@ async def get_smart_camera_test_calls(protocol: SmartProtocol): click.echo(f"Skipping {component_id}..", nl=False) click.echo(click.style("UNSUPPORTED", fg="yellow")) else: # Not a smart protocol device so assume camera protocol - for request in SMARTCAMERA_REQUESTS: + for request in SMARTCAM_REQUESTS: method = next(iter(request)) if method == "get": method = method + "_" + next(iter(request[method])) @@ -858,7 +858,7 @@ async def get_smart_fixtures( protocol: SmartProtocol, *, discovery_info: dict[str, Any] | None, batch_size: int ) -> list[FixtureResult]: """Get fixture for new TAPO style protocol.""" - if isinstance(protocol, SmartCameraProtocol): + if isinstance(protocol, SmartCamProtocol): test_calls, successes = await get_smart_camera_test_calls(protocol) child_wrapper: type[_ChildProtocolWrapper | _ChildCameraProtocolWrapper] = ( _ChildCameraProtocolWrapper @@ -991,8 +991,8 @@ async def get_smart_fixtures( copy_folder = SMART_FOLDER else: # smart camera protocol - model_info = SmartCamera._get_device_info(final, discovery_info) - copy_folder = SMARTCAMERA_FOLDER + model_info = SmartCamDevice._get_device_info(final, discovery_info) + copy_folder = SMARTCAM_FOLDER hw_version = model_info.hardware_version sw_version = model_info.firmware_version model = model_info.long_name diff --git a/devtools/generate_supported.py b/devtools/generate_supported.py index 61e2e0fb..90e16e07 100755 --- a/devtools/generate_supported.py +++ b/devtools/generate_supported.py @@ -13,7 +13,7 @@ from typing import Any, NamedTuple from kasa.device_type import DeviceType from kasa.iot import IotDevice from kasa.smart import SmartDevice -from kasa.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice class SupportedVersion(NamedTuple): @@ -48,7 +48,7 @@ README_FILENAME = "README.md" IOT_FOLDER = "tests/fixtures/iot/" SMART_FOLDER = "tests/fixtures/smart/" SMART_CHILD_FOLDER = "tests/fixtures/smart/child" -SMARTCAMERA_FOLDER = "tests/fixtures/smartcamera/" +SMARTCAM_FOLDER = "tests/fixtures/smartcam/" def generate_supported(args): @@ -65,7 +65,7 @@ def generate_supported(args): _get_supported_devices(supported, IOT_FOLDER, IotDevice) _get_supported_devices(supported, SMART_FOLDER, SmartDevice) _get_supported_devices(supported, SMART_CHILD_FOLDER, SmartDevice) - _get_supported_devices(supported, SMARTCAMERA_FOLDER, SmartCamera) + _get_supported_devices(supported, SMARTCAM_FOLDER, SmartCamDevice) readme_updated = _update_supported_file( README_FILENAME, _supported_summary(supported), print_diffs @@ -208,7 +208,7 @@ def _supported_text( def _get_supported_devices( supported: dict[str, Any], fixture_location: str, - device_cls: type[IotDevice | SmartDevice | SmartCamera], + device_cls: type[IotDevice | SmartDevice | SmartCamDevice], ): for file in Path(fixture_location).glob("*.json"): with file.open() as f: diff --git a/devtools/helpers/smartcamerarequests.py b/devtools/helpers/smartcamrequests.py similarity index 98% rename from devtools/helpers/smartcamerarequests.py rename to devtools/helpers/smartcamrequests.py index 2779ac0e..074b5774 100644 --- a/devtools/helpers/smartcamerarequests.py +++ b/devtools/helpers/smartcamrequests.py @@ -2,7 +2,7 @@ from __future__ import annotations -SMARTCAMERA_REQUESTS: list[dict] = [ +SMARTCAM_REQUESTS: list[dict] = [ {"getAlertTypeList": {"msg_alarm": {"name": "alert_type"}}}, {"getNightVisionCapability": {"image_capability": {"name": ["supplement_lamp"]}}}, {"getDeviceInfo": {"device_info": {"name": ["basic_info"]}}}, diff --git a/kasa/device_factory.py b/kasa/device_factory.py index f0b90b6e..d7ba5b53 100755 --- a/kasa/device_factory.py +++ b/kasa/device_factory.py @@ -24,9 +24,9 @@ from .protocols import ( IotProtocol, SmartProtocol, ) -from .protocols.smartcameraprotocol import SmartCameraProtocol +from .protocols.smartcamprotocol import SmartCamProtocol from .smart import SmartDevice -from .smartcamera.smartcamera import SmartCamera +from .smartcam import SmartCamDevice from .transports import ( AesTransport, BaseTransport, @@ -151,10 +151,10 @@ def get_device_class_from_family( "SMART.TAPOSWITCH": SmartDevice, "SMART.KASAPLUG": SmartDevice, "SMART.TAPOHUB": SmartDevice, - "SMART.TAPOHUB.HTTPS": SmartCamera, + "SMART.TAPOHUB.HTTPS": SmartCamDevice, "SMART.KASAHUB": SmartDevice, "SMART.KASASWITCH": SmartDevice, - "SMART.IPCAMERA.HTTPS": SmartCamera, + "SMART.IPCAMERA.HTTPS": SmartCamDevice, "IOT.SMARTPLUGSWITCH": IotPlug, "IOT.SMARTBULB": IotBulb, } @@ -189,7 +189,7 @@ def get_protocol( "IOT.KLAP": (IotProtocol, KlapTransport), "SMART.AES": (SmartProtocol, AesTransport), "SMART.KLAP": (SmartProtocol, KlapTransportV2), - "SMART.AES.HTTPS": (SmartCameraProtocol, SslAesTransport), + "SMART.AES.HTTPS": (SmartCamProtocol, SslAesTransport), } if not (prot_tran_cls := supported_device_protocols.get(protocol_transport_key)): return None diff --git a/kasa/module.py b/kasa/module.py index ccd22d4e..9f268577 100644 --- a/kasa/module.py +++ b/kasa/module.py @@ -60,7 +60,7 @@ if TYPE_CHECKING: from .device import Device from .iot import modules as iot from .smart import modules as smart - from .smartcamera import modules as smartcamera + from .smartcam import modules as smartcam _LOGGER = logging.getLogger(__name__) @@ -139,8 +139,8 @@ class Module(ABC): ) TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = ModuleName("TriggerLogs") - # SMARTCAMERA only modules - Camera: Final[ModuleName[smartcamera.Camera]] = ModuleName("Camera") + # SMARTCAM only modules + Camera: Final[ModuleName[smartcam.Camera]] = ModuleName("Camera") def __init__(self, device: Device, module: str) -> None: self._device = device diff --git a/kasa/protocols/smartcameraprotocol.py b/kasa/protocols/smartcamprotocol.py similarity index 97% rename from kasa/protocols/smartcameraprotocol.py rename to kasa/protocols/smartcamprotocol.py index 57f78d40..12caa207 100644 --- a/kasa/protocols/smartcameraprotocol.py +++ b/kasa/protocols/smartcamprotocol.py @@ -1,4 +1,4 @@ -"""Module for SmartCamera Protocol.""" +"""Module for SmartCamProtocol.""" from __future__ import annotations @@ -46,8 +46,8 @@ class SingleRequest: request: dict[str, Any] -class SmartCameraProtocol(SmartProtocol): - """Class for SmartCamera Protocol.""" +class SmartCamProtocol(SmartProtocol): + """Class for SmartCam Protocol.""" async def _handle_response_lists( self, response_result: dict[str, Any], method: str, retry_count: int @@ -123,7 +123,7 @@ class SmartCameraProtocol(SmartProtocol): """ method = request method_type = request[:3] - snake_name = SmartCameraProtocol._make_snake_name(request) + snake_name = SmartCamProtocol._make_snake_name(request) param = snake_name[4:] if ( (short_method := method[:3]) diff --git a/kasa/protocols/smartprotocol.py b/kasa/protocols/smartprotocol.py index d3fd9bfd..80e76ca6 100644 --- a/kasa/protocols/smartprotocol.py +++ b/kasa/protocols/smartprotocol.py @@ -168,7 +168,7 @@ class SmartProtocol(BaseProtocol): ] end = len(multi_requests) - # The SmartCameraProtocol sends requests with a length 1 as a + # The SmartCamProtocol sends requests with a length 1 as a # multipleRequest. The SmartProtocol doesn't so will never # raise_on_error raise_on_error = end == 1 diff --git a/kasa/smartcam/__init__.py b/kasa/smartcam/__init__.py new file mode 100644 index 00000000..574459f4 --- /dev/null +++ b/kasa/smartcam/__init__.py @@ -0,0 +1,5 @@ +"""Package for supporting tapo-branded cameras.""" + +from .smartcamdevice import SmartCamDevice + +__all__ = ["SmartCamDevice"] diff --git a/kasa/smartcamera/modules/__init__.py b/kasa/smartcam/modules/__init__.py similarity index 88% rename from kasa/smartcamera/modules/__init__.py rename to kasa/smartcam/modules/__init__.py index 462241e8..16d59581 100644 --- a/kasa/smartcamera/modules/__init__.py +++ b/kasa/smartcam/modules/__init__.py @@ -1,4 +1,4 @@ -"""Modules for SMARTCAMERA devices.""" +"""Modules for SMARTCAM devices.""" from .alarm import Alarm from .camera import Camera diff --git a/kasa/smartcamera/modules/alarm.py b/kasa/smartcam/modules/alarm.py similarity index 97% rename from kasa/smartcamera/modules/alarm.py rename to kasa/smartcam/modules/alarm.py index bf7ce1a5..12d43464 100644 --- a/kasa/smartcamera/modules/alarm.py +++ b/kasa/smartcam/modules/alarm.py @@ -3,7 +3,7 @@ from __future__ import annotations from ...feature import Feature -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule DURATION_MIN = 0 DURATION_MAX = 6000 @@ -12,11 +12,11 @@ VOLUME_MIN = 0 VOLUME_MAX = 10 -class Alarm(SmartCameraModule): +class Alarm(SmartCamModule): """Implementation of alarm module.""" # Needs a different name to avoid clashing with SmartAlarm - NAME = "SmartCameraAlarm" + NAME = "SmartCamAlarm" REQUIRED_COMPONENT = "siren" QUERY_GETTER_NAME = "getSirenStatus" diff --git a/kasa/smartcamera/modules/camera.py b/kasa/smartcam/modules/camera.py similarity index 97% rename from kasa/smartcamera/modules/camera.py rename to kasa/smartcam/modules/camera.py index 65f434d1..815db62b 100644 --- a/kasa/smartcamera/modules/camera.py +++ b/kasa/smartcam/modules/camera.py @@ -10,14 +10,14 @@ from ...credentials import Credentials from ...device_type import DeviceType from ...feature import Feature from ...json import loads as json_loads -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) LOCAL_STREAMING_PORT = 554 -class Camera(SmartCameraModule): +class Camera(SmartCamModule): """Implementation of device module.""" QUERY_GETTER_NAME = "getLensMaskConfig" diff --git a/kasa/smartcamera/modules/childdevice.py b/kasa/smartcam/modules/childdevice.py similarity index 90% rename from kasa/smartcamera/modules/childdevice.py rename to kasa/smartcam/modules/childdevice.py index 81905fbf..c4de5838 100644 --- a/kasa/smartcamera/modules/childdevice.py +++ b/kasa/smartcam/modules/childdevice.py @@ -1,10 +1,10 @@ """Module for child devices.""" from ...device_type import DeviceType -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule -class ChildDevice(SmartCameraModule): +class ChildDevice(SmartCamModule): """Implementation for child devices.""" REQUIRED_COMPONENT = "childControl" diff --git a/kasa/smartcamera/modules/device.py b/kasa/smartcam/modules/device.py similarity index 92% rename from kasa/smartcamera/modules/device.py rename to kasa/smartcam/modules/device.py index 34474ef2..0541d75c 100644 --- a/kasa/smartcamera/modules/device.py +++ b/kasa/smartcam/modules/device.py @@ -3,10 +3,10 @@ from __future__ import annotations from ...feature import Feature -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule -class DeviceModule(SmartCameraModule): +class DeviceModule(SmartCamModule): """Implementation of device module.""" NAME = "devicemodule" diff --git a/kasa/smartcamera/modules/led.py b/kasa/smartcam/modules/led.py similarity index 88% rename from kasa/smartcamera/modules/led.py rename to kasa/smartcam/modules/led.py index 0443d320..fb62c52d 100644 --- a/kasa/smartcamera/modules/led.py +++ b/kasa/smartcam/modules/led.py @@ -3,10 +3,10 @@ from __future__ import annotations from ...interfaces.led import Led as LedInterface -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule -class Led(SmartCameraModule, LedInterface): +class Led(SmartCamModule, LedInterface): """Implementation of led controls.""" REQUIRED_COMPONENT = "led" diff --git a/kasa/smartcamera/modules/pantilt.py b/kasa/smartcam/modules/pantilt.py similarity index 97% rename from kasa/smartcamera/modules/pantilt.py rename to kasa/smartcam/modules/pantilt.py index d1882927..fb647f6f 100644 --- a/kasa/smartcamera/modules/pantilt.py +++ b/kasa/smartcam/modules/pantilt.py @@ -3,13 +3,13 @@ from __future__ import annotations from ...feature import Feature -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule DEFAULT_PAN_STEP = 30 DEFAULT_TILT_STEP = 10 -class PanTilt(SmartCameraModule): +class PanTilt(SmartCamModule): """Implementation of device_local_time.""" REQUIRED_COMPONENT = "ptz" diff --git a/kasa/smartcamera/modules/time.py b/kasa/smartcam/modules/time.py similarity index 96% rename from kasa/smartcamera/modules/time.py rename to kasa/smartcam/modules/time.py index 6f40aafb..4e5cb8df 100644 --- a/kasa/smartcamera/modules/time.py +++ b/kasa/smartcam/modules/time.py @@ -9,10 +9,10 @@ from zoneinfo import ZoneInfo, ZoneInfoNotFoundError from ...cachedzoneinfo import CachedZoneInfo from ...feature import Feature from ...interfaces import Time as TimeInterface -from ..smartcameramodule import SmartCameraModule +from ..smartcammodule import SmartCamModule -class Time(SmartCameraModule, TimeInterface): +class Time(SmartCamModule, TimeInterface): """Implementation of device_local_time.""" QUERY_GETTER_NAME = "getTimezone" diff --git a/kasa/smartcamera/smartcamera.py b/kasa/smartcam/smartcamdevice.py similarity index 96% rename from kasa/smartcamera/smartcamera.py rename to kasa/smartcam/smartcamdevice.py index 2c09e4dd..4cbf3bbe 100644 --- a/kasa/smartcamera/smartcamera.py +++ b/kasa/smartcam/smartcamdevice.py @@ -1,4 +1,4 @@ -"""Module for smartcamera.""" +"""Module for SmartCamDevice.""" from __future__ import annotations @@ -8,15 +8,15 @@ from typing import Any from ..device import _DeviceInfo from ..device_type import DeviceType from ..module import Module -from ..protocols.smartcameraprotocol import _ChildCameraProtocolWrapper +from ..protocols.smartcamprotocol import _ChildCameraProtocolWrapper from ..smart import SmartChildDevice, SmartDevice from .modules import ChildDevice, DeviceModule -from .smartcameramodule import SmartCameraModule +from .smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) -class SmartCamera(SmartDevice): +class SmartCamDevice(SmartDevice): """Class for smart cameras.""" # Modules that are called as part of the init procedure on first update @@ -41,7 +41,7 @@ class SmartCamera(SmartDevice): basic_info = info["getDeviceInfo"]["device_info"]["basic_info"] short_name = basic_info["device_model"] long_name = discovery_info["device_model"] if discovery_info else short_name - device_type = SmartCamera._get_device_type_from_sysinfo(basic_info) + device_type = SmartCamDevice._get_device_type_from_sysinfo(basic_info) fw_version_full = basic_info["sw_version"] firmware_version, firmware_build = fw_version_full.split(" ", maxsplit=1) return _DeviceInfo( @@ -73,7 +73,7 @@ class SmartCamera(SmartDevice): async def _initialize_smart_child( self, info: dict, child_components: dict ) -> SmartDevice: - """Initialize a smart child device attached to a smartcamera.""" + """Initialize a smart child device attached to a smartcam device.""" child_id = info["device_id"] child_protocol = _ChildCameraProtocolWrapper(child_id, self.protocol) try: @@ -122,7 +122,7 @@ class SmartCamera(SmartDevice): async def _initialize_modules(self) -> None: """Initialize modules based on component negotiation response.""" - for mod in SmartCameraModule.REGISTERED_MODULES.values(): + for mod in SmartCamModule.REGISTERED_MODULES.values(): if ( mod.REQUIRED_COMPONENT and mod.REQUIRED_COMPONENT not in self._components diff --git a/kasa/smartcamera/smartcameramodule.py b/kasa/smartcam/smartcammodule.py similarity index 92% rename from kasa/smartcamera/smartcameramodule.py rename to kasa/smartcam/smartcammodule.py index 4b1bd36e..ca1a3b82 100644 --- a/kasa/smartcamera/smartcameramodule.py +++ b/kasa/smartcam/smartcammodule.py @@ -11,15 +11,15 @@ from ..smart.smartmodule import SmartModule if TYPE_CHECKING: from . import modules - from .smartcamera import SmartCamera + from .smartcamdevice import SmartCamDevice _LOGGER = logging.getLogger(__name__) -class SmartCameraModule(SmartModule): - """Base class for SMARTCAMERA modules.""" +class SmartCamModule(SmartModule): + """Base class for SMARTCAM modules.""" - SmartCameraAlarm: Final[ModuleName[modules.Alarm]] = ModuleName("SmartCameraAlarm") + SmartCamAlarm: Final[ModuleName[modules.Alarm]] = ModuleName("SmartCamAlarm") #: Query to execute during the main update cycle QUERY_GETTER_NAME: str @@ -30,7 +30,7 @@ class SmartCameraModule(SmartModule): REGISTERED_MODULES = {} - _device: SmartCamera + _device: SmartCamDevice def query(self) -> dict: """Query to execute during the update cycle. diff --git a/kasa/smartcamera/__init__.py b/kasa/smartcamera/__init__.py deleted file mode 100644 index 0d6052ea..00000000 --- a/kasa/smartcamera/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Package for supporting tapo-branded cameras.""" - -from .smartcamera import SmartCamera - -__all__ = ["SmartCamera"] diff --git a/tests/device_fixtures.py b/tests/device_fixtures.py index faaec64f..917f1998 100644 --- a/tests/device_fixtures.py +++ b/tests/device_fixtures.py @@ -13,11 +13,11 @@ from kasa import ( ) from kasa.iot import IotBulb, IotDimmer, IotLightStrip, IotPlug, IotStrip, IotWallSwitch from kasa.smart import SmartDevice -from kasa.smartcamera.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice from .fakeprotocol_iot import FakeIotProtocol from .fakeprotocol_smart import FakeSmartProtocol -from .fakeprotocol_smartcamera import FakeSmartCameraProtocol +from .fakeprotocol_smartcam import FakeSmartCamProtocol from .fixtureinfo import ( FIXTURE_DATA, ComponentFilter, @@ -317,16 +317,16 @@ device_smart = parametrize( device_iot = parametrize( "devices iot", model_filter=ALL_DEVICES_IOT, protocol_filter={"IOT"} ) -device_smartcamera = parametrize("devices smartcamera", protocol_filter={"SMARTCAMERA"}) -camera_smartcamera = parametrize( - "camera smartcamera", +device_smartcam = parametrize("devices smartcam", protocol_filter={"SMARTCAM"}) +camera_smartcam = parametrize( + "camera smartcam", device_type_filter=[DeviceType.Camera], - protocol_filter={"SMARTCAMERA"}, + protocol_filter={"SMARTCAM"}, ) -hub_smartcamera = parametrize( - "hub smartcamera", +hub_smartcam = parametrize( + "hub smartcam", device_type_filter=[DeviceType.Hub], - protocol_filter={"SMARTCAMERA"}, + protocol_filter={"SMARTCAM"}, ) @@ -344,8 +344,8 @@ def check_categories(): + hubs_smart.args[1] + sensors_smart.args[1] + thermostats_smart.args[1] - + camera_smartcamera.args[1] - + hub_smartcamera.args[1] + + camera_smartcam.args[1] + + hub_smartcam.args[1] ) diffs: set[FixtureInfo] = set(FIXTURE_DATA) - set(categorized_fixtures) if diffs: @@ -363,8 +363,8 @@ check_categories() def device_for_fixture_name(model, protocol): if protocol in {"SMART", "SMART.CHILD"}: return SmartDevice - elif protocol == "SMARTCAMERA": - return SmartCamera + elif protocol == "SMARTCAM": + return SmartCamDevice else: for d in STRIPS_IOT: if d in model: @@ -420,8 +420,8 @@ async def get_device_for_fixture( d.protocol = FakeSmartProtocol( fixture_data.data, fixture_data.name, verbatim=verbatim ) - elif fixture_data.protocol == "SMARTCAMERA": - d.protocol = FakeSmartCameraProtocol( + elif fixture_data.protocol == "SMARTCAM": + d.protocol = FakeSmartCamProtocol( fixture_data.data, fixture_data.name, verbatim=verbatim ) else: @@ -460,8 +460,8 @@ def get_fixture_info(fixture, protocol): def get_nearest_fixture_to_ip(dev): if isinstance(dev, SmartDevice): protocol_fixtures = filter_fixtures("", protocol_filter={"SMART"}) - elif isinstance(dev, SmartCamera): - protocol_fixtures = filter_fixtures("", protocol_filter={"SMARTCAMERA"}) + elif isinstance(dev, SmartCamDevice): + protocol_fixtures = filter_fixtures("", protocol_filter={"SMARTCAM"}) else: protocol_fixtures = filter_fixtures("", protocol_filter={"IOT"}) assert protocol_fixtures, "Unknown device type" diff --git a/tests/discovery_fixtures.py b/tests/discovery_fixtures.py index f8df4397..15109b3b 100644 --- a/tests/discovery_fixtures.py +++ b/tests/discovery_fixtures.py @@ -11,7 +11,7 @@ from kasa.transports.xortransport import XorEncryption from .fakeprotocol_iot import FakeIotProtocol from .fakeprotocol_smart import FakeSmartProtocol, FakeSmartTransport -from .fakeprotocol_smartcamera import FakeSmartCameraProtocol +from .fakeprotocol_smartcam import FakeSmartCamProtocol from .fixtureinfo import FixtureInfo, filter_fixtures, idgenerator DISCOVERY_MOCK_IP = "127.0.0.123" @@ -194,8 +194,8 @@ def patch_discovery(fixture_infos: dict[str, FixtureInfo], mocker): protos = { ip: FakeSmartProtocol(fixture_info.data, fixture_info.name) if fixture_info.protocol in {"SMART", "SMART.CHILD"} - else FakeSmartCameraProtocol(fixture_info.data, fixture_info.name) - if fixture_info.protocol in {"SMARTCAMERA", "SMARTCAMERA.CHILD"} + else FakeSmartCamProtocol(fixture_info.data, fixture_info.name) + if fixture_info.protocol in {"SMARTCAM", "SMARTCAM.CHILD"} else FakeIotProtocol(fixture_info.data, fixture_info.name) for ip, fixture_info in fixture_infos.items() } @@ -221,8 +221,8 @@ def patch_discovery(fixture_infos: dict[str, FixtureInfo], mocker): protos[host] = ( FakeSmartProtocol(fixture_info.data, fixture_info.name) if fixture_info.protocol in {"SMART", "SMART.CHILD"} - else FakeSmartCameraProtocol(fixture_info.data, fixture_info.name) - if fixture_info.protocol in {"SMARTCAMERA", "SMARTCAMERA.CHILD"} + else FakeSmartCamProtocol(fixture_info.data, fixture_info.name) + if fixture_info.protocol in {"SMARTCAM", "SMARTCAM.CHILD"} else FakeIotProtocol(fixture_info.data, fixture_info.name) ) port = ( diff --git a/tests/fakeprotocol_smartcamera.py b/tests/fakeprotocol_smartcam.py similarity index 97% rename from tests/fakeprotocol_smartcamera.py rename to tests/fakeprotocol_smartcam.py index 4059fbfb..d110e784 100644 --- a/tests/fakeprotocol_smartcamera.py +++ b/tests/fakeprotocol_smartcam.py @@ -5,16 +5,16 @@ from json import loads as json_loads from typing import Any from kasa import Credentials, DeviceConfig, SmartProtocol -from kasa.protocols.smartcameraprotocol import SmartCameraProtocol +from kasa.protocols.smartcamprotocol import SmartCamProtocol from kasa.transports.basetransport import BaseTransport from .fakeprotocol_smart import FakeSmartTransport -class FakeSmartCameraProtocol(SmartCameraProtocol): +class FakeSmartCamProtocol(SmartCamProtocol): def __init__(self, info, fixture_name, *, is_child=False, verbatim=False): super().__init__( - transport=FakeSmartCameraTransport( + transport=FakeSmartCamTransport( info, fixture_name, is_child=is_child, verbatim=verbatim ), ) @@ -25,7 +25,7 @@ class FakeSmartCameraProtocol(SmartCameraProtocol): return resp_dict -class FakeSmartCameraTransport(BaseTransport): +class FakeSmartCamTransport(BaseTransport): def __init__( self, info, diff --git a/tests/fixtureinfo.py b/tests/fixtureinfo.py index cc7a5df4..fc1dd1fb 100644 --- a/tests/fixtureinfo.py +++ b/tests/fixtureinfo.py @@ -13,7 +13,7 @@ import pytest from kasa.device_type import DeviceType from kasa.iot import IotDevice from kasa.smart.smartdevice import SmartDevice -from kasa.smartcamera.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice class FixtureInfo(NamedTuple): @@ -53,10 +53,10 @@ SUPPORTED_SMART_CHILD_DEVICES = [ ) ] -SUPPORTED_SMARTCAMERA_DEVICES = [ - (device, "SMARTCAMERA") +SUPPORTED_SMARTCAM_DEVICES = [ + (device, "SMARTCAM") for device in glob.glob( - os.path.dirname(os.path.abspath(__file__)) + "/fixtures/smartcamera/*.json" + os.path.dirname(os.path.abspath(__file__)) + "/fixtures/smartcam/*.json" ) ] @@ -64,7 +64,7 @@ SUPPORTED_DEVICES = ( SUPPORTED_IOT_DEVICES + SUPPORTED_SMART_DEVICES + SUPPORTED_SMART_CHILD_DEVICES - + SUPPORTED_SMARTCAMERA_DEVICES + + SUPPORTED_SMARTCAM_DEVICES ) @@ -179,14 +179,14 @@ def filter_fixtures( IotDevice._get_device_type_from_sys_info(fixture_data.data) in device_type ) - elif fixture_data.protocol == "SMARTCAMERA": + elif fixture_data.protocol == "SMARTCAM": info = fixture_data.data["getDeviceInfo"]["device_info"]["basic_info"] - return SmartCamera._get_device_type_from_sysinfo(info) in device_type + return SmartCamDevice._get_device_type_from_sysinfo(info) in device_type return False filtered = [] if protocol_filter is None: - protocol_filter = {"IOT", "SMART", "SMARTCAMERA"} + protocol_filter = {"IOT", "SMART", "SMARTCAM"} for fixture_data in fixture_list: if data_root_filter and data_root_filter not in fixture_data.data: continue diff --git a/tests/fixtures/smartcamera/C210(EU)_2.0_1.4.2.json b/tests/fixtures/smartcam/C210(EU)_2.0_1.4.2.json similarity index 100% rename from tests/fixtures/smartcamera/C210(EU)_2.0_1.4.2.json rename to tests/fixtures/smartcam/C210(EU)_2.0_1.4.2.json diff --git a/tests/fixtures/smartcamera/C210(EU)_2.0_1.4.3.json b/tests/fixtures/smartcam/C210(EU)_2.0_1.4.3.json similarity index 100% rename from tests/fixtures/smartcamera/C210(EU)_2.0_1.4.3.json rename to tests/fixtures/smartcam/C210(EU)_2.0_1.4.3.json diff --git a/tests/fixtures/smartcamera/H200(EU)_1.0_1.3.2.json b/tests/fixtures/smartcam/H200(EU)_1.0_1.3.2.json similarity index 100% rename from tests/fixtures/smartcamera/H200(EU)_1.0_1.3.2.json rename to tests/fixtures/smartcam/H200(EU)_1.0_1.3.2.json diff --git a/tests/fixtures/smartcamera/H200(US)_1.0_1.3.6.json b/tests/fixtures/smartcam/H200(US)_1.0_1.3.6.json similarity index 100% rename from tests/fixtures/smartcamera/H200(US)_1.0_1.3.6.json rename to tests/fixtures/smartcam/H200(US)_1.0_1.3.6.json diff --git a/tests/fixtures/smartcamera/TC65_1.0_1.3.9.json b/tests/fixtures/smartcam/TC65_1.0_1.3.9.json similarity index 100% rename from tests/fixtures/smartcamera/TC65_1.0_1.3.9.json rename to tests/fixtures/smartcam/TC65_1.0_1.3.9.json diff --git a/tests/smartcamera/modules/test_alarm.py b/tests/smartcamera/modules/test_alarm.py index 2301a2be..50e0b5b3 100644 --- a/tests/smartcamera/modules/test_alarm.py +++ b/tests/smartcamera/modules/test_alarm.py @@ -5,21 +5,21 @@ from __future__ import annotations import pytest from kasa import Device -from kasa.smartcamera.modules.alarm import ( +from kasa.smartcam.modules.alarm import ( DURATION_MAX, DURATION_MIN, VOLUME_MAX, VOLUME_MIN, ) -from kasa.smartcamera.smartcameramodule import SmartCameraModule +from kasa.smartcam.smartcammodule import SmartCamModule -from ...conftest import hub_smartcamera +from ...conftest import hub_smartcam -@hub_smartcamera +@hub_smartcam async def test_alarm(dev: Device): """Test device alarm.""" - alarm = dev.modules.get(SmartCameraModule.SmartCameraAlarm) + alarm = dev.modules.get(SmartCamModule.SmartCamAlarm) assert alarm original_duration = alarm.alarm_duration @@ -70,10 +70,10 @@ async def test_alarm(dev: Device): await dev.update() -@hub_smartcamera +@hub_smartcam async def test_alarm_invalid_setters(dev: Device): """Test device alarm invalid setter values.""" - alarm = dev.modules.get(SmartCameraModule.SmartCameraAlarm) + alarm = dev.modules.get(SmartCamModule.SmartCamAlarm) assert alarm # test set sound invalid @@ -92,10 +92,10 @@ async def test_alarm_invalid_setters(dev: Device): await alarm.set_alarm_duration(-3) -@hub_smartcamera +@hub_smartcam async def test_alarm_features(dev: Device): """Test device alarm features.""" - alarm = dev.modules.get(SmartCameraModule.SmartCameraAlarm) + alarm = dev.modules.get(SmartCamModule.SmartCamAlarm) assert alarm original_duration = alarm.alarm_duration diff --git a/tests/smartcamera/test_smartcamera.py b/tests/smartcamera/test_smartcamera.py index 6f1d82d3..ccb4fbc1 100644 --- a/tests/smartcamera/test_smartcamera.py +++ b/tests/smartcamera/test_smartcamera.py @@ -12,10 +12,10 @@ from freezegun.api import FrozenDateTimeFactory from kasa import Credentials, Device, DeviceType, Module -from ..conftest import camera_smartcamera, device_smartcamera, hub_smartcamera +from ..conftest import camera_smartcam, device_smartcam, hub_smartcam -@device_smartcamera +@device_smartcam async def test_state(dev: Device): if dev.device_type is DeviceType.Hub: pytest.skip("Hubs cannot be switched on and off") @@ -26,7 +26,7 @@ async def test_state(dev: Device): assert dev.is_on is not state -@camera_smartcamera +@camera_smartcam async def test_stream_rtsp_url(dev: Device): camera_module = dev.modules.get(Module.Camera) assert camera_module @@ -85,7 +85,7 @@ async def test_stream_rtsp_url(dev: Device): assert url is None -@device_smartcamera +@device_smartcam async def test_alias(dev): test_alias = "TEST1234" original = dev.alias @@ -100,7 +100,7 @@ async def test_alias(dev): assert dev.alias == original -@hub_smartcamera +@hub_smartcam async def test_hub(dev): assert dev.children for child in dev.children: @@ -112,7 +112,7 @@ async def test_hub(dev): assert child.time -@device_smartcamera +@device_smartcam async def test_device_time(dev: Device, freezer: FrozenDateTimeFactory): """Test a child device gets the time from it's parent module.""" fallback_time = datetime.now(UTC).astimezone().replace(microsecond=0) diff --git a/tests/test_cli.py b/tests/test_cli.py index a31a9fa6..52f5ff93 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -45,7 +45,7 @@ from kasa.cli.wifi import wifi from kasa.discover import Discover, DiscoveryResult from kasa.iot import IotDevice from kasa.smart import SmartDevice -from kasa.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice from .conftest import ( device_smart, @@ -181,7 +181,7 @@ async def test_state(dev, turn_on, runner): @turn_on async def test_toggle(dev, turn_on, runner): - if isinstance(dev, SmartCamera) and dev.device_type == DeviceType.Hub: + if isinstance(dev, SmartCamDevice) and dev.device_type == DeviceType.Hub: pytest.skip(reason="Hub cannot toggle state") await handle_turn_on(dev, turn_on) @@ -214,7 +214,7 @@ async def test_raw_command(dev, mocker, runner): update = mocker.patch.object(dev, "update") from kasa.smart import SmartDevice - if isinstance(dev, SmartCamera): + if isinstance(dev, SmartCamDevice): params = ["na", "getDeviceInfo"] elif isinstance(dev, SmartDevice): params = ["na", "get_device_info"] @@ -917,7 +917,7 @@ async def test_type_param(device_type, mocker, runner): mocker.patch("kasa.cli.device.state", new=_state) if device_type == "camera": - expected_type = SmartCamera + expected_type = SmartCamDevice elif device_type == "smart": expected_type = SmartDevice else: diff --git a/tests/test_device.py b/tests/test_device.py index e461033d..1d780c32 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -30,7 +30,7 @@ from kasa.iot.iottimezone import ( ) from kasa.iot.modules import IotLightPreset from kasa.smart import SmartChildDevice, SmartDevice -from kasa.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice def _get_subclasses(of_class): @@ -115,7 +115,7 @@ async def test_device_class_repr(device_class_name_obj): IotLightStrip: DeviceType.LightStrip, SmartChildDevice: DeviceType.Unknown, SmartDevice: DeviceType.Unknown, - SmartCamera: DeviceType.Camera, + SmartCamDevice: DeviceType.Camera, } type_ = CLASS_TO_DEFAULT_TYPE[klass] child_repr = ">" diff --git a/tests/test_device_factory.py b/tests/test_device_factory.py index 8f9f635a..a0f501c3 100644 --- a/tests/test_device_factory.py +++ b/tests/test_device_factory.py @@ -20,7 +20,7 @@ from kasa import ( from kasa.device_factory import ( Device, IotDevice, - SmartCamera, + SmartCamDevice, SmartDevice, connect, get_device_class_from_family, @@ -178,8 +178,8 @@ async def test_connect_http_client(discovery_mock, mocker): async def test_device_types(dev: Device): await dev.update() - if isinstance(dev, SmartCamera): - res = SmartCamera._get_device_type_from_sysinfo(dev.sys_info) + if isinstance(dev, SmartCamDevice): + res = SmartCamDevice._get_device_type_from_sysinfo(dev.sys_info) elif isinstance(dev, SmartDevice): assert dev._discovery_info device_type = cast(str, dev._discovery_info["device_type"]) diff --git a/tests/test_devtools.py b/tests/test_devtools.py index fa60acd5..e18243af 100644 --- a/tests/test_devtools.py +++ b/tests/test_devtools.py @@ -6,7 +6,7 @@ from devtools.dump_devinfo import get_legacy_fixture, get_smart_fixtures from kasa.iot import IotDevice from kasa.protocols import IotProtocol from kasa.smart import SmartDevice -from kasa.smartcamera import SmartCamera +from kasa.smartcam import SmartCamDevice from .conftest import ( FixtureInfo, @@ -17,8 +17,8 @@ from .conftest import ( smart_fixtures = parametrize( "smart fixtures", protocol_filter={"SMART"}, fixture_name="fixture_info" ) -smartcamera_fixtures = parametrize( - "smartcamera fixtures", protocol_filter={"SMARTCAMERA"}, fixture_name="fixture_info" +smartcam_fixtures = parametrize( + "smartcam fixtures", protocol_filter={"SMARTCAM"}, fixture_name="fixture_info" ) iot_fixtures = parametrize( "iot fixtures", protocol_filter={"IOT"}, fixture_name="fixture_info" @@ -27,8 +27,8 @@ iot_fixtures = parametrize( async def test_fixture_names(fixture_info: FixtureInfo): """Test that device info gets the right fixture names.""" - if fixture_info.protocol in {"SMARTCAMERA"}: - device_info = SmartCamera._get_device_info( + if fixture_info.protocol in {"SMARTCAM"}: + device_info = SmartCamDevice._get_device_info( fixture_info.data, fixture_info.data.get("discovery_result") ) elif fixture_info.protocol in {"SMART"}: @@ -62,11 +62,11 @@ async def test_smart_fixtures(fixture_info: FixtureInfo): assert fixture_info.data == fixture_result.data -@smartcamera_fixtures -async def test_smartcamera_fixtures(fixture_info: FixtureInfo): - """Test that smartcamera fixtures are created the same.""" +@smartcam_fixtures +async def test_smartcam_fixtures(fixture_info: FixtureInfo): + """Test that smartcam fixtures are created the same.""" dev = await get_device_for_fixture(fixture_info, verbatim=True) - assert isinstance(dev, SmartCamera) + assert isinstance(dev, SmartCamDevice) if dev.children: pytest.skip("Test not currently implemented for devices with children.") fixtures = await get_smart_fixtures(