FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Feature/dlklap transport by tedholtz · Pull Request #1729 · python-kasa/python-kasa · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .json  (1) .lock  (1) .md  (2) .py  (13) .toml  (1) dotfile  (1) All 6 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ venv

/build
docs/build

# MacOS
.DS_Store
1 change: 1 addition & 0 deletions README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ The following devices have been tested and confirmed as working. If your device
- **Cameras**: C100, C101, C110, C210, C220, C225, C325WB, C460, C520WS, C720, TC40, TC65, TC70
- **Doorbells and chimes**: D100C, D130, D230
- **Vacuums**: RV20 Max Plus, RV30 Max
- **Locks**: DL100
- **Hubs**: H100, H200
- **Hub-Connected Devices[^3]**: S200B, S200D, T100, T110, T300, T310, T315

Expand Down
5 changes: 5 additions & 0 deletions SUPPORTED.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ All Tapo devices require authentication.<br>Hub-Connected Devices may work acros
- **RV30 Max**
- Hardware: 1.0 (US) / Firmware: 1.2.0

### Locks

- **DL100**
- Hardware: 1.0 (US) / Firmware: 1.0.17

### Hubs

- **H100**
Expand Down
1 change: 1 addition & 0 deletions devtools/generate_supported.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SupportedVersion(NamedTuple):
DeviceType.Doorbell: "Doorbells and chimes",
DeviceType.Chime: "Doorbells and chimes",
DeviceType.Vacuum: "Vacuums",
DeviceType.Lock: "Locks",
DeviceType.Hub: "Hubs",
DeviceType.Sensor: "Hub-Connected Devices",
DeviceType.Thermostat: "Hub-Connected Devices",
Expand Down
2 changes: 2 additions & 0 deletions kasa/device_factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .transports import (
AesTransport,
BaseTransport,
DlklapTransport,
KlapTransport,
KlapTransportV2,
LinkieTransportV2,
Expand Down Expand Up @@ -232,6 +233,7 @@ def get_protocol(config: DeviceConfig, *, strict: bool = False) -> BaseProtocol
"SMART.AES": (SmartProtocol, AesTransport),
"SMART.KLAP": (SmartProtocol, KlapTransportV2),
"SMART.KLAP.HTTPS": (SmartProtocol, KlapTransportV2),
"SMART.DLKLAP": (SmartProtocol, DlklapTransport),
# H200 is device family SMART.TAPOHUB and uses SmartCamProtocol so use
# https to distuingish from SmartProtocol devices
"SMART.AES.HTTPS": (SmartCamProtocol, SslAesTransport),
Expand Down
1 change: 1 addition & 0 deletions kasa/device_type.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DeviceType(Enum):
Vacuum = "vacuum"
Chime = "chime"
Doorbell = "doorbell"
Lock = "lock"
Unknown = "unknown"

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions kasa/deviceconfig.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DeviceEncryptionType(Enum):
Klap = "KLAP"
Aes = "AES"
Xor = "XOR"
Dlklap = "DLKLAP"


class DeviceFamily(Enum):
Expand All @@ -81,6 +82,7 @@ class DeviceFamily(Enum):
SmartTapoRobovac = "SMART.TAPOROBOVAC"
SmartTapoChime = "SMART.TAPOCHIME"
SmartTapoDoorbell = "SMART.TAPODOORBELL"
SmartTapoLock = "SMART.TAPOLOCK"


class _DeviceConfigBaseMixin(DataClassJSONMixin):
Expand Down
2 changes: 2 additions & 0 deletions kasa/module.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from .device import Device
from .iot import modules as iot
from .smart import modules as smart
from .smart.modules import Lock
from .smartcam import modules as smartcam

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -140,6 +141,7 @@ class Module(ABC):
LightTransition: Final[ModuleName[smart.LightTransition]] = ModuleName(
"LightTransition"
)
Lock: Final[ModuleName[Lock]] = ModuleName("Lock")
MotionSensor: Final[ModuleName[smart.MotionSensor]] = ModuleName("MotionSensor")
ReportMode: Final[ModuleName[smart.ReportMode]] = ModuleName("ReportMode")
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = ModuleName(
Expand Down
2 changes: 2 additions & 0 deletions kasa/smart/modules/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .lightpreset import LightPreset
from .lightstripeffect import LightStripEffect
from .lighttransition import LightTransition
from .lock import Lock
from .matter import Matter
from .mop import Mop
from .motionsensor import MotionSensor
Expand All @@ -45,6 +46,7 @@
from .waterleaksensor import WaterleakSensor

__all__ = [
"Lock",
"Alarm",
"Time",
"Energy",
Expand Down
114 changes: 114 additions & 0 deletions kasa/smart/modules/lock.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""Implementation of lock module for TP-Link DL100 smart locks."""

from __future__ import annotations

import logging

from ...feature import Feature
from ..smartmodule import SmartModule

_LOGGER = logging.getLogger(__name__)

# lock_status polarity is device-verified and counterintuitive:
# 0 == bolt extended == LOCKED
# 1 == bolt retracted == UNLOCKED
# 2 UNINITIALIZED, 3 JAM_IN_UNLOCKING, 4 JAM_IN_LOCKING
LOCK_STATUS_LOCKED = 0
LOCK_STATUS_UNLOCKED = 1


class Lock(SmartModule):
"""Implementation of lock module for SMART.TAPOLOCK devices (DL100)."""

# No component list is exposed by the DL100; depend on the sysinfo key.
REQUIRED_COMPONENT = None
SYSINFO_LOOKUP_KEYS = ["lock_status"]

# Owner (local) path always uses this synthetic user id. Do NOT send
# tplink_account / access_info / lock_type / unlock_type for the owner.
SA_USER_ID = "local_1"

def _initialize_features(self) -> None:
"""Initialize features after the initial update."""
self._add_feature(
Feature(
self._device,
id="is_locked",
name="Locked",
container=self,
attribute_getter="is_locked",
icon="mdi:lock",
category=Feature.Category.Primary,
type=Feature.Type.BinarySensor,
)
)
# The DL100 reports battery in getDeviceInfo but does NOT advertise the
# "battery_detect" component, so the generic BatterySensor module never
# loads for it. Expose battery here instead, mirroring BatterySensor's
# feature ids so downstream consumers (e.g. Home Assistant) stay
# consistent.
if "battery_percentage" in self._device.sys_info:
self._add_feature(
Feature(
self._device,
id="battery_level",
name="Battery level",
container=self,
attribute_getter="battery",
icon="mdi:battery",
unit_getter=lambda: "%",
category=Feature.Category.Info,
type=Feature.Type.Sensor,
)
)
if "at_low_battery" in self._device.sys_info:
self._add_feature(
Feature(
self._device,
id="battery_low",
name="Battery low",
container=self,
attribute_getter="battery_low",
icon="mdi:alert",
category=Feature.Category.Debug,
type=Feature.Type.BinarySensor,
)
)

def query(self) -> dict:
"""Query to execute during the update cycle."""
return {}

@property
def is_locked(self) -> bool:
"""Return True when the bolt is extended (lock_status == 0)."""
return self._device.sys_info["lock_status"] == LOCK_STATUS_LOCKED

@property
def battery(self) -> int:
"""Return the battery level percentage."""
return self._device.sys_info["battery_percentage"]

@property
def battery_low(self) -> bool:
"""Return True if the battery is low."""
return bool(self._device.sys_info["at_low_battery"])

async def lock(self) -> dict:
"""Lock the device (extend the bolt)."""
return await self._set_lock_status(LOCK_STATUS_LOCKED)

async def unlock(self) -> dict:
"""Unlock the device (retract the bolt)."""
return await self._set_lock_status(LOCK_STATUS_UNLOCKED)

async def _set_lock_status(self, status: int) -> dict:
"""Send setLockStatus for the owner (local) path.

SmartProtocol wraps this into the multipleRequest envelope the device
expects, so we only supply the method name and params here.
"""
return await self.call(
"setLockStatus",
{"lock_status": status, "sa_user_id": self.SA_USER_ID},
)
2 changes: 2 additions & 0 deletions kasa/smart/smartdevice.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ def _get_device_type_from_components(
return DeviceType.Vacuum
if "TAPOCHIME" in device_type:
return DeviceType.Chime
if "TAPOLOCK" in device_type:
return DeviceType.Lock
_LOGGER.warning("Unknown device type, falling back to plug")
return DeviceType.Plug

Expand Down
2 changes: 2 additions & 0 deletions kasa/transports/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .aestransport import AesEncyptionSession, AesTransport
from .basetransport import BaseTransport
from .dlklaptransport import DlklapTransport
from .klaptransport import KlapTransport, KlapTransportV2
from .linkietransport import LinkieTransportV2
from .sslaestransport import SslAesTransport
Expand All @@ -14,6 +15,7 @@
"SslTransport",
"SslAesTransport",
"BaseTransport",
"DlklapTransport",
"KlapTransport",
"KlapTransportV2",
"LinkieTransportV2",
Expand Down
Loading

Back | FazBrowse Home | New Git URL