-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
Initial implementation for modularized smartdevice #757
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good. A few minor questions, but nothing that can't be addressed down the road anyway.
@@ -79,67 +80,43 @@ def _try_get_response(self, responses: dict, request: str, default=None) -> dict | |||
f"{request} not found in {responses} for device {self.host}" | |||
) | |||
|
|||
async def _negotiate(self): | |||
resp = await self.protocol.query("component_nego") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should do the child component nego here as well to keep it in the same place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm planning to clean it up when I get back to work on getting the hub supported, but I think it can wait for now. There are some differences we need to consider, namely that child devices can be added and removed.
"get_device_time": None, | ||
**extra_reqs, | ||
} | ||
# TODO: this could be optimized by constructing the query only once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think we should have a static query_requests
on the module that returns a list that can then be called at once.
It would also mean we could do a check to see that the queries succeed before adding the module so the whole thing doesn't break when a new device does the unexpected like the KS240.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we could just collect all the queries that are reported by the modules like this PR does, but keep it stored in an instance variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apols I can't see where the modules report the queries atm. Can they report multiple per module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They either implement query()
that returns a query dict, or set QUERY_GETTER_NAME
which is used by the base class implementation. Maybe the base class implementation should be removed to force all modules to import it, explicit being better than implicit and so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh, I completely missed that query
doesn't do the query, it returns the requests. Makes sense now although maybe we should rename it at some point as it's not obvious from the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the naming comes from the iotdevice modules as it was already part of the API :-) I'm not sure what'd be a better name, but in principle it's the query that gets executed always during the update cycle.
@@ -60,6 +60,11 @@ def _test_property_getters(): | |||
) | |||
for prop in properties: | |||
name, _ = prop | |||
# Skip emeter and time properties | |||
# TODO: needs API cleanup, emeter* should probably be removed in favor | |||
# of access through features/modules, handling of time* needs decision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment, the child device inherits all properties from the smartdevice class, but may not necessarily have the same modules available. For emeter* the problem solves by itself when/if we remove those properties, but unsure how to proceed with other properties like time
and timezone
. Fallback to parent's information?
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #757 +/- ##
==========================================
+ Coverage 88.41% 88.65% +0.24%
==========================================
Files 46 53 +7
Lines 3987 4099 +112
Branches 1052 1068 +16
==========================================
+ Hits 3525 3634 +109
- Misses 386 389 +3
Partials 76 76 ☔ View full report in Codecov by Sentry. |
Let's merge this to unblock adding more modules & handle the remaining TODOs in separate and smaller PRs. |
## [0.7.0](https://github.com/python-kasa/python-kasa/tree/0.7.0) (2024-06-23) [Full Changelog](0.6.2.1...0.7.0) We have been working hard behind the scenes to make this major release possible. This release brings a major refactoring of the library to serve the ever-growing list of supported devices and paves the way for the future, yet unsupported devices. The library now exposes device features through generic module and feature interfaces, that allows easy extension for future improvements. With almost 180 merged pull requests, over 200 changed files and since the last release, this release includes lots of goodies for everyone: * Support for multi-functional devices like the dimmable fan KS240. * Initial support for hubs and hub-connected devices like thermostats and sensors. * Both IOT (legacy kasa) and SMART (tapo and newer kasa) devices now expose features and share common API. * Modules to allow controlling new devices and functions such as light presets, fan controls, thermostats, humidity sensors, firmware updates and alarms. * The common APIs allow dynamic introspection of available device features, making it easy to create dynamic interfaces. * Improved documentation. Hope you enjoy the release, feel free to leave a comment and feedback! If you have a device that works, but is not listed in our supported devices list, feel free to [contribute fixture files](https://python-kasa.readthedocs.io/en/latest/contribute.html#contributing-fixture-files) to help us to make the library even better! > git diff 0.6.2.1..HEAD|diffstat > 214 files changed, 26960 insertions(+), 6310 deletions(-) For more information on the changes please checkout our [documentation on the API changes](https://python-kasa.readthedocs.io/en/latest/deprecated.html) **Breaking changes:** - Add common energy module and deprecate device emeter attributes [\#976](#976) (@sdb9696) - Move SmartBulb into SmartDevice [\#874](#874) (@sdb9696) - Change state\_information to return feature values [\#804](#804) (@rytilahti) - Remove SmartPlug in favor of SmartDevice [\#781](#781) (@rytilahti) - Add generic interface for accessing device features [\#741](#741) (@rytilahti) **Implemented enhancements:** - Cleanup cli output [\#1000](#1000) (@rytilahti) - Improve autooff name and unit [\#997](#997) (@rytilahti) - Update mode, time, rssi and report\_interval feature names/units [\#995](#995) (@sdb9696) - Add unit\_getter for feature [\#993](#993) (@rytilahti) - Add timezone to on\_since attributes [\#978](#978) (@sdb9696) - Add type hints to feature set\_value [\#974](#974) (@sdb9696) - Handle unknown light effect names and only calculate effect list once [\#973](#973) (@sdb9696) - Support smart child modules queries [\#967](#967) (@sdb9696) - Do not expose child modules on parent devices [\#964](#964) (@sdb9696) - Do not add parent only modules to strip sockets [\#963](#963) (@sdb9696) - Add time sync command [\#951](#951) (@rytilahti) - Make device initialisation easier by reducing required imports [\#936](#936) (@sdb9696) - Fix set\_state for common light modules [\#929](#929) (@sdb9696) - Add state feature for iot devices [\#924](#924) (@rytilahti) - Add post update hook to module and use in smart LightEffect [\#921](#921) (@sdb9696) - Add LightEffect module for smart light strips [\#918](#918) (@sdb9696) - Add light presets common module to devices. [\#907](#907) (@sdb9696) - Improve categorization of features [\#904](#904) (@rytilahti) - Create common interfaces for remaining device types [\#895](#895) (@sdb9696) - Make get\_module return typed module [\#892](#892) (@sdb9696) - Add LightEffectModule for dynamic light effects on SMART bulbs [\#887](#887) (@sdb9696) - Implement choice feature type [\#880](#880) (@rytilahti) - Add Fan interface for SMART devices [\#873](#873) (@sdb9696) - Improve temperature controls [\#872](#872) (@rytilahti) - Add precision\_hint to feature [\#871](#871) (@rytilahti) - Be more lax on unknown SMART devices [\#863](#863) (@rytilahti) - Handle paging of partial responses of lists like child\_device\_info [\#862](#862) (@sdb9696) - Better firmware module support for devices not connected to the internet [\#854](#854) (@sdb9696) - Re-query missing responses after multi request errors [\#850](#850) (@sdb9696) - Implement action feature [\#849](#849) (@rytilahti) - Add temperature control module for smart [\#848](#848) (@rytilahti) - Implement feature categories [\#846](#846) (@rytilahti) - Expose IOT emeter info as features [\#844](#844) (@rytilahti) - Add support for feature units [\#843](#843) (@rytilahti) - Add ColorModule for smart devices [\#840](#840) (@sdb9696) - Add colortemp feature for iot devices [\#827](#827) (@rytilahti) - Add support for firmware module v1 [\#821](#821) (@sdb9696) - Add colortemp module [\#814](#814) (@rytilahti) - Add iot brightness feature [\#808](#808) (@sdb9696) - Revise device initialization and subsequent updates [\#807](#807) (@rytilahti) - Add brightness module [\#806](#806) (@rytilahti) - Support multiple child requests [\#795](#795) (@sdb9696) - Support for on\_off\_gradually v2+ [\#793](#793) (@rytilahti) - Improve smartdevice update module [\#791](#791) (@rytilahti) - Add --child option to feature command [\#789](#789) (@rytilahti) - Add temperature\_unit feature to t315 [\#788](#788) (@rytilahti) - Add feature for ambient light sensor [\#787](#787) (@shifty35) - Add initial support for H100 and T315 [\#776](#776) (@rytilahti) - Generalize smartdevice child support [\#775](#775) (@rytilahti) - Raise CLI errors in debug mode [\#771](#771) (@sdb9696) - Add cloud module for smartdevice [\#767](#767) (@rytilahti) - Add firmware module for smartdevice [\#766](#766) (@rytilahti) - Add fan module [\#764](#764) (@rytilahti) - Add smartdevice module for led controls [\#761](#761) (@rytilahti) - Auto auto-off module for smartdevice [\#760](#760) (@rytilahti) - Add smartdevice module for smooth transitions [\#759](#759) (@rytilahti) - Initial implementation for modularized smartdevice [\#757](#757) (@rytilahti) - Let caller handle SMART errors on multi-requests [\#754](#754) (@sdb9696) - Add 'shell' command to cli [\#738](#738) (@rytilahti) **Fixed bugs:** - Fix smart led status to report rule status [\#1002](#1002) (@sdb9696) - Demote device\_time back to debug [\#1001](#1001) (@rytilahti) - Fix to call update when only --device-family passed to cli [\#987](#987) (@sdb9696) - Disallow non-targeted device commands [\#982](#982) (@rytilahti) - Add supported check to light transition module [\#971](#971) (@sdb9696) - Fix switching off light effects for iot lights strips [\#961](#961) (@sdb9696) - Add state features to iot strip sockets [\#960](#960) (@sdb9696) - Ensure http delay logic works during default login attempt [\#959](#959) (@sdb9696) - Fix fan speed level when off and derive smart fan module from common fan interface [\#957](#957) (@sdb9696) - Require update in cli for wifi commands [\#956](#956) (@rytilahti) - Do not raise on multi-request errors on child devices [\#949](#949) (@rytilahti) - Do not show a zero error code when cli exits from showing help [\#935](#935) (@rytilahti) - Initialize autooff features only when data is available [\#933](#933) (@rytilahti) - Fix P100 errors on multi-requests [\#930](#930) (@sdb9696) - Fix potential infinite loop if incomplete lists returned [\#920](#920) (@sdb9696) - Add 'battery\_percentage' only when it's available [\#906](#906) (@rytilahti) - Add missing alarm volume 'normal' [\#899](#899) (@rytilahti) - Use Path.save for saving the fixtures [\#894](#894) (@rytilahti) - Fix wifi scan re-querying error [\#891](#891) (@sdb9696) - Fix --help on subcommands [\#886](#886) (@rytilahti) - Fix smartprotocol response list handler to handle null reponses [\#884](#884) (@sdb9696) - Improve feature setter robustness [\#870](#870) (@rytilahti) - smartbulb: Limit brightness range to 1-100 [\#829](#829) (@rytilahti) - Fix energy module calling get\_current\_power [\#798](#798) (@sdb9696) - Fix auto update switch [\#786](#786) (@rytilahti) - Retry query on 403 after successful handshake [\#785](#785) (@sdb9696) - Ensure connections are closed when cli is finished [\#752](#752) (@sdb9696) - Fix for P100 on fw 1.1.3 login\_version none [\#751](#751) (@sdb9696) - Pass timeout parameters to discover\_single [\#744](#744) (@sdb9696) - Reduce AuthenticationExceptions raising from transports [\#740](#740) (@sdb9696) - Do not crash cli on missing discovery info [\#735](#735) (@rytilahti) - Fix port-override for aes&klap transports [\#734](#734) (@rytilahti) - Fix discovery cli to print devices not printed during discovery timeout [\#670](#670) (@sdb9696) **Added support for devices:** - Add fixture for L920-5\(EU\) 1.0.7 [\#972](#972) (@rytilahti) - Add P115 fixture [\#950](#950) (@rytilahti) - Add some device fixtures [\#948](#948) (@rytilahti) - Add fixture for S505D [\#947](#947) (@rytilahti) - Add fixture for p300 1.0.15 [\#915](#915) (@rytilahti) - Add H100 1.5.10 and KE100 2.4.0 fixtures [\#905](#905) (@rytilahti) - Add fixture for waterleak sensor T300 [\#897](#897) (@rytilahti) - Add support for contact sensor \(T110\) [\#877](#877) (@rytilahti) - Add support for waterleak sensor \(T300\) [\#876](#876) (@rytilahti) - Add support for KH100 hub [\#847](#847) (@Adriandorr) - Support for new ks240 fan/light wall switch [\#839](#839) (@sdb9696) - Add P100 fw 1.4.0 fixture [\#820](#820) (@sdb9696) - Add fixture for P110 sw 1.0.7 [\#801](#801) (@rytilahti) - Add updated l530 fixture 1.1.6 [\#792](#792) (@rytilahti) - Fix devtools for P100 and add fixture [\#753](#753) (@sdb9696) - Add H100 fixtures [\#737](#737) (@rytilahti) **Documentation updates:** - Cleanup README to use the new cli format [\#999](#999) (@rytilahti) - Add 0.7 api changes section to docs [\#996](#996) (@sdb9696) - Update README to be more approachable for new users [\#994](#994) (@rytilahti) - Update docs with more howto examples [\#968](#968) (@sdb9696) - Update documentation structure and start migrating to markdown [\#934](#934) (@sdb9696) - Add tutorial doctest module and enable top level await [\#919](#919) (@sdb9696) - Add warning about tapo watchdog [\#902](#902) (@rytilahti) - Move contribution instructions into docs [\#901](#901) (@rytilahti) - Add rust tapo link to README [\#857](#857) (@rytilahti) - Enable shell extra for installing ptpython and rich [\#782](#782) (@sdb9696) - Add WallSwitch device type and autogenerate supported devices docs [\#758](#758) (@sdb9696) **Project maintenance:** - Drop python3.8 support [\#992](#992) (@rytilahti) - Remove anyio dependency from pyproject.toml [\#990](#990) (@sdb9696) - Configure mypy to run in virtual environment and fix resulting issues [\#989](#989) (@sdb9696) - Better checking of child modules not supported by parent device [\#966](#966) (@sdb9696) - Use freezegun for testing aes http client delays [\#954](#954) (@sdb9696) - Fix passing custom port for dump\_devinfo [\#938](#938) (@rytilahti) - Update release playbook [\#932](#932) (@rytilahti) - Deprecate device level light, effect and led attributes [\#916](#916) (@sdb9696) - Update cli to use common modules and remove iot specific cli testing [\#913](#913) (@sdb9696) - Deprecate is\_something attributes [\#912](#912) (@sdb9696) - Make Light and Fan a common module interface [\#911](#911) (@sdb9696) - Rename bulb interface to light and move fan and light interface to interfaces [\#910](#910) (@sdb9696) - Make module names consistent and remove redundant module casting [\#909](#909) (@sdb9696) - Add child devices from hubs to generated list of supported devices [\#898](#898) (@sdb9696) - Update interfaces so they all inherit from Device [\#893](#893) (@sdb9696) - Update ks240 fixture with child device query info [\#890](#890) (@sdb9696) - Use pydantic.v1 namespace on all pydantic versions [\#883](#883) (@rytilahti) - Update dump\_devinfo to print original exception stack on errors. [\#882](#882) (@sdb9696) - Put modules back on children for wall switches [\#881](#881) (@sdb9696) - Fix pypy39 CI cache on macos [\#868](#868) (@sdb9696) - Do not try coverage upload for pypy [\#867](#867) (@sdb9696) - Add runner.arch to cache-key in CI [\#866](#866) (@sdb9696) - Fix broken CI due to missing python version on macos-latest [\#864](#864) (@sdb9696) - Fix incorrect state updates in FakeTestProtocols [\#861](#861) (@sdb9696) - Embed FeatureType inside Feature [\#860](#860) (@rytilahti) - Include component\_nego with child fixtures [\#858](#858) (@sdb9696) - Use brightness module for smartbulb [\#853](#853) (@rytilahti) - Ignore system environment variables for tests [\#851](#851) (@rytilahti) - Remove mock fixtures [\#845](#845) (@rytilahti) - Enable and convert to future annotations [\#838](#838) (@sdb9696) - Update poetry locks and pre-commit hooks [\#837](#837) (@sdb9696) - Cache pipx in CI and add custom setup action [\#835](#835) (@sdb9696) - Fix non python 3.8 compliant test [\#832](#832) (@sdb9696) - Fix CI issue with python version used by pipx to install poetry [\#831](#831) (@sdb9696) - Refactor split smartdevice tests to test\_{iot,smart}device [\#822](#822) (@rytilahti) - Add pre-commit caching and fix poetry extras cache [\#817](#817) (@sdb9696) - Fix slow aestransport and cli tests [\#816](#816) (@sdb9696) - Do not run coverage on pypy and cache poetry envs [\#812](#812) (@sdb9696) - Update test framework for dynamic parametrization [\#810](#810) (@sdb9696) - Put child fixtures in subfolder [\#809](#809) (@sdb9696) - Simplify device \_\_repr\_\_ [\#805](#805) (@rytilahti) - Add T315 fixture, tests for humidity&temperature modules [\#802](#802) (@rytilahti) - Do not fail fast on pypy CI jobs [\#799](#799) (@sdb9696) - Update dump\_devinfo to collect child device info [\#796](#796) (@sdb9696) - Refactor test framework [\#794](#794) (@sdb9696) - Add missing firmware module import [\#774](#774) (@rytilahti) - Fix dump\_devinfo scrubbing for ks240 [\#765](#765) (@rytilahti) - Rename and deprecate exception classes [\#739](#739) (@sdb9696) - Refactor devices into subpackages and deprecate old names [\#716](#716) (@sdb9696)
The initial steps to modularize the smartdevice. Modules are initialized based on the component negotiation, and each module can indicate which features it supports and which queries should be run during the update cycle.
TBD: