Skip to content
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

Implement introspectable settings #1500

Merged
merged 4 commits into from
Aug 15, 2022
Merged

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Aug 14, 2022

Continuing the work to make the library introspectable (#1495), this PR adds introspectable settings exposed in homeassitstant using number and select platforms.

image

If you want to develop or test this, the homeassistant fork supporting these features is currently available at rytilahti/home-assistant@xiaomi_miio/feat/entities_from_upstream

The @setting decorator creates a corresponding SettingDescriptor object depending on the input parameters:

  • If min_value or max_value is defined, a NumberSettingDescriptor is created.
  • If choices is defined, an EnumSettingDescriptor is created.

The created SettingDescriptor objects are exposed to downstream users using the Device.settings() method.

This also converts the descriptors to use attrs as kw_args is only available from python 3.10 onwards,
and using it is a prerequisite to allow sane inheritance on data classes.

Breaking change
This commit also touches cooker.py to rename previously used variable settings to _settings and its exposed getter to cooker_settings (@syssi).

The @settings decorator creates a corresponding descriptor
depending on what parameters are given to it:
* If min_value or max_value is defined, a NumberSettingDescriptor is created.
* If choices is defined, an EnumSettingDescriptor is created.

This also converts the descriptors to use attrs as kw_args is only available from python 3.10 onwards,
and using it is a prerequisite to allow sane inheritance on data classes.

This commit also touches cooker.py to rename previously used variable `settings` to `_settings` and its exposed getter to `cooker_settings`.
@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2022

Codecov Report

Merging #1500 (d576f85) into master (b432c7a) will decrease coverage by 0.01%.
The diff coverage is 53.08%.

@@            Coverage Diff             @@
##           master    #1500      +/-   ##
==========================================
- Coverage   82.63%   82.62%   -0.02%     
==========================================
  Files         142      142              
  Lines       14053    14081      +28     
  Branches     3383     3391       +8     
==========================================
+ Hits        11613    11634      +21     
- Misses       2221     2224       +3     
- Partials      219      223       +4     
Impacted Files Coverage Δ
miio/cooker.py 58.30% <3.22%> (ø)
miio/device.py 56.64% <60.00%> (+0.02%) ⬆️
miio/devicestatus.py 93.93% <84.61%> (-6.07%) ⬇️
miio/descriptors.py 100.00% <100.00%> (ø)
...o/integrations/vacuum/roborock/vacuumcontainers.py 77.65% <100.00%> (+0.08%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rytilahti rytilahti changed the title Add introspectable settings Implement introspectable settings Aug 14, 2022
@rytilahti rytilahti merged commit 0991f97 into master Aug 15, 2022
@rytilahti rytilahti deleted the feat/add_introspectable_settings branch August 15, 2022 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants