8000 Bulbs: allow specifying transition for state changes by rytilahti · Pull Request #70 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Bulbs: allow specifying transition for state changes #70

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

Conversation

rytilahti
Copy link
Member
@rytilahti rytilahti commented Jun 8, 2020

This adds transition kwarg for all state changing methods.

The values are in milliseconds, and limits of what values are accepted differ likely between devices, so there is no checks for that for now. This has only been tested using the brightness & turn on/off transitions on a KL60.

This is a WIP, as mypy does not like that the signature of turn_on and turn_off differ, so this does not currently pass the tests and that needs to be investigated.

This PR also changes the setters to return the response from the device, which can potentially be useful for downstream developers:

>>> asyncio.run(b.set_brightness(1))
{'on_off': 1, 'mode': 'normal', 'hue': 0, 'saturation': 0, 'color_temp': 2000, 'brightness': 1}

I wanted to push this up to give an example how to test the transitions, this is related to #69

@rytilahti rytilahti marked this pull request as draft June 8, 2020 19:37
@rytilahti rytilahti marked this pull request as ready for review June 12, 2020 22:08
@codecov-commenter
Copy link
codecov-commenter commented Jun 12, 2020

Codecov Report

Merging #70 into master will decrease coverage by 0.10%.
The diff coverage is 73.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #70      +/-   ##
==========================================
- Coverage   61.33%   61.22%   -0.11%     
==========================================
  Files           9        9              
  Lines        1169     1171       +2     
  Branches      177      178       +1     
==========================================
  Hits          717      717              
+ Misses        413      412       -1     
- Partials       39       42       +3     
Impacted Files Coverage Δ
kasa/smartbulb.py 73.07% <69.23%> (-1.15%) ⬇️
kasa/smartdevice.py 64.02% <100.00%> (ø)
kasa/protocol.py 50.74% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd073fa...1cfbc47. Read the comment docs.

@@ -142,8 +142,11 @@ async def get_light_state(self) -> Dict[str, Dict]:
# TODO: add warning and refer to use light.state?
return await self._query_helper(self.LIGHT_SERVICE, "get_light_state")

async def set_light_state(self, state: Dict) -> Dict:
async def set_light_state(self, state: Dict, *, transition: int = None) -> Dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really part of this PR, but shouldn't we further specify what is in the output Dict?

Copy link
Member Author

Choose a reason for hiding this comment

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

That could be added, it'd be Dict[str, Union[str,Dict]] or Dict[str, Union[str,Dict[str,Union[str,int]]] (which is not very beautiful :-)

Here's an example what it returns:

{'on_off': 0, 'dft_on_state': {'mode': 'normal', 'hue': 0, 'saturation': 0, 'color_temp': 2000, 'brightness': 23}}

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, that wouldn't be easy to read 😅

All state changing functions now allow defining transition time in milliseconds
@rytilahti rytilahti force-pushed the feature/smartbulb_transitions branch from c5a67ea to 1cfbc47 Compare June 14, 2020 16:26
@rytilahti rytilahti merged commit 99e0c4a into python-kasa:master Jun 14, 2020
@rytilahti rytilahti deleted the feature/smartbulb_transitions branch June 14, 2020 18:22
@rytilahti rytilahti mentioned this pull request Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0