| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
This is really cool, great work @sdb9696! Just wanted to give some quick feedback.
Sorry, something went wrong.
Yes I was thinking the same. However I wanted to keep this PR as close to your initial #499 as possible so we didn't start off with a giant PR.
There is some overlap, particularly around the retry logic which could be any httpx connection. Again as above I wanted to keep this PR as simple as possible. My suggestion would be to get this working for the Kasa EP25 and a TAPO plug, and then do some refactoring and code re-use in a separate PR. I'm happy to do it the other way round if you want but I thought it would be easier for you to keep things ticking along if you have less to review each time.
Some of the code, i.e. the Cipher, KeyPair and the SnowflakeId came from https://github.com/petretiandrea/plugp100 which seems to have the same GNU GPL 3 license as this library so I don't think there are any incompatibilities. Let me know if you agree. Anyway, let me know how you want to proceed, i.e. with incremental PRs or incremental commits to this PR. |
Sorry, something went wrong.
So I don't have a clear opinion on this. What I was thinking was that it would be great to have a base class straight from the beginning, as that will likely happen in the near future anyway and we know that there exists common functionalities among the devices. Another thing that caught my mind was that maybe it's also a good idea to contain the tapo functionality inside its own package (e.g., inside python-kasa/kasa/tapo) from the get-go to avoid moving them around soon-ish. There will likely be much more files coming in when other device categories get added, so having them separated from kasa-specific code makes sense. The base class does not need to have much, just that it exists there as a place to easily start adding common functionalities when we get that far.
Sounds reasonable to me, maybe some parts of the common functionalities can be refactored to the protocol base class to avoid inconsistencies among protocol handling, but that can wait for now.
Yupp, that's fine. Please add a docstring note with a link to the plugp100 repository and mention the compatible, I think that should be good enough :-) |
Sorry, something went wrong.
|
On another note, maybe the protocol itself should just be renamed and remain in the base package? Given it's not just used for tapo devices, but as an transport & encryption layer for the newer kasa-branded, too. |
Sorry, something went wrong.
|
|
||
| def _md5(payload: bytes) -> bytes: | ||
| digest = hashes.Hash(hashes.MD5()) # noqa: S303 | ||
| digest.update(payload) |
Code scanning / CodeQL
Use of a broken or weak cryptographic hashing algorithm on sensitive data
|
|
||
| def _sha1(payload: bytes) -> str: | ||
| sha1_algo = hashlib.sha1() # noqa: S324 | ||
| sha1_algo.update(payload) |
Code scanning / CodeQL
Use of a broken or weak cryptographic hashing algorithm on sensitive data
| @staticmethod | ||
| def create_key_pair(key_size: int = 1024): | ||
| """Create a key pair.""" | ||
| private_key = rsa.generate_private_key(public_exponent=65537, key_size=key_size) |
Code scanning / CodeQL
Use of weak cryptographic key
Codecov ReportAttention: 257 lines in your changes are missing coverage. Please review.
@@ Coverage Diff @@
## master #552 +/- ##
==========================================
- Coverage 82.29% 75.84% -6.45%
==========================================
Files 30 33 +3
Lines 2468 2861 +393
Branches 694 747 +53
==========================================
+ Hits 2031 2170 +139
- Misses 379 634 +255
+ Partials 58 57 -1 ☔ View full report in Codecov by Sentry. |
Sorry, something went wrong.
Ok that is done. Base class of TapoDevice(SmartDevice) and TapoPlug derives from TapoDevice (not SmartPlug)
That's done
That's done @ezekieldas could you please check this still works with your EP25? |
Sorry, something went wrong.
|
This looks fantastic: https://pastebin.com/xRAvpT9u Perhaps non-issue but there is that datetime.timedelta ValueError at the end. |
Sorry, something went wrong.
|
I have several of these new EP25 plugs and can verify that this at least appears to be working:
I am getting a similar ValueError to @ezekieldas at the end of output. Happy to help test, debug, etc. (and send one or two devices to devs for testing. If they don't work with Home Assistant, they are useless to me) |
Sorry, something went wrong.
|
The ValueError should be fixed if you take the latest version of this PR updated just now |
Sorry, something went wrong.
|
Yes, so I did another checkout of pull552 and this did correct the ValueError: [ ... ] == Device specific information == is_hw_v2: False overheated: False signal_level: 3 auto_off_status: off auto_off_remain_time: 0 SSID: foobarXYZ On since: 2023-11-18 05:04:27 == Modules == |
Sorry, something went wrong.
|
I'm going to order a device to have something to test with. Any idea if the P125M will work even though it supports matter? I can't see to find any of them that don't support matter for sale and will ship to Hawaii |
Sorry, something went wrong.
I haven't used or researched these, nor am I familiar with matter. However kp125m is listed on the integrations page. See the comment: supported via Matter, but without energy monitoring features |
Sorry, something went wrong.
|
I’m not sure I’m afraid. From looking at decompiled Kasa & TAPO .apk I’d say they support both but it’s difficult to be sure. I guess the worst case is we end up with a Matter protocol ;) |
Sorry, something went wrong.
|
I ordered the EP25 and the kp125m I figure one of them will be useful for testing |
Sorry, something went wrong.
|
To my understanding, based on some issue comments), the matter-based devices are using the "tapo" protocol (unsure if it's just the transport or also for the command set) as a secondary communications protocol. The emeter features do not work over the matter at the moment, as I think only the recently announced upcoming 1.2 (or 1.3?) has support for such. For EP25, it seems that the new hw version (v4?) is the one that has moved to use the AES encryption, and I'm quite confident others will follow as it just makes sense :-) edit: KP125M seems to use KLAP & tapo commands as per #450 (comment) |
Sorry, something went wrong.
There was a problem hiding this comment.
So I received my test bulb today and my pending deadline was postponed a bit, so I had some time to play around with it :-)
Here are some comments, I'll create a draft PR based on this PR that adds support for tapo bulbs. Some notes based on my experiments:
Sorry, something went wrong.
|
sdb9696#14 adds support for bulbs. Maybe it would make more sense to base it on top of python-kasa master instead of the branch for the PR at hand to keep the merges small, but github ui's diff view makes it easier to see how few changes were required for basic functionalities :-) |
Sorry, something went wrong.
|
Unbelievably, overnight my Tapo P110 updated it's firmware to the KLAP encryption. It's now running sw_version 1.3.0 Build 230905 Rel.152200. {'device_id': '**', 'owner': '**', 'device_type': 'SMART.TAPOPLUG', 'device_model': 'P110(UK)', 'ip': '**', 'mac': '**', '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}}} As a result I set to looking at what is needed to support this configuration. I've created a draft PR to support TAPO/KLAP, but I don't know if I've broken the AES transport in the process. I no longer have a device with this configuration :(. @ezekieldas would you mind testing your EP25 with this new PR to see if it still works with your device. @rytilahti there are more comments in the other PR regarding the approach. I've also addressed all your previous review comments in this PR. |
Sorry, something went wrong.
|
Here are the results from #557: https://pastebin.com/XPpDRS3e It ends with an AuthenticationException. Just to be certain, I compared same args/creds used in this test with the previous test on #552, and that remains successful. |
Sorry, something went wrong.
| self._energy = await self.protocol.query("get_energy_usage") | ||
| self._emeter = await self.protocol.query("get_current_power") |
There was a problem hiding this comment.
The bulb seems to support these commands, too, but I'm not sure if we can detect the availability using component_nego or some other way.
Here's the response for the from the bulb (kasa -d --type tapobulb --username $KASA_TAPO_EMAIL --password $KASA_TAPO_PASSWORD --host 192.168.xx.xx raw-command "" component_nego):
<< {'component_list': [{'id': 'device', 'ver_code': 2},
{'id': 'firmware', 'ver_code': 2},
{'id': 'quick_setup', 'ver_code': 3},
{'id': 'inherit', 'ver_code': 1},
{'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': 'cloud_connect', 'ver_code': 1},
{'id': 'default_states', 'ver_code': 1},
{'id': 'preset', 'ver_code': 1},
{'id': 'brightness', 'ver_code': 1},
{'id': 'color', 'ver_code': 1},
{'id': 'color_temperature', 'ver_code': 1},
{'id': 'auto_light', 'ver_code': 1},
{'id': 'on_off_gradually', 'ver_code': 1},
{'id': 'device_local_time', 'ver_code': 1},
{'id': 'light_effect', 'ver_code': 1},
{'id': 'iot_cloud', 'ver_code': 1},
{'id': 'bulb_quick_control', 'ver_code': 1}]}
{"component_list": }
I updated the list to the draft bulb PR, so it's easily available.
Sorry, something went wrong.
|
Please add a debug output for the query, that'll make it easier to debug issues when a query is failing :-) diff --git a/kasa/aesprotocol.py b/kasa/aesprotocol.py
index f74ae54..f357de4 100644
--- a/kasa/aesprotocol.py
+++ b/kasa/aesprotocol.py
@@ -304,6 +304,12 @@ class TPLinkAes(TPLinkProtocol):
raise SmartDeviceException("Query reached somehow to unreachable")
async def _execute_query(self, request: Union[str, Dict], retry_count: int) -> Dict:
+ _LOGGER.debug(
+ "%s >> %s",
+ self.host,
+ _LOGGER.isEnabledFor(logging.DEBUG) and pf(request),
+ )
+
if not self.http_client:
self.http_client = httpx.AsyncClient()
|
Sorry, something went wrong.
Hi @ezekieldas. I think I've fixed it, could you try again? |
Sorry, something went wrong.
|
It definitely looks fixed! https://pastebin.com/66Z1XGR5 I do a quick scan (human, me) of the output each time, and here I see the val for timezone looking a bit funky (see line 156): ...but other than that, it looks good! |
Sorry, something went wrong.
I've just figured out how to do multiple requests in one go. I'll add support for this in a later PR if that's ok? |
Sorry, something went wrong.
That's fine, let's get preliminary support in and we can then iterate and optimize 👍 |
Sorry, something went wrong.
Thank you very much! |
Sorry, something went wrong.
The trouble is I can no longer test this PR with a device myself because my P110 upgraded to KLAP overnight. Also the changes in #557 are going to make it much easier to write the FakeTransport for testing the TAPO protocol and test using the "new" fixtures with TAPO responses. I don't suppose we could hold off on the tests until #557? It will save me a lot of time and tests is my number 1 priority at the moment (as you may have guessed from #556) |
Sorry, something went wrong.
|
Sounds reasonable! I'll go through this one later tonight and see if there is something that should be handled before merging this. But I think in the end we will just merge this as is and iterate on later PRs 👍 |
Sorry, something went wrong.
|
@sdb9696 could you update the title and the description to be more descriptive? Doesn't need to be anything fancy, but given the size and the importance of this change, it would be great to have descriptive ones for anyone reading the changelogs/commit logs. I will now check if there's something that should be changed prior the merge. |
Sorry, something went wrong.
|
Now updated with changes or replies. N.B. I have squashed all the commits except the latest to make rebasing #557 on top of this PR easier. |
Sorry, something went wrong.
|
Great, thanks @rytilahti! Onto #557 :) |
Sorry, something went wrong.
… devices. (python-kasa#552) * Add Tapo protocol support * Update get_device_instance and test_unsupported following review
| Back | FazBrowse Home | New Git URL |
Related to #499 and #548