forked from K4CZP3R/tapo-p100-python
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): device discovery now detect right protocol
- Loading branch information
1 parent
bcd34c3
commit e78dff3
Showing
4 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,17 @@ | ||
{ | ||
"device_id": "device_id_123", | ||
"owner": "owner_id", | ||
"device_type": "SMART.TAPOBULB", | ||
"device_model": "L530E(EU)", | ||
"ip": "1.2.3.4", | ||
"mac": "1a-22-33-b4-c5-66", | ||
"is_support_iot_cloud": true, | ||
"obd_src": "tplink", | ||
"factory_default": false, | ||
"mgt_encrypt_schm": { | ||
"is_support_https": false, | ||
"encrypt_type": "KLAP", | ||
"http_port": 80, | ||
"lv": 2 | ||
} | ||
} |
This file contains 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,44 @@ | ||
from unittest.mock import patch, AsyncMock | ||
|
||
from plugp100.common.credentials import AuthCredential | ||
from plugp100.discovery import DiscoveredDevice | ||
from plugp100.new.tapobulb import TapoBulb | ||
from tests.conftest import load_fixture | ||
|
||
|
||
def test_must_convert_discovered_device_to_dict(): | ||
discovery_data = load_fixture("discovery.json") | ||
discovered_device = DiscoveredDevice.from_dict(discovery_data) | ||
assert discovered_device is not None | ||
dictionary = discovered_device.as_dict | ||
assert dictionary["mgt_encrypt_schm"] == discovery_data["mgt_encrypt_schm"] | ||
assert dictionary["mac"] == discovery_data["mac"] | ||
assert dictionary["ip"] == discovery_data["ip"] | ||
assert dictionary["device_id"] == discovery_data["device_id"] | ||
assert dictionary["device_type"] == discovery_data["device_type"] | ||
assert dictionary["device_model"] == discovery_data["device_model"] | ||
|
||
|
||
async def test_discovered_device_should_get_real_tapo_device(): | ||
discovered_device = DiscoveredDevice.from_dict(load_fixture("discovery.json")) | ||
device = await discovered_device.get_tapo_device( | ||
credentials=AuthCredential("test", "test") | ||
) | ||
assert device is not None | ||
assert device.protocol_version == "Klap V2" | ||
assert device.host == "1.2.3.4" | ||
assert isinstance(device, TapoBulb) | ||
|
||
|
||
async def test_should_not_get_device_info_if_discovery_has_type(): | ||
discovered_device = DiscoveredDevice.from_dict(load_fixture("discovery.json")) | ||
|
||
with patch( | ||
"plugp100.protocol.tapo_protocol.TapoProtocol.send_request", | ||
side_effect=AsyncMock(return_value=None), | ||
) as send_request: | ||
device = await discovered_device.get_tapo_device( | ||
credentials=AuthCredential("test", "test") | ||
) | ||
send_request.assert_not_called() | ||
assert device is not None |