Skip to content
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
83 changes: 74 additions & 9 deletions tests/test_device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class TestGetDevices(object):
async def test_gets_devices(self, client):
device_list = await client.get_devices()
assert device_list is not None
# 5 devices but the 5th one has 6 children
assert len(device_list) == 11
# 9 devices: HS103, HS105, HS110, HS300 (6 children), KL430,
# HS200, KP200 (2 children), KP400 (2 children), KL420L5
# Total: 9 parents + 6 + 2 + 2 children = 19
assert len(device_list) == 19

@pytest.mark.usefixtures('client')
class TestFindDevice(object):
Expand Down Expand Up @@ -58,7 +60,6 @@ async def test_finds_hs103_us_device(self, client):
assert device.device_info.is_same_region is True
assert device.device_info.status == 1
assert device.child_id is None
# We can cheat a little with knowledge that this is an enum
assert device.model_type is not None
assert device.model_type.name == 'HS103'

Expand Down Expand Up @@ -89,7 +90,6 @@ async def test_finds_hs105_us_device(self, client):
assert device.device_info.is_same_region is True
assert device.device_info.status == 1
assert device.child_id is None
# We can cheat a little with knowledge that this is an enum
assert device.model_type is not None
assert device.model_type.name == 'HS105'

Expand Down Expand Up @@ -120,7 +120,6 @@ async def test_finds_hs110_us_device(self, client):
assert device.device_info.is_same_region is True
assert device.device_info.status == 1
assert device.child_id is None
# We can cheat a little with knowledge that this is an enum
assert device.model_type is not None
assert device.model_type.name == 'HS110'

Expand Down Expand Up @@ -151,12 +150,11 @@ async def test_finds_hs300_us_device(self, client):
assert device.device_info.is_same_region is True
assert device.device_info.status == 1
assert device.child_id is None
# We can cheat a little with knowledge that this is an enum
assert device.model_type is not None
assert device.model_type.name == 'HS300'

@pytest.mark.asyncio
async def test_finds_unknown_us_device(self, client):
async def test_finds_kl430_us_device(self, client):
device_name = 'Test Strip'
device_id = '140BED90F6EF82191649329403A40C66528411D2'
device = await client.find_device(device_name)
Expand All @@ -182,9 +180,76 @@ async def test_finds_unknown_us_device(self, client):
assert device.device_info.is_same_region is True
assert device.device_info.status == 1
assert device.child_id is None
# We can cheat a little with knowledge that this is an enum
assert device.model_type is not None
assert device.model_type.name == 'UNKNOWN'
assert device.model_type.name == 'KL430'

@pytest.mark.asyncio
async def test_finds_hs200_us_device(self, client):
device_name = 'Kitchen Light Switch'
device_id = 'A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4A1B20001'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.device_id == device_id
assert device.device_info.device_model == 'HS200(US)'
assert device.model_type.name == 'HS200'

@pytest.mark.asyncio
async def test_finds_kp200_us_device(self, client):
device_name = 'Front Porch Plug'
device_id = 'B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5B2C30002'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.device_id == device_id
assert device.device_info.device_model == 'KP200(US)'
assert device.model_type.name == 'KP200'
assert device.has_children() is True

@pytest.mark.asyncio
async def test_finds_kp200_child_device(self, client):
device_name = 'Porch Light'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.model_type.name == 'KP200CHILD'

@pytest.mark.asyncio
async def test_finds_kp400_us_device(self, client):
device_name = 'Backyard Plug'
device_id = 'C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6C3D40003'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.device_id == device_id
assert device.device_info.device_model == 'KP400(US)'
assert device.model_type.name == 'KP400'
assert device.has_children() is True

@pytest.mark.asyncio
async def test_finds_kp400_child_device(self, client):
device_name = 'Garden Lights'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.model_type.name == 'KP400CHILD'

@pytest.mark.asyncio
async def test_finds_kl420l5_us_device(self, client):
device_name = 'Living Room Strip'
device_id = 'D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6A1D4E50004'
device = await client.find_device(device_name)

assert device is not None
assert device.get_alias() == device_name
assert device.device_id == device_id
assert device.device_info.device_model == 'KL420L5(US)'
assert device.model_type.name == 'KL420L5'


@pytest.mark.usefixtures('client')
Expand Down
72 changes: 72 additions & 0 deletions tests/wiremock/__files/get_device_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,78 @@
"fwId": "00000000000000000000000000000000",
"isSameRegion": true,
"status": 1
},
{
"deviceType": "IOT.SMARTPLUGSWITCH",
"role": 0,
"fwVer": "1.0.10 Build 210121 Rel.084339",
"appServerUrl": "http://127.0.0.1:8080",
"deviceRegion": "us-east-1",
"deviceId": "A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4A1B20001",
"deviceName": "Smart Wi-Fi Light Switch",
"deviceHwVer": "3.0",
"alias": "Kitchen Light Switch",
"deviceMac": "AABBCCDDEEE1",
"oemId": "ABCD1234EFGH5678ABCD1234EFGH5678",
"deviceModel": "HS200(US)",
"hwId": "1234ABCD5678EFGH1234ABCD5678EFGH",
"fwId": "00000000000000000000000000000000",
"isSameRegion": true,
"status": 1
},
{
"deviceType": "IOT.SMARTPLUGSWITCH",
"role": 0,
"fwVer": "1.0.3 Build 210121 Rel.084339",
"appServerUrl": "http://127.0.0.1:8080",
"deviceRegion": "us-east-1",
"deviceId": "B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5B2C30002",
"deviceName": "Smart Wi-Fi Outdoor Plug",
"deviceHwVer": "1.0",
"alias": "Front Porch Plug",
"deviceMac": "AABBCCDDEEE2",
"oemId": "ABCD1234KP200001ABCD1234KP200001",
"deviceModel": "KP200(US)",
"hwId": "1234ABCDKP200001ABCD1234KP200001",
"fwId": "00000000000000000000000000000000",
"isSameRegion": true,
"status": 1
},
{
"deviceType": "IOT.SMARTPLUGSWITCH",
"role": 0,
"fwVer": "1.0.5 Build 210121 Rel.084339",
"appServerUrl": "http://127.0.0.1:8080",
"deviceRegion": "us-east-1",
"deviceId": "C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6C3D40003",
"deviceName": "Smart Wi-Fi Outdoor Plug",
"deviceHwVer": "1.0",
"alias": "Backyard Plug",
"deviceMac": "AABBCCDDEEE3",
"oemId": "ABCD1234KP400001ABCD1234KP400001",
"deviceModel": "KP400(US)",
"hwId": "1234ABCDKP400001ABCD1234KP400001",
"fwId": "00000000000000000000000000000000",
"isSameRegion": true,
"status": 1
},
{
"deviceType": "IOT.SMARTBULB",
"role": 0,
"fwVer": "1.0.11 Build 210929 Rel.084339",
"appServerUrl": "http://127.0.0.1:8080",
"deviceRegion": "us-east-1",
"deviceId": "D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6A1D4E50004",
"deviceName": "Kasa Smart LED Light Strip",
"deviceHwVer": "1.0",
"alias": "Living Room Strip",
"deviceMac": "AABBCCDDEEE4",
"oemId": "ABCD1234KL420001ABCD1234KL420001",
"deviceModel": "KL420L5(US)",
"hwId": "1234ABCDKL420001ABCD1234KL420001",
"fwId": "00000000000000000000000000000000",
"isSameRegion": true,
"status": 1
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions tests/wiremock/__files/hs200_us_get_sys_info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error_code": 0,
"result": {
"responseData": "{\"system\": {\"get_sysinfo\": {\"sw_ver\": \"1.0.10 Build 210121 Rel.084339\", \"hw_ver\": \"3.0\", \"model\": \"HS200(US)\", \"deviceId\": \"A1B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4A1B20001\", \"oemId\": \"ABCD1234EFGH5678ABCD1234EFGH5678\", \"hwId\": \"1234ABCD5678EFGH1234ABCD5678EFGH\", \"rssi\": -42, \"longitude_i\": 1140579, \"latitude_i\": 225431, \"alias\": \"Kitchen Light Switch\", \"status\": \"new\", \"mic_type\": \"IOT.SMARTPLUGSWITCH\", \"feature\": \"TIM\", \"mac\": \"AA:BB:CC:DD:EE:01\", \"updating\": 0, \"led_off\": 0, \"relay_state\": 1, \"on_time\": 3600, \"active_mode\": \"none\", \"icon_hash\": \"\", \"dev_name\": \"Smart Wi-Fi Light Switch\", \"next_action\": {\"action\": -1}, \"err_code\": 0}}}"
}
}
6 changes: 6 additions & 0 deletions tests/wiremock/__files/kl420l5_us_get_sys_info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error_code": 0,
"result": {
"responseData": "{\"system\": {\"get_sysinfo\": {\"sw_ver\": \"1.0.11 Build 210929 Rel.084339\", \"hw_ver\": \"1.0\", \"model\": \"KL420L5(US)\", \"deviceId\": \"D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6A1D4E50004\", \"oemId\": \"ABCD1234KL420001ABCD1234KL420001\", \"hwId\": \"1234ABCDKL420001ABCD1234KL420001\", \"rssi\": -45, \"longitude_i\": 1140579, \"latitude_i\": 225431, \"alias\": \"Living Room Strip\", \"status\": \"new\", \"mic_type\": \"IOT.SMARTBULB\", \"feature\": \"\", \"mac\": \"AA:BB:CC:DD:EE:04\", \"updating\": 0, \"led_off\": 0, \"is_dimmable\": 1, \"is_color\": 1, \"is_variable_color_temp\": 1, \"light_state\": {\"on_off\": 1, \"mode\": \"normal\", \"hue\": 240, \"saturation\": 100, \"color_temp\": 0, \"brightness\": 75}, \"dev_name\": \"Kasa Smart LED Light Strip\", \"err_code\": 0}}}"
}
}
6 changes: 6 additions & 0 deletions tests/wiremock/__files/kl430_us_get_sys_info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error_code": 0,
"result": {
"responseData": "{\"system\": {\"get_sysinfo\": {\"sw_ver\": \"1.0.8 Build 210121 Rel.084339\", \"hw_ver\": \"2.0\", \"model\": \"KL430(US)\", \"deviceId\": \"140BED90F6EF82191649329403A40C66528411D2\", \"oemId\": \"8BB9A4E25D621BC7163EEF9CDDE2E37C\", \"hwId\": \"6E2F6FA0EEE2CC63C8E1CA1C90698437\", \"rssi\": -38, \"longitude_i\": 1140579, \"latitude_i\": 225431, \"alias\": \"Test Strip\", \"status\": \"new\", \"mic_type\": \"IOT.SMARTBULB\", \"feature\": \"\", \"mac\": \"7B:2A:CF:4A:E0:2B\", \"updating\": 0, \"led_off\": 0, \"is_dimmable\": 1, \"is_color\": 1, \"is_variable_color_temp\": 1, \"light_state\": {\"on_off\": 0, \"mode\": \"normal\", \"hue\": 0, \"saturation\": 0, \"color_temp\": 2700, \"brightness\": 50}, \"dev_name\": \"Kasa Smart Light Strip, Multicolor\", \"err_code\": 0}}}"
}
}
6 changes: 6 additions & 0 deletions tests/wiremock/__files/kp200_us_get_sys_info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error_code": 0,
"result": {
"responseData": "{\"system\": {\"get_sysinfo\": {\"sw_ver\": \"1.0.3 Build 210121 Rel.084339\", \"hw_ver\": \"1.0\", \"model\": \"KP200(US)\", \"deviceId\": \"B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5B2C30002\", \"oemId\": \"ABCD1234KP200001ABCD1234KP200001\", \"hwId\": \"1234ABCDKP200001ABCD1234KP200001\", \"rssi\": -35, \"longitude_i\": 1140579, \"latitude_i\": 225431, \"alias\": \"Front Porch Plug\", \"status\": \"new\", \"mic_type\": \"IOT.SMARTPLUGSWITCH\", \"feature\": \"TIM\", \"mac\": \"AA:BB:CC:DD:EE:02\", \"updating\": 0, \"led_off\": 0, \"children\": [{\"id\": \"B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5B2C3000200\", \"state\": 1, \"alias\": \"Porch Light\", \"on_time\": 1200, \"next_action\": {\"type\": -1}}, {\"id\": \"B2C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5B2C3000201\", \"state\": 0, \"alias\": \"Fountain\", \"on_time\": 0, \"next_action\": {\"type\": -1}}], \"child_num\": 2, \"err_code\": 0}}}"
}
}
6 changes: 6 additions & 0 deletions tests/wiremock/__files/kp400_us_get_sys_info_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"error_code": 0,
"result": {
"responseData": "{\"system\": {\"get_sysinfo\": {\"sw_ver\": \"1.0.5 Build 210121 Rel.084339\", \"hw_ver\": \"1.0\", \"model\": \"KP400(US)\", \"deviceId\": \"C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6C3D40003\", \"oemId\": \"ABCD1234KP400001ABCD1234KP400001\", \"hwId\": \"1234ABCDKP400001ABCD1234KP400001\", \"rssi\": -40, \"longitude_i\": 1140579, \"latitude_i\": 225431, \"alias\": \"Backyard Plug\", \"status\": \"new\", \"mic_type\": \"IOT.SMARTPLUGSWITCH\", \"feature\": \"TIM\", \"mac\": \"AA:BB:CC:DD:EE:03\", \"updating\": 0, \"led_off\": 0, \"children\": [{\"id\": \"C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6C3D4000300\", \"state\": 0, \"alias\": \"Garden Lights\", \"on_time\": 0, \"next_action\": {\"type\": -1}}, {\"id\": \"C3D4E5F6A1B2C3D4E5F6A1B2C3D4E5F6C3D4000301\", \"state\": 1, \"alias\": \"Pool Pump\", \"on_time\": 7200, \"next_action\": {\"type\": -1}}], \"child_num\": 2, \"err_code\": 0}}}"
}
}
7 changes: 7 additions & 0 deletions tests/wiremock/__files/v2_account_status_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"error_code": 0,
"result": {
"accountStatus": 0,
"appServerUrl": "http://127.0.0.1:8080"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"accountId": "123456",
"regTime": "2017-11-27 23:21:40",
"countryCode": "US",
"email": "example@gmail.com",
"token": "abcdef-AB1234cdeTKJH123kja0"
"email": "kasa_docker",
"token": "abcdef-AB1234cdeTKJH123kja0",
"refreshToken": "refresh-token-mock-abc123"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"request": {
"method": "POST",
"url": "/?appName=Kasa_Android&termID=2a8ced52-f200-4b79-a1fe-2f6b58193c4c&appVer=1.4.4.607&ospf=Android%2B6.0.1&netType=wifi&locale=es_ES&token=abcdef-AB1234cdeTKJH123kja0",
"urlPath": "/",
"bodyPatterns": [
{
"equalToJson" : {
"equalToJson": {
"method": "passthrough",
"params": {
"deviceId": "5BFA53B31294DDA5AB4DEBA1B62582E8EC2F789E",
Expand All @@ -14,8 +14,12 @@
}
],
"headers": {
"User-Agent": { "equalTo": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; A0001 Build/M4B30X)" },
"Content-Type": { "equalTo": "application/json" }
"User-Agent": {
"matches": "Dalvik/.*"
},
"Content-Type": {
"matches": "application/json.*"
}
}
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"request": {
"method": "POST",
"url": "/?appName=Kasa_Android&termID=2a8ced52-f200-4b79-a1fe-2f6b58193c4c&appVer=1.4.4.607&ospf=Android%2B6.0.1&netType=wifi&locale=es_ES&token=abcdef-AB1234cdeTKJH123kja0",
"urlPath": "/",
"bodyPatterns": [
{
"equalToJson" : {
"equalToJson": {
"method": "passthrough",
"params": {
"deviceId": "5BFA53B31294DDA5AB4DEBA1B62582E8EC2F789E",
Expand All @@ -14,8 +14,12 @@
}
],
"headers": {
"User-Agent": { "equalTo": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; A0001 Build/M4B30X)" },
"Content-Type": { "equalTo": "application/json" }
"User-Agent": {
"matches": "Dalvik/.*"
},
"Content-Type": {
"matches": "application/json.*"
}
}
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"request": {
"method": "POST",
"url": "/?appName=Kasa_Android&termID=2a8ced52-f200-4b79-a1fe-2f6b58193c4c&appVer=1.4.4.607&ospf=Android%2B6.0.1&netType=wifi&locale=es_ES&token=abcdef-AB1234cdeTKJH123kja0",
"urlPath": "/",
"bodyPatterns": [
{
"equalToJson" : {
"equalToJson": {
"method": "passthrough",
"params": {
"deviceId": "5BFA53B31294DDA5AB4DEBA1B62582E8EC2F789E",
Expand All @@ -14,8 +14,12 @@
}
],
"headers": {
"User-Agent": { "equalTo": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; A0001 Build/M4B30X)" },
"Content-Type": { "equalTo": "application/json" }
"User-Agent": {
"matches": "Dalvik/.*"
},
"Content-Type": {
"matches": "application/json.*"
}
}
},
"response": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"request": {
"method": "POST",
"url": "/?appName=Kasa_Android&termID=2a8ced52-f200-4b79-a1fe-2f6b58193c4c&appVer=1.4.4.607&ospf=Android%2B6.0.1&netType=wifi&locale=es_ES&token=abcdef-AB1234cdeTKJH123kja0",
"urlPath": "/",
"bodyPatterns": [
{
"equalToJson" : {
"equalToJson": {
"method": "passthrough",
"params": {
"deviceId": "5BFA53B31294DDA5AB4DEBA1B62582E8EC2F789E",
Expand All @@ -14,8 +14,12 @@
}
],
"headers": {
"User-Agent": { "equalTo": "Dalvik/2.1.0 (Linux; U; Android 6.0.1; A0001 Build/M4B30X)" },
"Content-Type": { "equalTo": "application/json" }
"User-Agent": {
"matches": "Dalvik/.*"
},
"Content-Type": {
"matches": "application/json.*"
}
}
},
"response": {
Expand Down
Loading