Skip to content

Add fan module #764

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 6 commits into from
Apr 17, 2024
Merged

Add fan module #764

merged 6 commits into from
Apr 17, 2024

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Feb 18, 2024

This adds the final missing piece, the fan control module, for KS240 support:

== Features ==
        Device ID (device_id): xx
        Signal Level (signal_level): 3
        RSSI (rssi): -41
        SSID (ssid): xx
        Brightness (brightness): 'brightness'
        Cloud connection (cloud_connection): True
        Fan speed level (fan_speed_level): 'fan_speed_level'
        Fan sleep mode (fan_sleep_mode): 'fan_sleep_mode_on'
        Auto update enabled (auto_update_enabled): False
        Update available (update_available): True
        LED (led): False
        Smooth transition on (smooth_transition_on): argument of type 'SmartErrorCode' is not iterable
        Smooth transition off (smooth_transition_off): argument of type 'SmartErrorCode' is not iterable
        Time (time): You need to call update() prior accessing module data for 'time'
== Child Ceiling Fan ==
        Device ID (device_id): xx
        State (state): False
        Cloud connection (cloud_connection): True
        Fan speed level (fan_speed_level): 1
        Fan sleep mode (fan_sleep_mode): False
        Auto update enabled (auto_update_enabled): False
        Update available (update_available): True
        Time (time): You need to call update() prior accessing module data for 'time'
== Child Dimmer Switch ==
        Device ID (device_id): xx
        State (state): False
        On since (on_since): None
        Brightness (brightness): 100
        Cloud connection (cloud_connection): True
        Auto update enabled (auto_update_enabled): False
        Update available (update_available): True
        Smooth transition on (smooth_transition_on): argument of type 'SmartErrorCode' is not iterable
        Smooth transition off (smooth_transition_off): argument of type 'SmartErrorCode' is not iterable
        Time (time): You need to call update() prior accessing module data for 'time'

Fixes #749.

@rytilahti rytilahti added the enhancement New feature or request label Feb 18, 2024
@rytilahti rytilahti force-pushed the feat/h100_and_children branch 3 times, most recently from ec73aad to 9b2a6f9 Compare February 19, 2024 00:30
@rytilahti rytilahti force-pushed the feat/h100_and_children branch 2 times, most recently from 921e903 to 66da963 Compare February 19, 2024 23:33
@sdb9696 sdb9696 added this to the 0.7.0 milestone Feb 20, 2024
@rytilahti rytilahti changed the base branch from feat/h100_and_children to master February 22, 2024 22:10
@rytilahti rytilahti force-pushed the feat/ks240_support branch 2 times, most recently from 54fdbf6 to 498361c Compare February 22, 2024 22:28
@rytilahti rytilahti force-pushed the feat/ks240_support branch from 1ea4a03 to 22f25e9 Compare March 4, 2024 19:06
@rytilahti rytilahti marked this pull request as ready for review March 4, 2024 19:07
@rytilahti rytilahti marked this pull request as draft March 4, 2024 19:08
Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 62.96296% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 88.82%. Comparing base (da441bc) to head (f4e7962).

Files Patch % Lines
kasa/smart/modules/fanmodule.py 56.52% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #764      +/-   ##
==========================================
- Coverage   88.97%   88.82%   -0.16%     
==========================================
  Files          64       65       +1     
  Lines        4519     4544      +25     
  Branches     1126     1129       +3     
==========================================
+ Hits         4021     4036      +15     
- Misses        414      424      +10     
  Partials       84       84              

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

@rytilahti rytilahti force-pushed the feat/ks240_support branch from 22f25e9 to 98e9f3d Compare March 4, 2024 23:52
@rytilahti rytilahti changed the base branch from master to feat/color_temp_module March 4, 2024 23:52
@rytilahti rytilahti changed the title Initial KS240 support Add fan module Mar 4, 2024
@rytilahti rytilahti marked this pull request as ready for review March 4, 2024 23:58
@rytilahti rytilahti marked this pull request as draft March 5, 2024 00:05
@rytilahti rytilahti force-pushed the feat/color_temp_module branch from 9f2278b to a4b2e2c Compare March 6, 2024 18:23
@rytilahti rytilahti changed the base branch from feat/color_temp_module to feat/add_colortemp March 7, 2024 00:34
@rytilahti rytilahti force-pushed the feat/add_colortemp branch from ca26d15 to 0ee6fac Compare March 15, 2024 16:19
@rytilahti rytilahti changed the base branch from feat/add_colortemp to master March 15, 2024 16:22
@rytilahti rytilahti changed the base branch from master to feat/add_colortemp March 15, 2024 16:23
Base automatically changed from feat/add_colortemp to master March 15, 2024 16:36
@rytilahti rytilahti force-pushed the feat/ks240_support branch from 0fb1e7e to 7ef7a9b Compare March 15, 2024 16:41
@rytilahti rytilahti marked this pull request as ready for review March 15, 2024 16:43
@rytilahti
Copy link
Member Author

A couple of open questions related to KS240 support:

  • How to deal with the features that are reported to be supported in the component_nego for the parent, but are actually implemented by a child device (like here for fan level)?
  • How to handle modules that embed their data in the child info? For example, the dimmer in KS240 has these in the child info:
'fade_off_time': 1,
'fade_on_time': 1,
'gradually_off_mode': 1,
'gradually_off_mode': 1,
'max_fade_off_time': 60,
'max_fade_on_time': 60,

instead of when the reporting is done through a different module like

"get_on_off_gradually_info": {

@sdb9696
Copy link
Collaborator

sdb9696 commented Mar 15, 2024

  • How to deal with the features that are reported to be supported in the component_nego for the parent, but are actually implemented by a child device (like here for fan level)?

If we make an assumption that any component that exists on the child should be called only on the child except for [somelist]?

  1. Would the list be fairly stable, i.e.device, firmware, quick_setup, time and iot_cloud?
  2. Do we know of anything that would break this assumption?

@rytilahti
Copy link
Member Author

If we make an assumption that any component that exists on the child should be called only on the child except for [somelist]?

Doing a block list could be an option, yeah. Alternatively, we could either:

  1. Add a property that can be checked to see if the data is available, and not try to access the value if not available, or alternatively,
  2. Never add an "unsupported" feature to the features

@rytilahti
Copy link
Member Author

Created #824 and #825 to track those, I think we could merge this already, if we don't want to add the KS240 fixtures already as a part of this PR?

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!

@sdb9696 sdb9696 merged commit 700643d into master Apr 17, 2024
@sdb9696 sdb9696 deleted the feat/ks240_support branch April 17, 2024 10:07
@StevenMassaro
Copy link

Should the KS240 be added to the list of supported devices in the readme/docs?

@rytilahti
Copy link
Member Author

As soon as we add a fixture file it will be automatically updated. There are some issues that needs to be solved to make the tests pass so that's why it wasn't added in this PR. The device should function with the cli tool already with this PR, though.

@sdb9696 sdb9696 mentioned this pull request Jun 21, 2024
sdb9696 added a commit that referenced this pull request Jun 23, 2024
## [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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KS240 gets discovered but will not authenticate
3 participants