8000 Rename smartcamera to smartcam by sdb9696 · Pull Request #1300 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Rename smartcamera to smartcam #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions devtools/dump_devinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

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,
Expand All @@ -42,19 +42,19 @@
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/"

Expand All @@ -65,7 +65,7 @@

@dataclasses.dataclass
class SmartCall:
"""Class for smart and smartcamera calls."""
"""Class for smart and smartcam calls."""

module: str
request: dict
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions devtools/generate_supported.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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):
Expand Down Expand Up @@ -48,7 +48,7 @@ class SupportedVersion(NamedTuple):
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):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}},
Expand Down
10 changes: 5 additions & 5 deletions kasa/device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions kasa/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
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__)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for SmartCamera Protocol."""
"""Module for SmartCamProtocol."""

from __future__ import annotations

Expand Down Expand Up @@ -46,8 +46,8 @@
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
Expand Down Expand Up @@ -123,7 +123,7 @@
"""
method = request
method_type = request[:3]
snake_name = SmartCameraProtocol._make_snake_name(request)
snake_name = SmartCamProtocol._make_snake_name(request)

Check warning on line 126 in kasa/protocols/smartcamprotocol.py

View check run for this annotation

Codecov / codecov/patch

kasa/protocols/smartcamprotocol.py#L126

Added line #L126 was not covered by tests
param = snake_name[4:]
if (
(short_method := method[:3])
Expand Down
2 changes: 1 addition & 1 deletion kasa/protocols/smartprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def _execute_multiple_query(self, requests: dict, retry_count: int) -> dic
]

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
Expand Down
5 changes: 5 additions & 0 deletions kasa/smartcam/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Package for supporting tapo-branded cameras."""

from .smartcamdevice import SmartCamDevice

__all__ = ["SmartCamDevice"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Modules for SMARTCAMERA devices."""
"""Modules for SMARTCAM devices."""

from .alarm import Alarm
from .camera import Camera
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,11 +12,11 @@
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions kasa/smartcamera/modules/time.py → kasa/smartcam/modules/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for smartcamera."""
"""Module for SmartCamDevice."""

from __future__ import annotations

Expand All @@ -8,15 +8,15 @@
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
Expand All @@ -41,7 +41,7 @@ def _get_device_info(
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(
Expand Down Expand Up @@ -73,7 +73,7 @@ def _update_children_info(self) -> None:
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:
Expand Down Expand Up @@ -122,7 +122,7 @@ async def _initialize_children(self) -> None:

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
Expand Down
Loading
Loading
0