mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-02-27 21:29:57 +00:00
Add Tapo C460 support (#1645)
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
Stale / stale (push) Has been cancelled
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
Stale / stale (push) Has been cancelled
Changes include: - New smartcam fixture for C460 - Battery module updates to safely handle optional temperature and voltage fields
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from kasa import Device
|
||||
from kasa.smartcam.smartcammodule import SmartCamModule
|
||||
|
||||
@@ -20,14 +22,69 @@ async def test_battery(dev: Device):
|
||||
battery = dev.modules.get(SmartCamModule.SmartCamBattery)
|
||||
assert battery
|
||||
|
||||
feat_ids = {
|
||||
"battery_level",
|
||||
"battery_low",
|
||||
"battery_temperature",
|
||||
"battery_voltage",
|
||||
"battery_charging",
|
||||
}
|
||||
for feat_id in feat_ids:
|
||||
required = {"battery_level", "battery_low", "battery_charging"}
|
||||
optional = {"battery_temperature", "battery_voltage"}
|
||||
|
||||
for feat_id in required:
|
||||
feat = dev.features.get(feat_id)
|
||||
assert feat
|
||||
assert feat.value is not None
|
||||
|
||||
for feat_id in optional:
|
||||
feat = dev.features.get(feat_id)
|
||||
if feat is not None:
|
||||
assert feat.value is not None
|
||||
|
||||
|
||||
@battery_smartcam
|
||||
@pytest.mark.parametrize(
|
||||
("raw", "expected"),
|
||||
[
|
||||
(None, None), # covers: v in (None, "NO") -> return None
|
||||
("NO", None), # covers: v in (None, "NO") -> return None
|
||||
("nonsense", None), # covers: ValueError -> except -> return None
|
||||
("12.3", 12.3), # sanity: happy path
|
||||
],
|
||||
)
|
||||
async def test_battery_temperature_edge_cases(dev: Device, raw, expected):
|
||||
battery = dev.modules.get(SmartCamModule.SmartCamBattery)
|
||||
assert battery
|
||||
|
||||
dev.sys_info["battery_temperature"] = raw
|
||||
assert battery.battery_temperature == expected
|
||||
|
||||
|
||||
@battery_smartcam
|
||||
@pytest.mark.parametrize(
|
||||
("voltage_raw", "expected_v"),
|
||||
[
|
||||
(None, None), # covers: battery_voltage -> return None
|
||||
("NO", None), # covers: battery_voltage -> return None
|
||||
("12000", 12.0), # sanity: parses string -> float(...) / 1000
|
||||
],
|
||||
)
|
||||
async def test_battery_voltage_edge_cases(dev: Device, voltage_raw, expected_v):
|
||||
battery = dev.modules.get(SmartCamModule.SmartCamBattery)
|
||||
assert battery
|
||||
|
||||
dev.sys_info["battery_voltage"] = voltage_raw
|
||||
assert battery.battery_voltage == expected_v
|
||||
|
||||
|
||||
@battery_smartcam
|
||||
@pytest.mark.parametrize(
|
||||
("charging_raw", "expected"),
|
||||
[
|
||||
(True, True), # covers: isinstance(v, bool) -> return v
|
||||
(False, False), # covers: isinstance(v, bool) -> return v
|
||||
(None, False), # covers: v is None -> return False
|
||||
("yes", True), # sanity: string normalization path
|
||||
("NO", False), # sanity: string normalization path
|
||||
],
|
||||
)
|
||||
async def test_battery_charging_edge_cases(dev: Device, charging_raw, expected):
|
||||
battery = dev.modules.get(SmartCamModule.SmartCamBattery)
|
||||
assert battery
|
||||
|
||||
dev.sys_info["battery_charging"] = charging_raw
|
||||
assert battery.battery_charging is expected
|
||||
|
||||
Reference in New Issue
Block a user