8000 Add smartcamera devices to supported docs (#1257) · ryenitcher/python-kasa@5fe75ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fe75ca

Browse files
authored
Add smartcamera devices to supported docs (python-kasa#1257)
The library now officially supports H200, C200 and TC65
1 parent b8f6651 commit 5fe75ca

File tree

6 files changed

+89
-10
lines changed

6 files changed

+89
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ The following devices have been tested and confirmed as working. If your device
197197
- **Wall Switches**: S500D, S505, S505D
198198
- **Bulbs**: L510B, L510E, L530E, L630
199199
- **Light Strips**: L900-10, L900-5, L920-5, L930-5
200-
- **Hubs**: H100
200+
- **Cameras**: C210, TC65
201+
- **Hubs**: H100, H200
201202
- **Hub-Connected Devices<sup>\*\*\*</sup>**: S200B, S200D, T100, T110, T300, T310, T315
202203

203204
<!--SUPPORTED_END-->

SUPPORTED.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,23 @@ All Tapo devices require authentication.<br>Hub-Connected Devices may work acros
246246
- **L930-5**
247247
- Hardware: 1.0 (US) / Firmware: 1.1.2
248248

249+
### Cameras
250+
251+
- **C210**
252+
- Hardware: 2.0 (EU) / Firmware: 1.4.2
253+
- Hardware: 2.0 (EU) / Firmware: 1.4.3
254+
- **TC65**
255+
- Hardware: 1.0 / Firmware: 1.3.9
256+
249257
### Hubs
250258

251259
- **H100**
252260
- Hardware: 1.0 (EU) / Firmware: 1.2.3
253261
- Hardware: 1.0 (EU) / Firmware: 1.5.10
254262
- Hardware: 1.0 (EU) / Firmware: 1.5.5
263+
- **H200**
264+
- Hardware: 1.0 (EU) / Firmware: 1.3.2
265+
- Hardware: 1.0 (US) / Firmware: 1.3.6
255266

256267
### Hub-Connected Devices
257268

devtools/dump_devinfo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
)
4747
from kasa.protocols.smartprotocol import SmartProtocol, _ChildProtocolWrapper
4848
from kasa.smart import SmartChildDevice
49+
from kasa.smartcamera import SmartCamera
4950

5051
Call = namedtuple("Call", "module method")
5152
FixtureResult = namedtuple("FixtureResult", "filename, folder, data")
@@ -973,14 +974,12 @@ async def get_smart_fixtures(
973974
copy_folder = SMART_FOLDER
974975
else:
975976
# smart camera protocol
976-
basic_info = final["getDeviceInfo"]["device_info"]["basic_info"]
977-
hw_version = basic_info["hw_version"]
978-
sw_version = basic_info["sw_version"]
979-
model = basic_info["device_model"]
980-
region = basic_info.get("region")
981-
sw_version = sw_version.split(" ", maxsplit=1)[0]
982-
if region is not None:
983-
model = f"{model}({region})"
977+
model_info = SmartCamera._get_device_info(final, discovery_info)
978+
model = model_info.long_name
979+
hw_version = model_info.hardware_version
980+
sw_version = model_info.firmare_version
981+
if model_info.region is not None:
982+
model = f"{model}({model_info.region})"
984983
copy_folder = SMARTCAMERA_FOLDER
985984

986985
save_filename = f"{model}_{hw_version}_{sw_version}.json"

devtools/generate_supported.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
from kasa.device_factory import _get_device_type_from_sys_info
1212
from kasa.device_type import DeviceType
13-
from kasa.smart.smartdevice import SmartDevice
13+
from kasa.smart import SmartDevice
14+
from kasa.smartcamera import SmartCamera
1415

1516

1617
class SupportedVersion(NamedTuple):
@@ -32,6 +33,7 @@ class SupportedVersion(NamedTuple):
3233
DeviceType.Fan: "Wall Switches",
3334
DeviceType.Bulb: "Bulbs",
3435
DeviceType.LightStrip: "Light Strips",
36+
DeviceType.Camera: "Cameras",
3537
DeviceType.Hub: "Hubs",
3638
DeviceType.Sensor: "Hub-Connected Devices",
3739
DeviceType.Thermostat: "Hub-Connected Devices",
@@ -43,6 +45,7 @@ class SupportedVersion(NamedTuple):
4345

4446
IOT_FOLDER = "tests/fixtures/"
4547
SMART_FOLDER = "tests/fixtures/smart/"
48+
SMARTCAMERA_FOLDER = "tests/fixtures/smartcamera/"
4649

4750

4851
def generate_supported(args):
@@ -58,6 +61,7 @@ def generate_supported(args):
5861

5962
_get_iot_supported(supported)
6063
_get_smart_supported(supported)
64+
_get_smartcamera_supported(supported)
6165

6266
readme_updated = _update_supported_file(
6367
README_FILENAME, _supported_summary(supported), print_diffs
@@ -234,6 +238,29 @@ def _get_smart_supported(supported):
234238
)
235239

236240

241+
def _get_smartcamera_supported(supported):
242+
for file in Path(SMARTCAMERA_FOLDER).glob("**/*.json"):
243+
with file.open() as f:
244+
fixture_data = json.load(f)
245+
246+
model_info = SmartCamera._get_device_info(
247+
fixture_data, fixture_data.get("discovery_result")
248+
)
249+
250+
supported_type = DEVICE_TYPE_TO_PRODUCT_GROUP[model_info.device_type]
251+
252+
stype = supported[model_info.brand].setdefault(supported_type, {})
253+
smodel = stype.setdefault(model_info.long_name, [])
254+
smodel.append(
255+
SupportedVersion(
256+
region=model_info.region,
257+
hw=model_info.hardware_version,
258+
fw=model_info.firmare_version,
259+
auth=model_info.requires_auth,
260+
)
261+
)
262+
263+
237264
def _get_iot_supported(supported):
238265
for file in Path(IOT_FOLDER).glob("*.json"):
239266
with file.open() as f:

kasa/device.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ class WifiNetwork:
152152
_LOGGER = logging.getLogger(__name__)
153153

154154

155+
@dataclass
156+
class _DeviceInfo:
157+
"""Device Model Information."""
158+
159+
short_name: str
160+
long_name: str
161+
brand: str
162+
device_family: str
163+
device_type: DeviceType
164+
hardware_version: str
165+
firmare_version: str
166+
firmware_build: str
167+
requires_auth: bool
168+
region: str | None
169+
170+
155171
class Device(ABC):
156172
"""Common device interface.
157173

kasa/smartcamera/smartcamera.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
from typing import Any
77

8+
from ..device import _DeviceInfo
89
from ..device_type import DeviceType
910
from ..module import Module
1011
from ..protocols.smartcameraprotocol import _ChildCameraProtocolWrapper
@@ -29,6 +30,30 @@ def _get_device_type_from_sysinfo(sysinfo: dict[str, Any]) -> DeviceType:
2930
return DeviceType.Hub
3031
return DeviceType.Camera
3132

33+
@staticmethod
34+
def _get_device_info(
35+
info: dict[str, Any], discovery_info: dict[str, Any] | None
36+
) -> _DeviceInfo:
37+
"""Get model information for a device."""
38+
basic_info = info["getDeviceInfo"]["device_info"]["basic_info"]
39+
short_name = basic_info["device_model"]
40+
long_name = discovery_info["device_model"] if discovery_info else short_name
41+
device_type = SmartCamera._get_device_type_from_sysinfo(basic_info)
42+
fw_version_full = basic_info["sw_version"]
43+
firmare_version, firmware_build = fw_version_full.split(" ", maxsplit=1)
44+
return _DeviceInfo(
45+
short_name=basic_info["device_model"],
46+
long_name=long_name,
47+
brand="tapo",
48+
device_family=basic_info["device_type"],
49+
device_type=device_type,
50+
hardware_version=basic_info["hw_version"],
51+
firmare_version=firmare_version,
52+
firmware_build=firmware_build,
53+
requires_auth=True,
54+
region=basic_info.get("region"),
55+
)
56+
3257
def _update_internal_info(self, info_resp: dict) -> None:
3358
"""Update the internal device info."""
3459
info = self._try_get_response(info_resp, "getDeviceInfo")

0 commit comments

Comments
 (0)
0