Skip to content

Add ssltransport for robovacs #943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Dec 1, 2024
Merged

Add ssltransport for robovacs #943

merged 25 commits into from
Dec 1, 2024

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Jun 2, 2024

This PR implements a clear-text, token-based transport protocol seen on RV30 Plus (#937).

  • Client sends {"username": "email@example.com", "password": md5(password)} and gets back a token in the response
  • Rest of the communications are done with POST at /app?token=<token>

TBD:

  • Figure out how to detect these devices, e.g., the robovac reports to use AES even when it doesn't
  • Decide if ssl verification should be always disabled, or if we need to make this configurable
  • Cleanup commented out leftovers from aestransport
  • Tests
  • Improve tests: error conditions (login failures, ..)

@rytilahti rytilahti added the enhancement New feature or request label Jun 2, 2024
Copy link

codecov bot commented Jun 2, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 92.20%. Comparing base (d122b48) to head (8d78a29).
Report is 136 commits behind head on master.

Files with missing lines Patch % Lines
kasa/transports/ssltransport.py 97.41% 2 Missing and 1 partial ⚠️
kasa/smart/smartdevice.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #943      +/-   ##
==========================================
+ Coverage   92.13%   92.20%   +0.06%     
==========================================
  Files         119      120       +1     
  Lines        7619     7744     +125     
  Branches      794      805      +11     
==========================================
+ Hits         7020     7140     +120     
- Misses        441      444       +3     
- Partials      158      160       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rytilahti rytilahti mentioned this pull request Jun 2, 2024
@rytilahti
Copy link
Member Author

Needs investigated if the protocol is the same (or very similar) to one proposed in #1165. If yes, this can probably be closed in favor of that PR.

@rytilahti rytilahti changed the title Add cleartexttransport seen on robovacs Add ssltransport seen on robovacs Nov 28, 2024
Copy link
Collaborator

@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor nits.

Also need to add:

"SMART.TAPOROBOVAC": SmartDevice, to device_factory.get_device_class_from_family

and

SmartRobovac= "SMART.TAPOROBOVAC" to DeviceFamily

and update SmartDevice._get_device_type_from_components to return DeviceType.RoboVac appropriately.

Is it worth adding the new get methods from #937 to dump_devinfo as extra_calls or better still to helpers.smartrequests.py under new clean and map components?

rytilahti and others added 3 commits November 29, 2024 17:16
Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
@rytilahti
Copy link
Member Author

Is it worth adding the new get methods from #937 to dump_devinfo as extra_calls or better still to helpers.smartrequests.py under new clean and map components?

Yes, I think they deserve their own components. Do you think they should go in as part of this PR? My plan was to avoid adding vac specific code as part of this PR, and create another one that adds everything we can from the response dump to get a mostly complete fixture from the get-go.

@rytilahti rytilahti changed the title Add ssltransport seen on robovacs Add ssltransport for robovacs Nov 29, 2024
@rytilahti rytilahti requested a review from sdb9696 November 30, 2024 14:48
@rytilahti rytilahti marked this pull request as ready for review November 30, 2024 14:50
@rytilahti
Copy link
Member Author

This should be now ready for review, #1322 needs to be merged first and this then rebased on top of the master prior merging.

Comment on lines +209 to +214
def _session_expired(self) -> bool:
"""Return true if session has expired."""
return (
self._session_expire_at is None
or self._session_expire_at - time.time() <= 0
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear if the tokens ever expire, so we can either keep this as-is, or remove the complete session expired handling (and hope that the device reports with an error to retrigger login).

Opinions on that? Not having _session_expired() would clean up the code a bit.

Comment on lines +183 to +184
except Exception as ex:
raise KasaException(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having second thoughts on whether we should be wrapping unexpected exceptions like this, as letting it blow would be a clearer indication that something is off.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in HA we catch KasaException in order to ensure we always conform with the quality requirement to only raise HomeAssistantError. (It might not be a requirement anymore with the latest quality scale but haven’t checked)

Copy link
Collaborator

@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think we can simplify get_protocol in a subsequent PR.

@rytilahti rytilahti merged commit 9966c60 into master Dec 1, 2024
18 checks passed
@rytilahti rytilahti deleted the feat/tokentransport branch December 1, 2024 17:06
@sdb9696 sdb9696 mentioned this pull request Dec 21, 2024
sdb9696 added a commit that referenced this pull request Dec 21, 2024
## [0.9.0](https://github.com/python-kasa/python-kasa/tree/0.9.0) (2024-12-21)

[Full Changelog](0.8.1...0.9.0)

**Release highlights:**

- Improvements to Tapo camera support:
  - C100, C225, C325WB, C520WS and TC70 now supported.
  - Support for motion, person, tamper, and baby cry detection.
- Initial support for Tapo robovacs.
- API extended with `FeatureAttributes` for consumers to test for [supported features](https://python-kasa.readthedocs.io/en/stable/topics.html#modules-and-features).
- Experimental support for Kasa cameras[^1]

[^1]: Currently limited to devices not yet provisioned via the Tapo app - Many thanks to @Puxtril!

**Breaking changes:**

- Use DeviceInfo consistently across devices [\#1338](#1338) (@sdb9696)

**Implemented enhancements:**

- Add rssi and signal\_level to smartcam [\#1392](#1392) (@sdb9696)
- Add smartcam detection modules [\#1389](#1389) (@sdb9696)
- Add bare-bones matter modules to smart and smartcam devices [\#1371](#1371) (@sdb9696)
- Add bare bones homekit modules smart and smartcam devices [\#1370](#1370) (@sdb9696)
- Return raw discovery result in cli discover raw [\#1342](#1342) (@sdb9696)
- cli: print model, https, and lv for discover list [\#1339](#1339) (@rytilahti)
- Improve overheat reporting [\#1335](#1335) (@rytilahti)
- Provide alternative camera urls [\#1316](#1316) (@sdb9696)
- Add LinkieTransportV2 and basic IOT.IPCAMERA support [\#1270](#1270) (@Puxtril)
- Add ssltransport for robovacs [\#943](#943) (@rytilahti)

**Fixed bugs:**

- Tapo H200 Hub does not work with python-kasa [\#1149](#1149)
- Treat smartcam 500 errors after handshake as retryable [\#1395](#1395) (@sdb9696)
- Fix lens mask required component and state [\#1386](#1386) (@sdb9696)
- Add LensMask module to smartcam [\#1385](#1385) (@sdb9696)
- Do not error when accessing smart device\_type before update [\#1319](#1319) (@sdb9696)
- Fallback to other module data on get\_energy\_usage errors [\#1245](#1245) (@rytilahti)

**Added support for devices:**

- Add P210M\(US\) 1.0 1.0.3 fixture [\#1399](#1399) (@sdb9696)
- Add C225\(US\) 2.0 1.0.11 fixture [\#1398](#1398) (@sdb9696)
- Add P306\(US\) 1.0 1.1.2 fixture [\#1396](#1396) (@nakanaela)
- Add TC70 3.0 1.3.11 fixture [\#1390](#1390) (@sdb9696)
- Add C325WB\(EU\) 1.0 1.1.17 Fixture [\#1379](#1379) (@sdb9696)
- Add C100 4.0 1.3.14 Fixture [\#1378](#1378) (@sdb9696)
- Add KS200 \(US\) IOT Fixture and P115 \(US\) Smart Fixture [\#1355](#1355) (@ZeliardM)
- Add C520WS camera fixture [\#1352](#1352) (@Happy-Cadaver)

**Documentation updates:**

- Update docs for Tapo Lab Third-Party compatibility [\#1380](#1380) (@sdb9696)
- Add homebridge-kasa-python link to README [\#1367](#1367) (@rytilahti)
- Update docs for new FeatureAttribute behaviour [\#1365](#1365) (@sdb9696)
- Add link to related homeassistant-tapo-control [\#1333](#1333) (@rytilahti)

**Project maintenance:**

- Add P135 1.0 1.2.0 fixture [\#1397](#1397) (@sdb9696)
- Handle smartcam device blocked response [\#1393](#1393) (@sdb9696)
- Handle KeyboardInterrupts in the cli better [\#1391](#1391) (@sdb9696)
- Update C520WS fixture with new methods [\#1384](#1384) (@sdb9696)
- Miscellaneous minor fixes to dump\_devinfo [\#1382](#1382) (@sdb9696)
- Add timeout parameter to dump\_devinfo [\#1381](#1381) (@sdb9696)
- Simplify get\_protocol to prevent clashes with smartcam and robovac [\#1377](#1377) (@sdb9696)
- Add smartcam modules to package inits [\#1376](#1376) (@sdb9696)
- Enable saving of fixture files without git clone [\#1375](#1375) (@sdb9696)
- Force single for some smartcam requests [\#1374](#1374) (@sdb9696)
- Add new methods to dump\_devinfo [\#1373](#1373) (@sdb9696)
- Update cli, light modules, and docs to use FeatureAttributes [\#1364](#1364) (@sdb9696)
- Pass raw components to SmartChildDevice init [\#1363](#1363) (@sdb9696)
- Fix line endings in device\_fixtures.py [\#1361](#1361) (@sdb9696)
- Update dump\_devinfo for raw discovery json and common redactors [\#1358](#1358) (@sdb9696)
- Tweak RELEASING.md instructions for patch releases [\#1347](#1347) (@sdb9696)
- Scrub more vacuum keys [\#1328](#1328) (@rytilahti)
- Remove unnecessary check for python \<3.10 [\#1326](#1326) (@rytilahti)
- Add vacuum component queries to dump\_devinfo [\#1320](#1320) (@rytilahti)
- Handle missing mgt\_encryption\_schm in discovery [\#1318](#1318) (@sdb9696)
- Follow main package structure for tests [\#1317](#1317) (@rytilahti)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request no-stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants