mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add KP125M fixture and allow passing credentials for tests (#567)
* Add KP125M fixture. Enable tapo auth in pytest. * authentication is not just for tapo * Use "##MASKEDNAME##" base64 for nickname and ssid. --------- Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
parent
bd23d61687
commit
be289a5751
@ -95,6 +95,7 @@ PLUGS = {
|
||||
"KP105",
|
||||
"KP115",
|
||||
"KP125",
|
||||
"KP125M",
|
||||
"KP401",
|
||||
"KS200M",
|
||||
}
|
||||
@ -103,11 +104,11 @@ STRIPS = {"HS107", "HS300", "KP303", "KP200", "KP400", "EP40"}
|
||||
DIMMERS = {"ES20M", "HS220", "KS220M", "KS230", "KP405"}
|
||||
|
||||
DIMMABLE = {*BULBS, *DIMMERS}
|
||||
WITH_EMETER = {"HS110", "HS300", "KP115", "KP125", *BULBS}
|
||||
WITH_EMETER = {"HS110", "HS300", "KP115", "KP125", "KP125M", *BULBS}
|
||||
|
||||
ALL_DEVICES_IOT = BULBS.union(PLUGS).union(STRIPS).union(DIMMERS)
|
||||
|
||||
PLUGS_SMART = {"P110"}
|
||||
PLUGS_SMART = {"P110", "KP125M"}
|
||||
ALL_DEVICES_SMART = BULBS_SMART.union(PLUGS_SMART)
|
||||
|
||||
ALL_DEVICES = ALL_DEVICES_IOT.union(ALL_DEVICES_SMART)
|
||||
@ -297,8 +298,12 @@ async def _update_and_close(d):
|
||||
return d
|
||||
|
||||
|
||||
async def _discover_update_and_close(ip):
|
||||
d = await Discover.discover_single(ip, timeout=10)
|
||||
async def _discover_update_and_close(ip, username, password):
|
||||
if username and password:
|
||||
credentials = Credentials(username=username, password=password)
|
||||
else:
|
||||
credentials = None
|
||||
d = await Discover.discover_single(ip, timeout=10, credentials=credentials)
|
||||
return await _update_and_close(d)
|
||||
|
||||
|
||||
@ -339,15 +344,17 @@ async def dev(request):
|
||||
file, protocol = request.param
|
||||
|
||||
ip = request.config.getoption("--ip")
|
||||
username = request.config.getoption("--username")
|
||||
password = request.config.getoption("--password")
|
||||
if ip:
|
||||
model = IP_MODEL_CACHE.get(ip)
|
||||
d = None
|
||||
if not model:
|
||||
d = await _discover_update_and_close(ip)
|
||||
d = await _discover_update_and_close(ip, username, password)
|
||||
IP_MODEL_CACHE[ip] = model = d.model
|
||||
if model not in file:
|
||||
pytest.skip(f"skipping file {file}")
|
||||
return d if d else await _discover_update_and_close(ip)
|
||||
return d if d else await _discover_update_and_close(ip, username, password)
|
||||
|
||||
return await get_device_for_file(file, protocol)
|
||||
|
||||
@ -411,6 +418,12 @@ def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--ip", action="store", default=None, help="run against device on given ip"
|
||||
)
|
||||
parser.addoption(
|
||||
"--username", action="store", default=None, help="authentication username"
|
||||
)
|
||||
parser.addoption(
|
||||
"--password", action="store", default=None, help="authentication password"
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
|
175
kasa/tests/fixtures/smart/KP125M(US)_1.0_1.1.3.json
vendored
Normal file
175
kasa/tests/fixtures/smart/KP125M(US)_1.0_1.1.3.json
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
{
|
||||
"component_nego": {
|
||||
"component_list": [
|
||||
{
|
||||
"id": "device",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "firmware",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "quick_setup",
|
||||
"ver_code": 3
|
||||
},
|
||||
{
|
||||
"id": "time",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "wireless",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "schedule",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "countdown",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "antitheft",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "account",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "synchronize",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "sunrise_sunset",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "led",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "cloud_connect",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "iot_cloud",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "device_local_time",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "default_states",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "auto_off",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "energy_monitoring",
|
||||
"ver_code": 2
|
||||
},
|
||||
{
|
||||
"id": "power_protection",
|
||||
"ver_code": 1
|
||||
},
|
||||
{
|
||||
"id": "matter",
|
||||
"ver_code": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
"discovery_result": {
|
||||
"device_id": "00000000000000000000000000000000",
|
||||
"device_model": "KP125M(US)",
|
||||
"device_type": "SMART.KASAPLUG",
|
||||
"factory_default": false,
|
||||
"ip": "127.0.0.123",
|
||||
"is_support_iot_cloud": true,
|
||||
"mac": "00-00-00-00-00-00",
|
||||
"mgt_encrypt_schm": {
|
||||
"encrypt_type": "AES",
|
||||
"http_port": 80,
|
||||
"is_support_https": false,
|
||||
"lv": 2
|
||||
},
|
||||
"obd_src": "tplink",
|
||||
"owner": "00000000000000000000000000000000"
|
||||
},
|
||||
"get_current_power": {
|
||||
"current_power": 17
|
||||
},
|
||||
"get_device_info": {
|
||||
"auto_off_remain_time": 0,
|
||||
"auto_off_status": "off",
|
||||
"avatar": "coffee_maker",
|
||||
"default_states": {
|
||||
"state": {},
|
||||
"type": "last_states"
|
||||
},
|
||||
"device_id": "0000000000000000000000000000000000000000",
|
||||
"device_on": true,
|
||||
"fw_id": "00000000000000000000000000000000",
|
||||
"fw_ver": "1.1.3 Build 230801 Rel.092557",
|
||||
"has_set_location_info": true,
|
||||
"hw_id": "00000000000000000000000000000000",
|
||||
"hw_ver": "1.0",
|
||||
"ip": "127.0.0.123",
|
||||
"lang": "en_US",
|
||||
"latitude": 0,
|
||||
"longitude": 0,
|
||||
"mac": "00-00-00-00-00-00",
|
||||
"model": "KP125M",
|
||||
"nickname": "IyNNQVNLRUROQU1FIyM=",
|
||||
"oem_id": "00000000000000000000000000000000",
|
||||
"on_time": 5332,
|
||||
"overheated": false,
|
||||
"power_protection_status": "normal",
|
||||
"region": "America/Chicago",
|
||||
"rssi": -62,
|
||||
"signal_level": 2,
|
||||
"specs": "",
|
||||
"ssid": "IyNNQVNLRUROQU1FIyM=",
|
||||
"time_diff": -360,
|
||||
"type": "SMART.KASAPLUG"
|
||||
},
|
||||
"get_device_time": {
|
||||
"region": "America/Chicago",
|
||||
"time_diff": -360,
|
||||
"timestamp": 1701569348
|
||||
},
|
||||
"get_device_usage": {
|
||||
"power_usage": {
|
||||
"past30": 6757,
|
||||
"past7": 4101,
|
||||
"today": 513
|
||||
},
|
||||
"saved_power": {
|
||||
"past30": 9516,
|
||||
"past7": 5748,
|
||||
"today": 696
|
||||
},
|
||||
"time_usage": {
|
||||
"past30": 16273,
|
||||
"past7": 9849,
|
||||
"today": 1209
|
||||
}
|
||||
},
|
||||
"get_energy_usage": {
|
||||
"current_power": 17654,
|
||||
"electricity_charge": [
|
||||
0,
|
||||
64,
|
||||
111
|
||||
],
|
||||
"local_time": "2023-12-02 20:09:08",
|
||||
"month_energy": 1020,
|
||||
"month_runtime": 2649,
|
||||
"today_energy": 513,
|
||||
"today_runtime": 1209
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user